private MajorType getMajorType(MinorType minorType) { MajorType majorType; majorType = Types.optional(minorType); return majorType; }
private static int toSQLType(MinorType minorType) { String sqlTypeName = Types.getSqlTypeName(Types.optional(minorType)); return Types.getJdbcTypeCode(sqlTypeName); } }
private HiveFuncHolder matchAndCreateGenericUDFHolder(Class<? extends GenericUDF> udfClazz, MajorType[] argTypes, ObjectInspector[] argOIs) { // probe UDF to find if the arg types and acceptable // if acceptable create a holder object try { GenericUDF udfInstance = udfClazz.newInstance(); ObjectInspector returnOI = udfInstance.initialize(argOIs); return new HiveFuncHolder( udfClazz, argTypes, returnOI, Types.optional(ObjectInspectorHelper.getDrillType(returnOI)), nonDeterministicUDFs.contains(udfClazz)); } catch (IllegalAccessException | InstantiationException e) { logger.debug("Failed to instantiate class", e); } catch (Exception e) { /*ignore this*/ } return null; }
@Override public MajorType getOutputType(List<LogicalExpression> expressions) { for(LogicalExpression e : expressions){ if(e.getMajorType().getMode() == DataMode.OPTIONAL){ return Types.optional(outputMinorType); } } return Types.required(outputMinorType); } }
private HiveFuncHolder matchAndCreateUDFHolder(String udfName, Class<? extends UDF> udfClazz, MajorType[] argTypes, ObjectInspector[] argOIs) { try { GenericUDF udfInstance = new GenericUDFBridge(udfName, false/* is operator */, udfClazz.getName()); ObjectInspector returnOI = udfInstance.initialize(argOIs); return new HiveFuncHolder( udfName, udfClazz, argTypes, returnOI, Types.optional(ObjectInspectorHelper.getDrillType(returnOI)), nonDeterministicUDFs.contains(udfClazz)); } catch (Exception e) { /*ignore this*/ } return null; }
@Override public ListWriter list(String name) { FieldWriter writer = fields.get(name.toLowerCase()); int vectorCount = container.size(); if(writer == null) { if (!unionEnabled){ writer = new SingleListWriter(name,container,this); } else{ writer = new PromotableWriter(container.addOrGet(name, Types.optional(MinorType.LIST), ListVector.class), container); } if (container.size() > vectorCount) { writer.allocate(); } writer.setPosition(currentChildIndex); fields.put(name.toLowerCase(), writer); } return writer; }
private UnionVector createUnion() { final MaterializedField newField = MaterializedField.create(UNION_VECTOR_NAME, Types.optional(MinorType.UNION)); final UnionVector unionVector = new UnionVector(newField, allocator, null); // For efficiency, should not create a reader that will never be used. // Keeping for backward compatibility. // // This vector already creates a reader for every vector. The reader isn't used for // the ResultSetVector, but may be used by older code. Someone can perhaps // track down uses, I kept this code. The Union vector is normally created in the // older "complex writer" which may use this reader. // // Moving forward, we should revisit union vectors (and the older complex writer). // At that time, we can determine if the vector needs to own a reader, or if // the reader can be created as needed. // If we create a "result set reader" that works cross-batch in parallel with the // result set loader (for writing), then vectors would not carry their own readers. // // Yes indeed, union vectors are a mess. reader = new UnionListReader(this); return unionVector; }
@Override public ListWriter list(String name) { FieldWriter writer = fields.get(name.toLowerCase()); int vectorCount = container.size(); if(writer == null) { if (!unionEnabled){ writer = new SingleListWriter(name,container,this); } else{ writer = new PromotableWriter(container.addOrGet(name, Types.optional(MinorType.LIST), ListVector.class), container); } if (container.size() > vectorCount) { writer.allocate(); } writer.setPosition(idx()); fields.put(name.toLowerCase(), writer); } return writer; }
@Override protected FieldWriter getWriter(MinorType type) { if (state == State.UNION) { return writer; } if (state == State.UNTYPED) { if (type == null) { return null; } ValueVector v = listVector.addOrGetVector(new VectorDescriptor(Types.optional(type))).getVector(); v.allocateNew(); setWriter(v); writer.setPosition(position); } if (type != this.type) { return promoteToUnion(); } return writer; }
TYPES[minorType.getNumber()] = Types.optional(minorType);
majorType = Types.optional(minorType); } else { majorType = Types.required(minorType);
private FieldWriter promoteToUnion() { String name = vector.getField().getName(); TransferPair tp = vector.getTransferPair(vector.getField().getType().getMinorType().name().toLowerCase(), vector.getAllocator()); tp.transfer(); if (parentContainer != null) { unionVector = parentContainer.addOrGet(name, Types.optional(MinorType.UNION), UnionVector.class); } else if (listVector != null) { unionVector = listVector.promoteToUnion(); } unionVector.addVector(tp.getTo()); writer = new UnionWriter(unionVector); writer.setPosition(idx()); for (int i = 0; i < idx(); i++) { unionVector.getMutator().setType(i, vector.getField().getType().getMinorType()); } vector = null; state = State.UNION; return writer; }
public AbstractStringWriter(String fieldName, DrillBuf managedBuf) { super(fieldName, Types.optional(MinorType.VARCHAR)); this.data = managedBuf; ensureLength(100); }
/** * Create nullable major type using given minor type * and wraps it in typed null constant. * * @param type minor type * @return typed null constant instance */ private TypedNullConstant createNullExpr(MinorType type) { return new TypedNullConstant(Types.optional(type)); }
@Override public void define(OutputMutator outputMutator) throws SchemaChangeException { MaterializedField field = MaterializedField.create(getName(), Types.optional(MinorType.INT)); mutator = outputMutator.addField(field, NullableIntVector.class).getMutator(); }
@Override public void define(OutputMutator outputMutator) throws SchemaChangeException { MaterializedField field = MaterializedField.create(getName(), Types.optional(MinorType.FLOAT8)); mutator = outputMutator.addField(field, NullableFloat8Vector.class).getMutator(); }
@Override public void define(OutputMutator outputMutator) throws SchemaChangeException { MaterializedField field = MaterializedField.create(getName(), Types.optional(MinorType.VARCHAR)); mutator = outputMutator.addField(field, NullableVarCharVector.class).getMutator(); }
@Override public void define(OutputMutator outputMutator) throws SchemaChangeException { MaterializedField field = MaterializedField.create(getName(), Types.optional(MinorType.BIGINT)); mutator = outputMutator.addField(field, NullableBigIntVector.class).getMutator(); }
@Override public void define(OutputMutator outputMutator) throws SchemaChangeException { MaterializedField field = MaterializedField.create(getName(), Types.optional(MinorType.TIMESTAMP)); mutator = outputMutator.addField(field, NullableTimeStampVector.class).getMutator(); }
@Override public void define(OutputMutator outputMutator) throws SchemaChangeException { MaterializedField field = MaterializedField.create(getName(), Types.optional(MinorType.SMALLINT)); mutator = outputMutator.addField(field, NullableSmallIntVector.class).getMutator(); }