public static <T> T newAccessor(MinorType type, Class<? extends T> accessors[]) { try { Class<? extends T> accessorClass = accessors[type.ordinal()]; if (accessorClass == null) { throw new UnsupportedOperationException(type.toString()); } return accessorClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException(e); } } }
public static ObjectInspector getDrillObjectInspector(DataMode mode, MinorType minorType, boolean varCharToStringReplacement) { try { if (mode == DataMode.REQUIRED) { if (OIMAP_REQUIRED.containsKey(minorType)) { if (varCharToStringReplacement && minorType == MinorType.VARCHAR) { return (ObjectInspector) ((Class) OIMAP_REQUIRED.get(minorType).toArray()[1]).newInstance(); } else { return (ObjectInspector) ((Class) OIMAP_REQUIRED.get(minorType).toArray()[0]).newInstance(); } } } else if (mode == DataMode.OPTIONAL) { if (OIMAP_OPTIONAL.containsKey(minorType)) { if (varCharToStringReplacement && minorType == MinorType.VARCHAR) { return (ObjectInspector) ((Class) OIMAP_OPTIONAL.get(minorType).toArray()[1]).newInstance(); } else { return (ObjectInspector) ((Class) OIMAP_OPTIONAL.get(minorType).toArray()[0]).newInstance(); } } } else { throw new UnsupportedOperationException("Repeated types are not supported as arguement to Hive UDFs"); } } catch(InstantiationException | IllegalAccessException e) { throw new RuntimeException("Failed to instantiate ObjectInspector", e); } throw new UnsupportedOperationException( String.format("Type %s[%s] not supported as arguement to Hive UDFs", minorType.toString(), mode.toString())); }
public static BaseScalarWriter newWriter(ValueVector vector) { MajorType major = vector.getField().getType(); MinorType type = major.getMinorType(); try { Class<? extends BaseScalarWriter> accessorClass = requiredWriters[type.ordinal()]; if (accessorClass == null) { throw new UnsupportedOperationException(type.toString()); } Constructor<? extends BaseScalarWriter> ctor = accessorClass.getConstructor(ValueVector.class); return ctor.newInstance(vector); } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException e) { throw new IllegalStateException(e); } } }
public static Object getValueFromFieldType(JsonParser parser, MinorType fieldType) throws IOException { switch (fieldType) { case BIGINT: return parser.getLongValue(); case VARCHAR: return parser.getValueAsString(); case FLOAT4: return parser.getFloatValue(); case BIT: return parser.getBooleanValue(); case LATE: case NULL: return null; default: throw new RuntimeException("Unexpected Field type to return value: " + fieldType.toString()); } } }
public static BaseScalarWriter newWriter(ValueVector vector) { MajorType major = vector.getField().getType(); MinorType type = major.getMinorType(); try { Class<? extends BaseScalarWriter> accessorClass = requiredWriters[type.ordinal()]; if (accessorClass == null) { throw new UnsupportedOperationException(type.toString()); } Constructor<? extends BaseScalarWriter> ctor = accessorClass.getConstructor(ValueVector.class); return ctor.newInstance(vector); } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException e) { throw new IllegalStateException(e); } } }
/** * Returns the function which asserts that the current subtype of a union type is a specific type, and allows the materializer * to bind to that specific type when doing function resolution * @param type * @param arg * @return */ private LogicalExpression getUnionAssertFunctionForType(MinorType type, LogicalExpression arg) { if (type == MinorType.UNION) { return arg; } if (type == MinorType.LIST || type == MinorType.MAP) { return getExceptionFunction("Unable to cast union to " + type); } String castFuncName = String.format("assert_%s", type.toString()); return new FunctionCall(castFuncName, Collections.singletonList(arg), ExpressionPosition.UNKNOWN); }
public static BaseScalarReader buildColumnReader(VectorAccessor va) { MajorType major = va.type(); MinorType type = major.getMinorType(); switch (type) { case GENERIC_OBJECT: case LATE: case NULL: case LIST: case MAP: throw new UnsupportedOperationException(type.toString()); default: return newAccessor(type, requiredReaders); } }
public static LogicalExpression convertToNullableType(LogicalExpression fromExpr, MinorType toType, FunctionLookupContext functionLookupContext, ErrorCollector errorCollector) { String funcName = "convertToNullable" + toType.toString(); List<LogicalExpression> args = Lists.newArrayList(); args.add(fromExpr); FunctionCall funcCall = new FunctionCall(funcName, args, ExpressionPosition.UNKNOWN); FunctionResolver resolver = FunctionResolverFactory.getResolver(funcCall); DrillFuncHolder matchedConvertToNullableFuncHolder = functionLookupContext.findDrillFunction(resolver, funcCall); if (matchedConvertToNullableFuncHolder == null) { logFunctionResolutionError(errorCollector, funcCall); return NullExpression.INSTANCE; } return matchedConvertToNullableFuncHolder.getExpr(funcName, args, ExpressionPosition.UNKNOWN); }
private ObjectReader requireReader(MinorType type) { ObjectReader reader = member(type); if (reader == null) { throw new IllegalArgumentException("Union does not include type " + type.toString()); } return reader; }
@Override public RexNode visitCastExpression(CastExpression e, Void value) throws RuntimeException { RexNode convertedInput = e.getInput().accept(this, null); String typeStr = e.getMajorType().getMinorType().toString(); if (SqlTypeName.get(typeStr) == null) { logger.debug("SqlTypeName could not find {}", typeStr); } SqlTypeName typeName = TypeInferenceUtils.getCalciteTypeFromDrillType(e.getMajorType().getMinorType()); RelDataType targetType = TypeInferenceUtils.createCalciteTypeWithNullability( inputRel.getCluster().getTypeFactory(), typeName, true); return builder.makeCast(targetType, convertedInput); }
@Override public ObjectWriter addMember(ColumnMetadata member) { if (variantSchema().hasType(member.type())) { throw new IllegalArgumentException("Duplicate type: " + member.type().toString()); } if (isSingleType()) { throw new IllegalStateException("List is defined to contains a single type."); } return addColumn(member).writer(); }
private LogicalExpression getConvertToNullableExpr(List<LogicalExpression> args, MinorType minorType, FunctionLookupContext functionLookupContext) { String funcName = "convertToNullable" + minorType.toString(); FunctionCall funcCall = new FunctionCall(funcName, args, ExpressionPosition.UNKNOWN); FunctionResolver resolver = FunctionResolverFactory.getResolver(funcCall); DrillFuncHolder matchedConvertToNullableFuncHolder = functionLookupContext.findDrillFunction(resolver, funcCall); if (matchedConvertToNullableFuncHolder == null) { logFunctionResolutionError(errorCollector, funcCall); return NullExpression.INSTANCE; } return matchedConvertToNullableFuncHolder.getExpr(funcName, args, ExpressionPosition.UNKNOWN); }
public static <T> T newAccessor(MinorType type, Class<? extends T> accessors[]) { try { Class<? extends T> accessorClass = accessors[type.ordinal()]; if (accessorClass == null) { throw new UnsupportedOperationException(type.toString()); } return accessorClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException(e); } } }
@Override public ObjectWriter addMember(ColumnMetadata member) { if (variantSchema().hasType(member.type())) { throw new IllegalArgumentException("Duplicate type: " + member.type().toString()); } return addColumn(member).writer(); }
/** * Get the function that tests whether a union type is a specific type * @param type * @param arg * @return */ private LogicalExpression getIsTypeExpressionForType(MinorType type, LogicalExpression arg) { String isFuncName = String.format("is_%s", type.toString()); List<LogicalExpression> args = Lists.newArrayList(); args.add(arg); return new FunctionCall(isFuncName, args, ExpressionPosition.UNKNOWN); }
return getBitVector(); default: throw new UnsupportedOperationException(type.toString());
/** * Build a writer for a non-projected column. * @param schema schema of the column * @return a "dummy" writer for the column */ public static AbstractObjectWriter buildDummyColumnWriter(ColumnMetadata schema) { switch (schema.type()) { case GENERIC_OBJECT: case LATE: case LIST: case MAP: case UNION: throw new UnsupportedOperationException(schema.type().toString()); default: ScalarObjectWriter scalarWriter = new ScalarObjectWriter( new DummyScalarWriter(schema)); switch (schema.mode()) { case OPTIONAL: case REQUIRED: return scalarWriter; case REPEATED: return new ArrayObjectWriter( new DummyArrayWriter(schema, scalarWriter)); default: throw new UnsupportedOperationException(schema.mode().toString()); } } }
public static AbstractObjectWriter buildColumnWriter(ColumnMetadata schema, ValueVector vector) { if (vector == null) { return buildDummyColumnWriter(schema); } // Build a writer for a materialized column. assert schema.type() == vector.getField().getType().getMinorType(); assert schema.mode() == vector.getField().getType().getMode(); switch (schema.type()) { case GENERIC_OBJECT: case LATE: case NULL: case LIST: case MAP: case UNION: throw new UnsupportedOperationException(schema.type().toString()); default: switch (schema.mode()) { case OPTIONAL: return nullableScalarWriter(schema, (NullableVector) vector); case REQUIRED: return requiredScalarWriter(schema, vector); case REPEATED: return repeatedScalarWriter(schema, (RepeatedValueVector) vector); default: throw new UnsupportedOperationException(schema.mode().toString()); } } }
public static BaseScalarReader buildColumnReader(VectorAccessor va) { MajorType major = va.type(); MinorType type = major.getMinorType(); switch (type) { case GENERIC_OBJECT: case LATE: case NULL: case LIST: case MAP: throw new UnsupportedOperationException(type.toString()); default: return newAccessor(type, requiredReaders); } }
private ObjectReader requireReader(MinorType type) { ObjectReader reader = member(type); if (reader == null) { throw new IllegalArgumentException("Union does not include type " + type.toString()); } return reader; }