@Override public MajorType getOutputType(List<LogicalExpression> expressions) { for(LogicalExpression e : expressions){ if(e.getMajorType().getMode() == DataMode.OPTIONAL){ return e.getMajorType(); } } return expressions.get(0).getMajorType(); } }
public MaterializedField getOtherNullableVersion() { MajorType mt = type; DataMode newDataMode; switch (mt.getMode()){ case OPTIONAL: newDataMode = DataMode.REQUIRED; break; case REQUIRED: newDataMode = DataMode.OPTIONAL; break; default: throw new UnsupportedOperationException(); } return new MaterializedField(name, mt.toBuilder().setMode(newDataMode).build(), children); }
@Override public void updateSchema(VectorAccessible batch) throws IOException { BatchSchema schema = batch.getSchema(); int i = 0; try { if (!checkForTable(name)) { List<ColumnSchema> columns = new ArrayList<>(); for (MaterializedField f : schema) { columns.add(new ColumnSchema.ColumnSchemaBuilder(f.getName(), getType(f.getType())) .nullable(f.getType().getMode() == DataMode.OPTIONAL) .key(i == 0).build()); i++; } Schema kuduSchema = new Schema(columns); table = client.createTable(name, kuduSchema, new CreateTableOptions()); } } catch (Exception e) { throw new IOException(e); } }
/** * Build a 2+D array reader. The backing vector must be a repeated * list. The element reader must itself be a repeated list, or a * repeated of some other type. * * @param schema * @param listAccessor * @param elementReader * @return */ public static AbstractObjectReader buildRepeatedList(ColumnMetadata schema, VectorAccessor listAccessor, AbstractObjectReader elementReader) { assert schema.isArray(); assert listAccessor.type().getMinorType() == MinorType.LIST; assert listAccessor.type().getMode() == DataMode.REPEATED; assert elementReader.type() == ObjectType.ARRAY; // Create the array over whatever it is that the list holds. ArrayReaderImpl arrayReader = new ArrayReaderImpl(schema, listAccessor, elementReader); // The repeated list has no bits vector, all values are non-null. arrayReader.bindNullState(NullStateReaders.REQUIRED_STATE_READER); // Wrap it all in an object reader. return new ArrayObjectReader(arrayReader); }
/** * Checks if given major type is string scalar type. * * @param type major type * @return true if given major type is scalar string, false otherwise */ public static boolean isScalarStringType(final MajorType type) { if (type.getMode() == REPEATED) { return false; } switch(type.getMinorType()) { case FIXEDCHAR: case FIXED16CHAR: case VARCHAR: case VAR16CHAR: return true; default: return false; } }
public static boolean softEquals(final MajorType a, final MajorType b, final boolean allowNullSwap) { if (a.getMinorType() != b.getMinorType()) { return false; } if (allowNullSwap) { switch (a.getMode()) { case OPTIONAL: case REQUIRED: switch (b.getMode()) { case OPTIONAL: case REQUIRED: return true; default: } default: } } return a.getMode() == b.getMode(); }
/** * Add a vector that matches the argument. Transfer the buffer from the argument * to the new vector. * * @param v the vector to clone and add * @return the cloned vector that now holds the data from the argument */ public ValueVector addVector(ValueVector v) { String name = v.getField().getType().getMinorType().name().toLowerCase(); MajorType type = v.getField().getType(); MinorType minorType = type.getMinorType(); Preconditions.checkState(internalMap.getChild(name) == null, String.format("%s vector already exists", name)); final ValueVector newVector = internalMap.addOrGet(name, type, BasicTypeHelper.getValueVectorClass(minorType, type.getMode())); v.makeTransferPair(newVector).transfer(); internalMap.putChild(name, newVector); cachedSubtypes[minorType.ordinal()] = newVector; addSubType(minorType); return newVector; }
public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.common.types.TypeProtos.MajorType message) throws java.io.IOException { if(message.hasMinorType()) output.writeEnum(1, message.getMinorType().getNumber(), false); if(message.hasMode()) output.writeEnum(2, message.getMode().getNumber(), false); if(message.hasWidth()) output.writeInt32(3, message.getWidth(), false); if(message.hasPrecision()) output.writeInt32(4, message.getPrecision(), false); if(message.hasScale()) output.writeInt32(5, message.getScale(), false); if(message.hasTimeZone()) output.writeInt32(6, message.getTimeZone(), false); for(org.apache.drill.common.types.TypeProtos.MinorType subType : message.getSubTypeList()) output.writeEnum(7, subType.getNumber(), true); } public boolean isInitialized(org.apache.drill.common.types.TypeProtos.MajorType message)
/** * Add an externally-created subtype vector. The vector must represent a type that * does not yet exist in the union, and must be of OPTIONAL mode. Does not call * the callback since the client (presumably) knows that it is adding the type. * The caller must also allocate the buffer for the vector. * * @param vector subtype vector to add */ public void addType(ValueVector vector) { MinorType type = vector.getField().getType().getMinorType(); assert subtype(type) == null; assert vector.getField().getType().getMode() == DataMode.OPTIONAL; assert vector.getField().getName().equals(type.name().toLowerCase()); cachedSubtypes[type.ordinal()] = vector; internalMap.putChild(type.name(), vector); addSubType(type); }
public DataMode getDataMode() { return type.getMode(); }
public boolean isNullable() { return type.getMode() == DataMode.OPTIONAL; } public DataMode getDataMode() { return type.getMode(); }
public static boolean isRepeated(final MajorType type) { return type.getMode() == REPEATED; }
MajorType getLastPathType() { if ((this.getField().getType().getMinorType() == MinorType.LIST && this.getField().getType().getMode() == DataMode.REPEATED)) { // Use Repeated scalar type instead of Required List. VectorWithOrdinal vord = getChildVectorWithOrdinal(null); ValueVector v = vord.vector; if (!(v instanceof AbstractContainerVector)) { return v.getField().getType(); } } else if (this.getField().getType().getMinorType() == MinorType.MAP && this.getField().getType().getMode() == DataMode.REPEATED) { // Use Required Map return this.getField().getType().toBuilder().setMode(DataMode.REQUIRED).build(); } return this.getField().getType(); }
/*** * Gets SQL data type name for given Drill RPC-/protobuf-level data type. * @return * canonical keyword sequence for SQL data type (leading keywords in * corresponding {@code <data type>}; what * {@code INFORMATION_SCHEMA.COLUMNS.TYPE_NAME} would list) */ public static String getSqlTypeName(final MajorType type) { if (type.getMode() == DataMode.REPEATED || type.getMinorType() == MinorType.LIST) { return "ARRAY"; } return getBaseSqlTypeName(type); }
private ValueVector getValueVector(MinorType minorType, MajorType majorType, MaterializedField field) throws SchemaChangeException { final Class<? extends ValueVector> clazz = TypeHelper.getValueVectorClass( minorType, majorType.getMode()); ValueVector vector = output.addField(field, clazz); vector.allocateNew(); return vector; }
public static String getSqlModeName(final MajorType type) { switch (type.getMode()) { case REQUIRED: return "NOT NULL"; case OPTIONAL: return "NULLABLE"; case REPEATED: return "ARRAY"; default: return "UNKNOWN"; } }
@Override public String toString() { return this.path.getRootSegment().getPath() + "(" + type.getMinorType() + "_" + type.getMode() +")"; }
@Override public MajorType getMajorType() { // If any of argumgnet of a boolean "and"/"or" is nullable, the result is nullable bit. // Otherwise, it's non-nullable bit. for (LogicalExpression e : args) { if (e.getMajorType().getMode() == DataMode.OPTIONAL) { return Types.OPTIONAL_BIT; } } return Types.REQUIRED_BIT; }
@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); } }