Java Code Examples for org.apache.pig.impl.util.UDFContext#getUDFProperties()
The following examples show how to use
org.apache.pig.impl.util.UDFContext#getUDFProperties() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonStorage.java From spork with Apache License 2.0 | 6 votes |
@Override public void prepareToWrite(RecordWriter writer) throws IOException { // Store the record writer reference so we can use it when it's time // to write tuples this.writer = writer; // Get the schema string from the UDFContext object. UDFContext udfc = UDFContext.getUDFContext(); Properties p = udfc.getUDFProperties(this.getClass(), new String[]{udfcSignature}); String strSchema = p.getProperty(SCHEMA_SIGNATURE); if (strSchema == null) { throw new IOException("Could not find schema in UDF context"); } // Parse the schema from the string stored in the properties object. schema = new ResourceSchema(Utils.getSchemaFromString(strSchema)); // Build a Json factory jsonFactory = new JsonFactory(); }
Example 2
Source File: FixedWidthLoader.java From spork with Apache License 2.0 | 6 votes |
@Override public RequiredFieldResponse pushProjection(RequiredFieldList requiredFieldList) throws FrontendException { if (requiredFieldList == null) return null; if (fields != null && requiredFieldList.getFields() != null) { requiredFields = new boolean[fields.length]; for (RequiredField f : requiredFieldList.getFields()) { requiredFields[f.getIndex()] = true; } UDFContext udfc = UDFContext.getUDFContext(); Properties p = udfc.getUDFProperties(this.getClass(), new String[]{ udfContextSignature }); try { p.setProperty(REQUIRED_FIELDS_SIGNATURE, ObjectSerializer.serialize(requiredFields)); } catch (Exception e) { throw new RuntimeException("Cannot serialize requiredFields for pushProjection"); } } return new RequiredFieldResponse(true); }
Example 3
Source File: FixedWidthLoader.java From spork with Apache License 2.0 | 6 votes |
public ResourceSchema getSchema(String location, Job job) throws IOException { if (schema != null) { // Send schema to backend // Schema should have been passed as an argument (-> constructor) // or provided in the default constructor UDFContext udfc = UDFContext.getUDFContext(); Properties p = udfc.getUDFProperties(this.getClass(), new String[]{ udfContextSignature }); p.setProperty(SCHEMA_SIGNATURE, schema.toString()); return schema; } else { // Should never get here throw new IllegalArgumentException( "No schema found: default schema was never created and no user-specified schema was found." ); } }
Example 4
Source File: RegisteredJarVisibilityLoader.java From spork with Apache License 2.0 | 6 votes |
@Override public void setLocation(String location, Job job) throws IOException { UDFContext udfContext = UDFContext.getUDFContext(); Properties properties = udfContext.getUDFProperties(RegisteredJarVisibilityLoader.class); if (!properties.containsKey(REGISTERED_JAR_VISIBILITY_SCHEMA)) { LOG.info("Storing " + RegisteredJarVisibilitySchema.class.getName() + " in UDFContext."); properties.put(REGISTERED_JAR_VISIBILITY_SCHEMA, new RegisteredJarVisibilitySchema()); LOG.info("Stored " + RegisteredJarVisibilitySchema.class.getName() + " in UDFContext."); } else { LOG.info("Retrieving " + REGISTERED_JAR_VISIBILITY_SCHEMA + " from UDFContext."); RegisteredJarVisibilitySchema registeredJarVisibilitySchema = (RegisteredJarVisibilitySchema) properties.get(REGISTERED_JAR_VISIBILITY_SCHEMA); LOG.info("Retrieved " + REGISTERED_JAR_VISIBILITY_SCHEMA + " from UDFContext."); } super.setLocation(location, job); }
Example 5
Source File: JsonLoader.java From spork with Apache License 2.0 | 6 votes |
public ResourceSchema getSchema(String location, Job job) throws IOException { ResourceSchema s; if (schema!=null) { s = schema; } else { // Parse the schema s = (new JsonMetadata()).getSchema(location, job, true); if (s == null) { throw new IOException("Unable to parse schema found in file in " + location); } } // Now that we have determined the schema, store it in our // UDFContext properties object so we have it when we need it on the // backend UDFContext udfc = UDFContext.getUDFContext(); Properties p = udfc.getUDFProperties(this.getClass(), new String[]{udfcSignature}); p.setProperty(SCHEMA_SIGNATURE, s.toString()); return s; }
Example 6
Source File: FixedWidthStorer.java From spork with Apache License 2.0 | 6 votes |
@Override public void prepareToWrite(RecordWriter writer) throws IOException { // Store writer to use in putNext() this.writer = writer; // Get the schema string from the UDFContext object. UDFContext udfc = UDFContext.getUDFContext(); Properties p = udfc.getUDFProperties(this.getClass(), new String[]{ udfContextSignature }); String strSchema = p.getProperty(SCHEMA_SIGNATURE); if (strSchema == null) { throw new IOException("Could not find schema in UDF context"); } schema = new ResourceSchema(Utils.getSchemaFromString(strSchema)); fields = schema.getFields(); }
Example 7
Source File: CassandraStorage.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** set partition filter */ public void setPartitionFilter(Expression partitionFilter) throws IOException { UDFContext context = UDFContext.getUDFContext(); Properties property = context.getUDFProperties(AbstractCassandraStorage.class); property.setProperty(PARTITION_FILTER_SIGNATURE, indexExpressionsToString(filterToIndexExpressions(partitionFilter))); }
Example 8
Source File: FixedWidthStorer.java From spork with Apache License 2.0 | 5 votes |
@Override public void checkSchema(ResourceSchema s) throws IOException { // Not actually checking schema // Just storing it to use in the backend UDFContext udfc = UDFContext.getUDFContext(); Properties p = udfc.getUDFProperties(this.getClass(), new String[]{ udfContextSignature }); p.setProperty(SCHEMA_SIGNATURE, s.toString()); }
Example 9
Source File: AvroStorage.java From spork with Apache License 2.0 | 5 votes |
/** * Internal function for getting the Properties object associated with * this UDF instance. * @param c Class of this UDF * @param signature Signature string * @return The Properties object associated with this UDF instance */ @SuppressWarnings("rawtypes") protected final Properties getProperties(final Class c, final String signature) { UDFContext context = UDFContext.getUDFContext(); if (signature == null) { return context.getUDFProperties(c); } else { return context.getUDFProperties(c, new String[] {signature}); } }
Example 10
Source File: AbstractCassandraStorage.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** get the columnfamily definition for the signature */ protected CfInfo getCfInfo(String signature) throws IOException { UDFContext context = UDFContext.getUDFContext(); Properties property = context.getUDFProperties(AbstractCassandraStorage.class); String prop = property.getProperty(signature); CfInfo cfInfo = new CfInfo(); cfInfo.cfDef = cfdefFromString(prop.substring(2)); cfInfo.compactCqlTable = prop.charAt(0) == '1' ? true : false; cfInfo.cql3Table = prop.charAt(1) == '1' ? true : false; return cfInfo; }
Example 11
Source File: CqlNativeStorage.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** retrieve where clause for partition filter */ private String getWhereClauseForPartitionFilter() { UDFContext context = UDFContext.getUDFContext(); Properties property = context.getUDFProperties(AbstractCassandraStorage.class); return property.getProperty(PARTITION_FILTER_SIGNATURE); }
Example 12
Source File: DBStorage.java From spork with Apache License 2.0 | 5 votes |
/** * Initialise the database connection and prepared statement here. */ @SuppressWarnings("unchecked") @Override public void prepareToWrite(RecordWriter writer) throws IOException { ps = null; con = null; if (insertQuery == null) { throw new IOException("SQL Insert command not specified"); } try { if (user == null || pass == null) { con = DriverManager.getConnection(jdbcURL); } else { con = DriverManager.getConnection(jdbcURL, user, pass); } con.setAutoCommit(false); ps = con.prepareStatement(insertQuery); } catch (SQLException e) { log.error("Unable to connect to JDBC @" + jdbcURL); throw new IOException("JDBC Error", e); } count = 0; // Try to get the schema from the UDFContext object. UDFContext udfc = UDFContext.getUDFContext(); Properties p = udfc.getUDFProperties(this.getClass(), new String[]{udfcSignature}); String strSchema = p.getProperty(SCHEMA_SIGNATURE); if (strSchema != null) { // Parse the schema from the string stored in the properties object. schema = new ResourceSchema(Utils.getSchemaFromString(strSchema)); } }
Example 13
Source File: CSVExcelStorage.java From spork with Apache License 2.0 | 5 votes |
public void checkSchema(ResourceSchema s) throws IOException { // Not actually checking schema // Actually, just storing it to use in the backend UDFContext udfc = UDFContext.getUDFContext(); Properties p = udfc.getUDFProperties(this.getClass(), new String[]{ udfContextSignature }); p.setProperty(SCHEMA_SIGNATURE, s.toString()); }
Example 14
Source File: ParquetStorer.java From parquet-mr with Apache License 2.0 | 4 votes |
private Properties getProperties() { UDFContext udfc = UDFContext.getUDFContext(); Properties p = udfc.getUDFProperties(this.getClass(), new String[]{ signature }); return p; }
Example 15
Source File: ParquetLoader.java From parquet-mr with Apache License 2.0 | 4 votes |
protected void storeInUDFContext(String key, Object value) { UDFContext udfContext = UDFContext.getUDFContext(); java.util.Properties props = udfContext.getUDFProperties( this.getClass(), new String[]{signature}); props.put(key, value); }
Example 16
Source File: PhoenixHBaseLoader.java From phoenix with Apache License 2.0 | 4 votes |
private void storeInUDFContext(final String signature,final String key,final String value) { final UDFContext udfContext = UDFContext.getUDFContext(); final Properties props = udfContext.getUDFProperties(this.getClass(), new String[]{signature}); props.put(key, value); }
Example 17
Source File: ContextualEvalFunc.java From datafu with Apache License 2.0 | 4 votes |
/** * Helper method to return the context properties for this class * * @return context properties */ protected Properties getContextProperties() { UDFContext context = UDFContext.getUDFContext(); Properties properties = context.getUDFProperties(this.getClass()); return properties; }
Example 18
Source File: CqlNativeStorage.java From stratio-cassandra with Apache License 2.0 | 4 votes |
public void setPartitionFilter(Expression partitionFilter) throws IOException { UDFContext context = UDFContext.getUDFContext(); Properties property = context.getUDFProperties(AbstractCassandraStorage.class); property.setProperty(PARTITION_FILTER_SIGNATURE, partitionFilterToWhereClauseString(partitionFilter)); }
Example 19
Source File: Loader.java From logparser with Apache License 2.0 | 4 votes |
private void storeInUDFContext(String key, Object value) { UDFContext udfContext = UDFContext.getUDFContext(); Properties props = udfContext.getUDFProperties( this.getClass(), new String[]{theUDFContextSignature}); props.put(key, value); }
Example 20
Source File: PhoenixHBaseLoader.java From phoenix with Apache License 2.0 | 4 votes |
private String getValueFromUDFContext(final String signature,final String key) { final UDFContext udfContext = UDFContext.getUDFContext(); final Properties props = udfContext.getUDFProperties(this.getClass(), new String[]{signature}); return props.getProperty(key); }