setState(144); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.DECIMAL9).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build(); setState(152); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.DECIMAL18).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build(); setState(160); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.DECIMAL28DENSE).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build(); setState(168); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.DECIMAL28SPARSE).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build(); setState(176); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.DECIMAL38DENSE).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build(); setState(184); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.DECIMAL38SPARSE).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build(); setState(192); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.VARDECIMAL).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build();
@Override public MajorType getMajorType() { if (outputType != null) { return outputType; } MajorType elseType = elseExpression.getMajorType(); MajorType ifType = ifCondition.expression.getMajorType(); if (elseType.getMinorType() == MinorType.UNION) { Set<MinorType> subtypes = Sets.newHashSet(); for (MinorType subtype : elseType.getSubTypeList()) { subtypes.add(subtype); } for (MinorType subtype : ifType.getSubTypeList()) { subtypes.add(subtype); } MajorType.Builder builder = MajorType.newBuilder().setMinorType(MinorType.UNION).setMode(DataMode.OPTIONAL); for (MinorType subtype : subtypes) { builder.addSubType(subtype); } return builder.build(); } MajorType.Builder builder = MajorType.newBuilder().setMinorType(ifType.getMinorType()); builder.setMode(elseType.getMode() == DataMode.OPTIONAL || ifType.getMode() == DataMode.OPTIONAL ? DataMode.OPTIONAL : elseType.getMode()); builder = Types.calculateTypePrecisionAndScale(ifType, elseType, builder); return builder.build(); }
subBuilder.mergeFrom(majorType_); majorType_ = subBuilder.buildPartial();
setState(144); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.DECIMAL9).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build(); setState(152); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.DECIMAL18).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build(); setState(160); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.DECIMAL28DENSE).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build(); setState(168); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.DECIMAL28SPARSE).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build(); setState(176); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.DECIMAL38DENSE).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build(); setState(184); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.DECIMAL38SPARSE).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build(); setState(192); match(CParen); ((NumTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.VARDECIMAL).setMode(DataMode.REQUIRED).setPrecision(((NumTypeContext)_localctx).precision.value.intValue()).setScale(((NumTypeContext)_localctx).scale.value.intValue()).build();
if (thenType != elseType && !(thenType == MinorType.NULL || elseType == MinorType.NULL)) { MajorType.Builder builder = MajorType.newBuilder().setMinorType(MinorType.UNION).setMode(DataMode.OPTIONAL); if (thenType == MinorType.UNION) { for (MinorType subType : conditions.expression.getMajorType().getSubTypeList()) { builder.addSubType(subType); builder.addSubType(thenType); builder.addSubType(subType); builder.addSubType(elseType); outputType = builder.build(); conditions = new IfExpression.IfCondition(newCondition, addCastExpression(conditions.expression, outputType, functionLookupContext, errorCollector, false));
subBuilder.mergeFrom(majorType_); majorType_ = subBuilder.buildPartial();
parmType = MajorType.newBuilder().setMinorType(parmType.getMinorType()).setMode(parmType.getMode()). setScale(currentArg.getMajorType().getScale()).setPrecision(computePrecision(currentArg)).build(); MajorType majorType = MajorType.newBuilder() .setMinorType(MinorType.VARDECIMAL) .setMode(funcExprMajorType.getMode()) .setScale(funcExprMajorType.getScale()) .setPrecision(funcExprMajorType.getPrecision()) .build(); return addCastExpression(funcExpr, majorType, functionLookupContext, errorCollector); parmType = MajorType.newBuilder().setMinorType(parmType.getMinorType()).setMode(parmType.getMode()). setScale(currentArg.getMajorType().getScale()).setPrecision(computePrecision(currentArg)).build();
case "VARCHAR": case "CHAR": castType = Types.required(MinorType.VARCHAR).toBuilder().setPrecision(call.getType().getPrecision()).build(); break; case "INTEGER": TypeProtos.MajorType .newBuilder() .setMinorType(MinorType.VARDECIMAL) .setPrecision(precision) .setScale(scale) .build(); break;
builder.addId(id).remainder(expectedPath.getRootSegment().getChild()); List<MinorType> minorTypes = ((UnionVector) vector).getSubTypes(); MajorType.Builder majorTypeBuilder = MajorType.newBuilder().setMinorType(MinorType.UNION); for (MinorType type : minorTypes) { majorTypeBuilder.addSubType(type); MajorType majorType = majorTypeBuilder.build(); builder.intermediateType(majorType); if (seg.isLastPath()) { builder.remainder(child); builder.withIndex(); builder.finalType(vector.getField().getType().toBuilder().setMode(DataMode.OPTIONAL).build()); return builder.build(); } else {
for (Ordering od : orderings) { final LogicalExpression expr = ExpressionTreeMaterializer.materialize(od.getExpr(), incoming, collector, context.getFunctionRegistry()); TypeProtos.MajorType.Builder builder = TypeProtos.MajorType.newBuilder().mergeFrom(expr.getMajorType()) .clearMode().setMode(TypeProtos.DataMode.REQUIRED); TypeProtos.MajorType newType = builder.build(); MaterializedField outputField = MaterializedField.create("f" + i++, newType); if (collector.hasErrors()) {
match(CParen); if (((CastCallContext)_localctx).repeat != null && ((CastCallContext)_localctx).repeat.isRep.compareTo(Boolean.TRUE)==0) ((CastCallContext)_localctx).e = FunctionCallFactory.createCast(TypeProtos.MajorType.newBuilder().mergeFrom(((CastCallContext)_localctx).dataType.type).setMode(DataMode.REPEATED).build(), pos(((CastCallContext)_localctx).Cast), ((CastCallContext)_localctx).expression.e); else ((CastCallContext)_localctx).e = FunctionCallFactory.createCast(((CastCallContext)_localctx).dataType.type, pos(((CastCallContext)_localctx).Cast), ((CastCallContext)_localctx).expression.e);
Set<MinorType> types = typeSetMap.get(path); if (types.size() > 1) { MajorType.Builder builder = MajorType.newBuilder().setMinorType(MinorType.UNION).setMode(DataMode.OPTIONAL); for (MinorType t : types) { builder.addSubType(t); MaterializedField field = MaterializedField.create(path.getLastSegment().getNameSegment().getPath(), builder.build()); fields.add(field); } else {
setState(198); ((CharTypeContext)_localctx).typeLen = typeLen(); ((CharTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.VARCHAR).setMode(DataMode.REQUIRED).setPrecision(((CharTypeContext)_localctx).typeLen.length.intValue()).build(); setState(202); ((CharTypeContext)_localctx).typeLen = typeLen(); ((CharTypeContext)_localctx).type = TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.VARBINARY).setMode(DataMode.REQUIRED).setPrecision(((CharTypeContext)_localctx).typeLen.length.intValue()).build();
Types.required(TypeProtos.MinorType.VARCHAR).toBuilder().setWidth( getOriginalScanRel().getCluster().getTypeFactory().createSqlType(SqlTypeName.VARCHAR).getPrecision()).build(); case "LONG": case "BIGINT": return Types.required(TypeProtos.MinorType.BIT); case "BINARY": return Types.required(TypeProtos.MinorType.VARBINARY).toBuilder().build(); case "ANY": case "DECIMAL":
return; case 1: builder.setMinorType(org.apache.drill.common.types.TypeProtos.MinorType.valueOf(input.readEnum())); break; case 2: builder.setMode(org.apache.drill.common.types.TypeProtos.DataMode.valueOf(input.readEnum())); break; case 3: builder.setWidth(input.readInt32()); break; case 4: builder.setPrecision(input.readInt32()); break; case 5: builder.setScale(input.readInt32()); break; case 6: builder.setTimeZone(input.readInt32()); break; case 7: builder.addSubType(org.apache.drill.common.types.TypeProtos.MinorType.valueOf(input.readEnum())); break; default:
public Builder mergeFrom(org.apache.drill.common.types.TypeProtos.MajorType other) { if (other == org.apache.drill.common.types.TypeProtos.MajorType.getDefaultInstance()) return this; if (other.hasMinorType()) { setMinorType(other.getMinorType()); setMode(other.getMode()); setWidth(other.getWidth()); setPrecision(other.getPrecision()); setScale(other.getScale()); setTimeZone(other.getTimeZone()); bitField0_ = (bitField0_ & ~0x00000040); } else { ensureSubTypeIsMutable(); subType_.addAll(other.subType_); onChanged(); this.mergeUnknownFields(other.getUnknownFields()); return this;
} else { final TypeProtos.MajorType.Builder builder = TypeProtos.MajorType.newBuilder() .setMode(field.getType().isNullable() ? TypeProtos.DataMode.OPTIONAL : TypeProtos.DataMode.REQUIRED) .setMinorType(TypeInferenceUtils.getDrillTypeFromCalciteType(sqlTypeName)); builder.setScale(field.getType().getScale()); builder.setPrecision(field.getType().getPrecision()); } else if (TypeInferenceUtils.isScalarStringType(sqlTypeName)) { builder.setPrecision(field.getType().getPrecision()); columnTypes.add(builder.build());
/** * This return type is used by add and subtract functions for decimal data type. * DecimalScalePrecisionAddFunction is used to compute the output types' scale and precision. * * @param logicalExpressions logical expressions * @param attributes function attributes * @return return type */ @Override public TypeProtos.MajorType getType(List<LogicalExpression> logicalExpressions, FunctionAttributes attributes) { TypeProtos.DataMode mode = FunctionUtils.getReturnTypeDataMode(logicalExpressions, attributes); assert logicalExpressions.size() == 2; TypeProtos.MajorType leftMajorType = logicalExpressions.get(0).getMajorType(); TypeProtos.MajorType rightMajorType = logicalExpressions.get(1).getMajorType(); DecimalScalePrecisionAddFunction outputScalePrec = new DecimalScalePrecisionAddFunction( DecimalUtility.getDefaultPrecision(leftMajorType.getMinorType(), leftMajorType.getPrecision()), leftMajorType.getScale(), DecimalUtility.getDefaultPrecision(rightMajorType.getMinorType(), rightMajorType.getPrecision()), rightMajorType.getScale()); return TypeProtos.MajorType.newBuilder() .setMinorType(TypeProtos.MinorType.VARDECIMAL) .setScale(outputScalePrec.getOutputScale()) .setPrecision(outputScalePrec.getOutputPrecision()) .setMode(mode) .build(); } }
/** * Calculates return type and its nullability. Precision and scale is not included. * * @param logicalExpressions logical expressions * @param attributes function attributes * @return return type */ @Override public TypeProtos.MajorType getType(List<LogicalExpression> logicalExpressions, FunctionAttributes attributes) { if (attributes.getReturnValue().getType().getMinorType() == TypeProtos.MinorType.UNION) { final Set<TypeProtos.MinorType> subTypes = Sets.newHashSet(); for (final ValueReference ref : attributes.getParameters()) { subTypes.add(ref.getType().getMinorType()); } final TypeProtos.MajorType.Builder builder = TypeProtos.MajorType.newBuilder() .setMinorType(TypeProtos.MinorType.UNION) .setMode(TypeProtos.DataMode.OPTIONAL); for (final TypeProtos.MinorType subType : subTypes) { builder.addSubType(subType); } return builder.build(); } return attributes.getReturnValue().getType().toBuilder() .setMode(FunctionUtils.getReturnTypeDataMode(logicalExpressions, attributes)) .build(); } }
/** * Given a SqlOperatorBinding, convert it to FunctionCall * @param opBinding the given SqlOperatorBinding * @return FunctionCall the converted FunctionCall */ public static FunctionCall convertSqlOperatorBindingToFunctionCall(final SqlOperatorBinding opBinding) { final List<LogicalExpression> args = Lists.newArrayList(); for (int i = 0; i < opBinding.getOperandCount(); ++i) { final RelDataType type = opBinding.getOperandType(i); final TypeProtos.MinorType minorType = getDrillTypeFromCalciteType(type); TypeProtos.DataMode dataMode = type.isNullable() ? TypeProtos.DataMode.OPTIONAL : TypeProtos.DataMode.REQUIRED; TypeProtos.MajorType.Builder builder = TypeProtos.MajorType.newBuilder() .setMode(dataMode) .setMinorType(minorType); if (Types.isDecimalType(minorType)) { builder .setScale(type.getScale()) .setPrecision(type.getPrecision()); } args.add(new MajorTypeInLogicalExpression(builder.build())); } final String drillFuncName = FunctionCallFactory.replaceOpWithFuncName(opBinding.getOperator().getName()); return new FunctionCall( drillFuncName, args, ExpressionPosition.UNKNOWN); }