/** * <code>optional .common.MajorType major_type = 1;</code> * * <pre> * the type associated with this field. * </pre> */ public Builder setMajorType( com.dremio.common.types.TypeProtos.MajorType.Builder builderForValue) { if (majorTypeBuilder_ == null) { majorType_ = builderForValue.build(); onChanged(); } else { majorTypeBuilder_.setMessage(builderForValue.build()); } bitField0_ |= 0x00000001; return this; } /**
final int dataTypeLength; if (globalDictionaryColumns.containsKey(fieldName)) { mt = MajorType.newBuilder().setMinorType(MinorType.INT).setMode(getDataMode(column)).build(); dataTypeLength = getTypeLengthInBits(PrimitiveType.PrimitiveTypeName.INT32); } else {
@Test @Ignore public void testUnionDistinctBothEmptyJson() throws Exception { final String rootEmpty = FileUtils.getResourceAsFile("/project/pushdown/empty.json").toURI().toString(); final String query = String.format( "select key from dfs_test.\"%s\" " + "union " + "select key from dfs_test.\"%s\"", rootEmpty, rootEmpty); final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); final MajorType majorType = TypeProtos.MajorType.newBuilder() .setMinorType(TypeProtos.MinorType.INT) .setMode(TypeProtos.DataMode.OPTIONAL) .build(); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("key"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .build() .run(); }
.setMode(DataMode.OPTIONAL) .setWidth(call.getType().getPrecision()) .build(); break; .setPrecision(precision) .setScale(scale) .build(); } else { throw new UnsupportedOperationException("Only Decimal types with precision range 0 - 38 is supported"); .setMode(DataMode.OPTIONAL) .setPrecision(call.getType().getPrecision()) .build(); break; case TIMESTAMP:
return builder.build();
.unOrdered() .csvBaselineFile("testframework/decimal_test.tsv") .baselineTypes(MajorType.newBuilder().setMinorType(MinorType.DECIMAL).setMode(DataMode.REQUIRED).setPrecision(32).setScale(2).build())
.setScale(decimalField.getMajorType().getScale()); decimalField.setMajorType(majorTypeBuilder.build()); decimalField.setBufferLength(decimalField.getBufferLength() + 8*valueCount); drillBuffer.writerIndex(dataBuffer.readableBytes() + 8*valueCount);
/** * Helper method that converts Hive type definition to Dremio type definition. * * @param typeInfo Hive type info * @param options * @return */ public static MajorType getMajorTypeFromHiveTypeInfo(final TypeInfo typeInfo, final OptionManager options) { switch (typeInfo.getCategory()) { case PRIMITIVE: { PrimitiveTypeInfo primitiveTypeInfo = (PrimitiveTypeInfo) typeInfo; MinorType minorType = getMinorTypeFromHivePrimitiveTypeInfo(primitiveTypeInfo, options); MajorType.Builder typeBuilder = MajorType.newBuilder().setMinorType(getMinorTypeFromArrowMinorType(minorType)) .setMode(DataMode.OPTIONAL); // Hive columns (both regular and partition) could have null values if (primitiveTypeInfo.getPrimitiveCategory() == PrimitiveCategory.DECIMAL) { DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) primitiveTypeInfo; typeBuilder.setPrecision(decimalTypeInfo.precision()) .setScale(decimalTypeInfo.scale()).build(); } return typeBuilder.build(); } case LIST: case MAP: case STRUCT: case UNION: default: throwUnsupportedHiveDataTypeError(typeInfo.getCategory().toString()); } return null; // never reached }
private CastExpression cast(RexCall call) { TerminalExpression argument = (TerminalExpression) call.getOperands().get(0).accept(this); // Casts do not work for metadata columns isMeta(argument, call, true); MajorType target; switch (call.getType().getSqlTypeName()) { case CHAR: case VARCHAR: target = Types.optional(MinorType.VARCHAR).toBuilder().setWidth(call.getType().getPrecision()).build(); break; case INTEGER: target = Types.optional(MinorType.INT); break; case BIGINT: target = Types.optional(MinorType.BIGINT); break; case FLOAT: target = Types.optional(MinorType.FLOAT4); break; case DOUBLE: target = Types.optional(MinorType.FLOAT8); break; case DECIMAL: throw new PredicateAnalyzerException("Cast to DECIMAL type unsupported"); default: target = Types.optional(MinorType.valueOf(call.getType().getSqlTypeName().getName())); } return new CastExpression(target, argument); }
@Ignore("DX-4180") @Test public void testUnionDistinctBothEmptyBatch() throws Exception { String rootSimple = FileUtils.getResourceAsFile("/store/json/booleanData.json").toURI().toString(); final String query = String.format( "select key from dfs_test.\"%s\" where 1 = 0 " + "union " + "select key from dfs_test.\"%s\" where 1 = 0", rootSimple, rootSimple); final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); final MajorType majorType = TypeProtos.MajorType.newBuilder() .setMinorType(TypeProtos.MinorType.INT) .setMode(TypeProtos.DataMode.OPTIONAL) .build(); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("key"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .build() .run(); }
@JsonIgnore public MajorType getMajorType() { MajorType.Builder b = MajorType.newBuilder(); b.setMode(mode); b.setMinorType(minorType); if (precision != null) { b.setPrecision(precision); } if (width != null) { b.setWidth(width); } if (scale != null) { b.setScale(scale); } return b.build(); }
public static MajorType optional(final MinorType type) { return MajorType.newBuilder().setMode(DataMode.OPTIONAL).setMinorType(type).build(); }
@JsonIgnore public MajorType getMajorType() { MajorType.Builder b = MajorType.newBuilder(); b.setMode(mode); b.setMinorType(minorType); if (precision != null) { b.setPrecision(precision); } if (width != null) { b.setWidth(width); } if (scale != null) { b.setScale(scale); } return b.build(); }
public static MajorType required(final MinorType type) { return MajorType.newBuilder().setMode(DataMode.REQUIRED).setMinorType(type).build(); }
public static MajorType withMode(final MinorType type, final DataMode mode) { return MajorType.newBuilder().setMode(mode).setMinorType(type).build(); }
public static MajorType repeated(final MinorType type) { return MajorType.newBuilder().setMode(REPEATED).setMinorType(type).build(); }
public SerializedField.Builder getMetadataBuilder() { return SerializedField.newBuilder() .setMajorType(MajorType.newBuilder().setMinorType(MinorType.LIST).setMode(DataMode.OPTIONAL).build()) .setNamePart(NamePart.newBuilder().setName(listVector.getField().getName())) .setValueCount(listVector.getValueCount()) .setBufferLength(listVector.getBufferSize()) .addChild(buildOffsetMetadata()) .addChild(buildValidityMetadata()) .addChild(TypeHelper.getMetadata(listVector.vector)); }
public static MajorType withScaleAndPrecision(final MinorType type, final DataMode mode, final int scale, final int precision) { return MajorType.newBuilder().setMinorType(type).setMode(mode).setScale(scale).setPrecision(precision).build(); }
public static TypeProtos.MajorType toMajorType(PrimitiveType.PrimitiveTypeName primitiveTypeName, int length, TypeProtos.DataMode mode, SchemaElement schemaElement, OptionManager options, Field arrowField, final boolean readInt96AsTimeStamp) { MinorType minorType = getMinorType(primitiveTypeName, length, schemaElement, options, arrowField, readInt96AsTimeStamp); TypeProtos.MajorType.Builder typeBuilder = TypeProtos.MajorType.newBuilder().setMinorType(minorType).setMode(mode); if (CoreDecimalUtility.isDecimalType(minorType)) { typeBuilder.setPrecision(schemaElement.getPrecision()).setScale(schemaElement.getScale()); } return typeBuilder.build(); } }