Java Code Examples for org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils#getStandardJavaObjectInspectorFromTypeInfo()
The following examples show how to use
org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils#getStandardJavaObjectInspectorFromTypeInfo() .
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: HiveGenericUDF.java From flink with Apache License 2.0 | 6 votes |
@Override public void openInternal() { LOG.info("Open HiveGenericUDF as {}", hiveFunctionWrapper.getClassName()); function = hiveFunctionWrapper.createFunction(); try { returnInspector = function.initializeAndFoldConstants( HiveInspectors.toInspectors(constantArguments, argTypes)); } catch (UDFArgumentException e) { throw new FlinkHiveUDFException(e); } deferredObjects = new GenericUDF.DeferredObject[argTypes.length]; for (int i = 0; i < deferredObjects.length; i++) { deferredObjects[i] = new DeferredObjectAdapter( TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo( HiveTypeUtil.toHiveTypeInfo(argTypes[i])), argTypes[i].getLogicalType() ); } }
Example 2
Source File: UDAFCollectAction.java From 163-bigdate-note with GNU General Public License v3.0 | 6 votes |
@Override public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException { //判断参数个数 if (parameters.length != 2) { throw new UDFArgumentTypeException(parameters.length - 1, "Two argument is excepted."); } ObjectInspector oi = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(parameters[0]); // ObjectInspector oi1 = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(parameters[1]); if (oi.getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "Argument must be PRIMITIVE, but" + oi.getCategory().name() + " was passed."); } // PrimitiveObjectInspector inputOI = (PrimitiveObjectInspector) oi; // if (inputOI.getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING) { // throw new UDFArgumentTypeException(0, "Argument must be String, but" // + inputOI.getPrimitiveCategory().name() // + " was passed."); // } return new AllActionsOfThisPeople30MinBefore(); }
Example 3
Source File: IOUtil.java From hugegraph-loader with Apache License 2.0 | 6 votes |
public default void writeOrc(String fileName, TypeInfo typeInfo, Object... values) { Path path = new Path(this.storePath(), fileName); ObjectInspector inspector = TypeInfoUtils .getStandardJavaObjectInspectorFromTypeInfo( typeInfo); OrcFile.WriterOptions options = OrcFile.writerOptions(this.config()) .inspector(inspector); Object row = Arrays.asList(values); try (Writer writer = OrcFile.createWriter(path, options)) { writer.addRow(row); } catch (IOException e) { throw new RuntimeException(String.format( "Failed to write values '%s' to file '%s' in ORC " + "compression format", row, path), e); } }
Example 4
Source File: HiveTypeConverter.java From metacat with Apache License 2.0 | 6 votes |
@Override public Type toMetacatType(final String type) { // Hack to fix presto "varchar" type coming in with no length which is required by Hive. final TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString( "varchar".equals(type.toLowerCase()) ? serdeConstants.STRING_TYPE_NAME : type); ObjectInspector oi = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(typeInfo); // The standard struct object inspector forces field names to lower case, however in Metacat we need to preserve // the original case of the struct fields so we wrap it with our wrapper to force the fieldNames to keep // their original case if (typeInfo.getCategory().equals(ObjectInspector.Category.STRUCT)) { final StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo; final StandardStructObjectInspector objectInspector = (StandardStructObjectInspector) oi; oi = new HiveTypeConverter.SameCaseStandardStructObjectInspector( structTypeInfo.getAllStructFieldNames(), objectInspector); } return getCanonicalType(oi); }
Example 5
Source File: JSONSerDe.java From searchanalytics-bigdata with MIT License | 6 votes |
/** * An initialization function used to gather information about the table. * Typically, a SerDe implementation will be interested in the list of * column names and their types. That information will be used to help * perform actual serialization and deserialization of data. */ @Override public void initialize(final Configuration conf, final Properties tbl) throws SerDeException { // Get a list of the table's column names. final String colNamesStr = tbl.getProperty(serdeConstants.LIST_COLUMNS); // Jai...change column names to lower case. colNames = Arrays.asList(colNamesStr.toLowerCase().split(",")); // Get a list of TypeInfos for the columns. This list lines up with // the list of column names. final String colTypesStr = tbl .getProperty(serdeConstants.LIST_COLUMN_TYPES); final List<TypeInfo> colTypes = TypeInfoUtils .getTypeInfosFromTypeString(colTypesStr); rowTypeInfo = (StructTypeInfo) TypeInfoFactory.getStructTypeInfo( colNames, colTypes); rowOI = TypeInfoUtils .getStandardJavaObjectInspectorFromTypeInfo(rowTypeInfo); }
Example 6
Source File: JSONCDHSerDe.java From bigdata-tutorial with Apache License 2.0 | 6 votes |
/** * An initialization function used to gather information about the table. * Typically, a SerDe implementation will be interested in the list of * column names and their types. That information will be used to help perform * actual serialization and deserialization of data. */ @Override public void initialize(Configuration conf, Properties tbl) throws SerDeException { // Get a list of the table's column names. String colNamesStr = tbl.getProperty(serdeConstants.LIST_COLUMNS); colNames = Arrays.asList(colNamesStr.split(",")); // Get a list of TypeInfos for the columns. This list lines up with // the list of column names. String colTypesStr = tbl.getProperty(serdeConstants.LIST_COLUMN_TYPES); List<TypeInfo> colTypes = TypeInfoUtils.getTypeInfosFromTypeString(colTypesStr); rowTypeInfo = (StructTypeInfo) TypeInfoFactory.getStructTypeInfo(colNames, colTypes); rowOI = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(rowTypeInfo); }
Example 7
Source File: HiveSimpleUDF.java From flink with Apache License 2.0 | 5 votes |
@Override public void openInternal() { LOG.info("Opening HiveSimpleUDF as '{}'", hiveFunctionWrapper.getClassName()); function = hiveFunctionWrapper.createFunction(); List<TypeInfo> typeInfos = new ArrayList<>(); for (DataType arg : argTypes) { typeInfos.add(HiveTypeUtil.toHiveTypeInfo(arg)); } try { method = function.getResolver().getEvalMethod(typeInfos); returnInspector = ObjectInspectorFactory.getReflectionObjectInspector(method.getGenericReturnType(), ObjectInspectorFactory.ObjectInspectorOptions.JAVA); ObjectInspector[] argInspectors = new ObjectInspector[typeInfos.size()]; for (int i = 0; i < argTypes.length; i++) { argInspectors[i] = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(typeInfos.get(i)); } conversionHelper = new GenericUDFUtils.ConversionHelper(method, argInspectors); conversions = new HiveObjectConversion[argInspectors.length]; for (int i = 0; i < argInspectors.length; i++) { conversions[i] = HiveInspectors.getConversion(argInspectors[i], argTypes[i].getLogicalType()); } allIdentityConverter = Arrays.stream(conversions) .allMatch(conv -> conv instanceof IdentityConversion); } catch (Exception e) { throw new FlinkHiveUDFException( String.format("Failed to open HiveSimpleUDF from %s", hiveFunctionWrapper.getClassName()), e); } }
Example 8
Source File: HiveSimpleUDF.java From flink with Apache License 2.0 | 5 votes |
@Override public void openInternal() { LOG.info("Opening HiveSimpleUDF as '{}'", hiveFunctionWrapper.getClassName()); function = hiveFunctionWrapper.createFunction(); List<TypeInfo> typeInfos = new ArrayList<>(); for (DataType arg : argTypes) { typeInfos.add(HiveTypeUtil.toHiveTypeInfo(arg, false)); } try { method = function.getResolver().getEvalMethod(typeInfos); returnInspector = ObjectInspectorFactory.getReflectionObjectInspector(method.getGenericReturnType(), ObjectInspectorFactory.ObjectInspectorOptions.JAVA); ObjectInspector[] argInspectors = new ObjectInspector[typeInfos.size()]; for (int i = 0; i < argTypes.length; i++) { argInspectors[i] = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(typeInfos.get(i)); } conversionHelper = new GenericUDFUtils.ConversionHelper(method, argInspectors); conversions = new HiveObjectConversion[argInspectors.length]; for (int i = 0; i < argInspectors.length; i++) { conversions[i] = HiveInspectors.getConversion(argInspectors[i], argTypes[i].getLogicalType(), hiveShim); } allIdentityConverter = Arrays.stream(conversions) .allMatch(conv -> conv instanceof IdentityConversion); } catch (Exception e) { throw new FlinkHiveUDFException( String.format("Failed to open HiveSimpleUDF from %s", hiveFunctionWrapper.getClassName()), e); } }
Example 9
Source File: CobolStringField.java From Cobol-to-Hive with Apache License 2.0 | 5 votes |
public CobolStringField(String debugInfo, int levelNo, String name, String picClause) { super(); super.debugInfo = debugInfo; super.levelNo = levelNo; super.type = CobolFieldType.STRING; super.name = name; String fieldType = "string"; if (picClause.contains("(")) { String[] s = picClause.split("\\(|\\)|\\."); if (s.length == 2) { try { super.length = Integer.parseInt(s[1]); } catch (NumberFormatException e) { throw e; } } else { throw new RuntimeException( "Alphanumeric Picture clause has more brackets:" + this.debugInfo); } } else { if (picClause.trim().toLowerCase().matches("[x|a]+\\.")) super.length = picClause.length() -1; else if (picClause.trim().toLowerCase().matches("[x|a]+")) super.length = picClause.length(); else { throw new RuntimeException( "Alphanumeric Picture clause incorrect '" + this.debugInfo); } } if (super.length < 65355) { fieldType = "varchar(" + this.length + ")"; } super.typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(fieldType); this.oi = TypeInfoUtils .getStandardJavaObjectInspectorFromTypeInfo(this.typeInfo); }
Example 10
Source File: LWSerDe.java From hive-solr with Apache License 2.0 | 5 votes |
@Override public void initialize(Configuration conf, Properties tblProperties) throws SerDeException { colNames = Arrays.asList(tblProperties.getProperty(serdeConstants.LIST_COLUMNS).split(",")); colTypes = TypeInfoUtils.getTypeInfosFromTypeString(tblProperties.getProperty(serdeConstants.LIST_COLUMN_TYPES)); typeInfo = (StructTypeInfo) TypeInfoFactory.getStructTypeInfo(colNames, colTypes); inspector = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(typeInfo); row = new ArrayList<>(); enableFieldMapping = Boolean.valueOf(tblProperties.getProperty(ENABLE_FIELD_MAPPING, "false")); }
Example 11
Source File: MaxByUDAF.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] argTypes) throws SemanticException { if (argTypes.length != 2) { throw new UDFArgumentLengthException( "Exactly two arguments are expected: " + argTypes.length); } ObjectInspector yOI = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(argTypes[1]); if (!ObjectInspectorUtils.compareSupported(yOI)) { throw new UDFArgumentTypeException(1, "Cannot support comparison of map<> type or complex type containing map<>."); } return new Evaluator(); }
Example 12
Source File: MinByUDAF.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] argTypes) throws SemanticException { if (argTypes.length != 2) { throw new UDFArgumentLengthException( "Exactly two arguments are expected: " + argTypes.length); } ObjectInspector yOI = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(argTypes[1]); if (!ObjectInspectorUtils.compareSupported(yOI)) { throw new UDFArgumentTypeException(1, "Cannot support comparison of map<> type or complex type containing map<>."); } return new Evaluator(); }
Example 13
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Nonnull public static ObjectInspector getObjectInspector(@Nonnull final String typeString, final boolean preferWritable) { TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(typeString); if (preferWritable) { return TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(typeInfo); } else { return TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(typeInfo); } }
Example 14
Source File: MaxRowUDAF.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException { ObjectInspector oi = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(parameters[0]); if (!ObjectInspectorUtils.compareSupported(oi)) { throw new UDFArgumentTypeException(0, "Cannot support comparison of map<> type or complex type containing map<>."); } return new GenericUDAFMaxRowEvaluator(); }
Example 15
Source File: DynamoDBObjectInspector.java From emr-dynamodb-connector with Apache License 2.0 | 5 votes |
DynamoDBField(int fieldID, String fieldName, String attributeName, TypeInfo typeInfo, HiveDynamoDBType ddType) { super(); this.fieldID = fieldID; this.fieldName = fieldName; this.attributeName = attributeName; this.objectInspector = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(typeInfo); this.ddType = ddType; }
Example 16
Source File: SolrSerde.java From hive-solr with MIT License | 4 votes |
@Override public void initialize(@Nullable Configuration configuration, Properties tbl) throws SerDeException { row=new ArrayList<Object>(); // Read Column Names String columnNameProp = tbl.getProperty(serdeConstants.LIST_COLUMNS); if (columnNameProp != null && columnNameProp.length() > 0) { columnNames = Arrays.asList(columnNameProp.split(",")); } else { columnNames = new ArrayList<String>(); } // Read Column Types String columnTypeProp = tbl.getProperty(serdeConstants.LIST_COLUMN_TYPES); // default all string if (columnTypeProp == null) { String[] types = new String[columnNames.size()]; Arrays.fill(types, 0, types.length, serdeConstants.STRING_TYPE_NAME); columnTypeProp = StringUtils.join(types, ":"); } columnTypes = TypeInfoUtils.getTypeInfosFromTypeString(columnTypeProp); // Check column and types equals if (columnTypes.size() != columnNames.size()) { throw new SerDeException("len(columnNames) != len(columntTypes)"); } // Create ObjectInspectors from the type information for each column List<ObjectInspector> columnOIs = new ArrayList<ObjectInspector>(); ObjectInspector oi; for (int c = 0; c < columnNames.size(); c++) { oi = TypeInfoUtils .getStandardJavaObjectInspectorFromTypeInfo(columnTypes .get(c)); columnOIs.add(oi); } objectInspector = ObjectInspectorFactory.getStandardStructObjectInspector(columnNames, columnOIs); }
Example 17
Source File: TestRecordReaderImpl.java From hive-dwrf with Apache License 2.0 | 4 votes |
public static ObjectInspector createJavaObjectInspectorFromFieldSchema(String columnTypeString) { TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(columnTypeString); return TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(typeInfo); }
Example 18
Source File: SMSerDe.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
/** * An initialization function used to gather information about the table. * Typically, a SerDe implementation will be interested in the list of * column names and their types. That information will be used to help * perform actual serialization and deserialization of data. */ //@Override public void initialize(Configuration conf, Properties tbl) throws SerDeException { if (Log.isDebugEnabled()) SpliceLogUtils.debug(Log, "initialize with conf=%s, tbl=%s",conf,tbl); // Get a list of the table's column names. tableName = tbl.getProperty(MRConstants.SPLICE_TABLE_NAME); String hbaseDir = null; if (conf != null) { hbaseDir = conf.get(HConstants.HBASE_DIR); } if (hbaseDir == null) hbaseDir = System.getProperty(HConstants.HBASE_DIR); if (hbaseDir == null) throw new SerDeException("hbase root directory not set, please include hbase.rootdir in config or via -D system property ..."); if (conf != null) { conf.set(MRConstants.SPLICE_INPUT_TABLE_NAME, tableName); conf.set(MRConstants.SPLICE_JDBC_STR, tbl.getProperty(MRConstants.SPLICE_JDBC_STR)); conf.set(HConstants.HBASE_DIR, hbaseDir); if (conf.get(HiveConf.ConfVars.POSTEXECHOOKS.varname) == null) { conf.set(HiveConf.ConfVars.POSTEXECHOOKS.varname, "com.splicemachine.mrio.api.hive.PostExecHook"); } if (conf.get(HiveConf.ConfVars.ONFAILUREHOOKS.varname) == null) { conf.set(HiveConf.ConfVars.ONFAILUREHOOKS.varname, "com.splicemachine.mrio.api.hive.FailureExecHook"); } } if (sqlUtil == null) sqlUtil = SMSQLUtil.getInstance(tbl.getProperty(MRConstants.SPLICE_JDBC_STR)); String colNamesStr = tbl.getProperty(Constants.LIST_COLUMNS); colNames.clear(); for (String split: colNamesStr.split(",")) colNames.add(split.toUpperCase()); String colTypesStr = tbl.getProperty(Constants.LIST_COLUMN_TYPES); colTypes = TypeInfoUtils.getTypeInfosFromTypeString(colTypesStr); objectCache = new ArrayList<Object>(colTypes.size()); if (tableName != null) { tableName = tableName.trim().toUpperCase(); try { if (!sqlUtil.checkTableExists(tableName)) throw new SerDeException(String.format("table %s does not exist...",tableName)); if (conf != null) { ScanSetBuilder tableScannerBuilder = sqlUtil.getTableScannerBuilder(tableName, colNames); conf.set(MRConstants.SPLICE_SCAN_INFO, tableScannerBuilder.base64Encode()); // TableContext tableContext = sqlUtil.createTableContext(tableName, tableScannerBuilder); // conf.set(MRConstants.SPLICE_TBLE_CONTEXT, tableContext.getTableContextBase64String()); } } catch (Exception e) { throw new SerDeException(e); } } if (Log.isDebugEnabled()) SpliceLogUtils.debug(Log, "generating hive info colNames=%s, colTypes=%s",colNames,colTypes); rowTypeInfo = (StructTypeInfo) TypeInfoFactory.getStructTypeInfo(colNames, colTypes); rowOI = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(rowTypeInfo); //serdeParams = LazySimpleSerDe.initSerdeParams(conf, tbl, getClass().getName()); Log.info("--------Finished initialize"); }