Java Code Examples for org.apache.calcite.plan.RelOptCluster#getTypeFactory()
The following examples show how to use
org.apache.calcite.plan.RelOptCluster#getTypeFactory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassRowTypeCache.java From mat-calcite-plugin with Apache License 2.0 | 6 votes |
@Override public RexNode apply(RexBuilderContext context) { RelOptCluster cluster = context.getCluster(); RelDataTypeFactory typeFactory = cluster.getTypeFactory(); final SqlFunction UDF = new SqlUserDefinedFunction( new SqlIdentifier("RESOLVE_SIMPLE", SqlParserPos.ZERO), ReturnTypes.explicit(typeFactory.createJavaType(Object.class)), null, OperandTypes.ANY_ANY, ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false), typeFactory.createJavaType(int.class)), ScalarFunctionImpl.create(IObjectMethods.class, "resolveSimpleValue")); RexBuilder b = context.getBuilder(); RexNode rexNode = b.makeCall(UDF, context.getIObject(), b.makeLiteral(name)); return b.makeCast(dataType, rexNode); }
Example 2
Source File: ClassRowTypeCache.java From mat-calcite-plugin with Apache License 2.0 | 6 votes |
@Override public RexNode apply(RexBuilderContext context) { RelOptCluster cluster = context.getCluster(); RelDataTypeFactory typeFactory = cluster.getTypeFactory(); final SqlFunction UDF = new SqlUserDefinedFunction( new SqlIdentifier("RESOLVE_REFERENCE", SqlParserPos.ZERO), ReturnTypes.explicit(typeFactory.createJavaType(HeapReference.class)), null, OperandTypes.ANY_ANY, ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false), typeFactory.createJavaType(String.class)), ScalarFunctionImpl.create(IObjectMethods.class, "resolveReferenceValue")); RexBuilder b = context.getBuilder(); return b.makeCall(UDF, context.getIObject(), b.makeLiteral(name)); }
Example 3
Source File: FilterFlattenTransposeRule.java From dremio-oss with Apache License 2.0 | 5 votes |
private static List<RexInputRef> asNodes(final RelOptCluster cluster, Iterable<Integer> indices){ final RexBuilder builder = cluster.getRexBuilder(); final RelDataTypeFactory factory = cluster.getTypeFactory(); return FluentIterable.from(indices).transform(new Function<Integer, RexInputRef>(){ @Override public RexInputRef apply(Integer input) { return builder.makeInputRef(factory.createTypeWithNullability(factory.createSqlType(SqlTypeName.ANY), true), input); }}).toList(); }
Example 4
Source File: RexVisitorComplexExprSplitter.java From dremio-oss with Apache License 2.0 | 5 votes |
public RexVisitorComplexExprSplitter(RelOptCluster cluster, FunctionImplementationRegistry funcReg, int firstUnused) { super(true); this.factory = cluster.getTypeFactory(); this.builder = cluster.getRexBuilder(); this.funcReg = funcReg; this.complexExprs = new ArrayList<>(); this.lastUsedIndex = firstUnused; }
Example 5
Source File: ClassRowTypeCache.java From mat-calcite-plugin with Apache License 2.0 | 5 votes |
public RexNode apply(RexBuilderContext context) { RelOptCluster cluster = context.getCluster(); RelDataTypeFactory typeFactory = cluster.getTypeFactory(); final SqlFunction UDF = new SqlUserDefinedFunction( new SqlIdentifier("TO_REFERENCE", SqlParserPos.ZERO), ReturnTypes.explicit(typeFactory.createJavaType(HeapReference.class)), null, OperandTypes.ANY, ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false)), ScalarFunctionImpl.create(ISnapshotMethods.class, "toReference") ); return context.getBuilder().makeCall(UDF, context.getIObject()); }
Example 6
Source File: TraitPropagationTest.java From calcite with Apache License 2.0 | 5 votes |
PhysTable(RelOptCluster cluster) { super(cluster, cluster.traitSet().replace(PHYSICAL).replace(COLLATION)); RelDataTypeFactory typeFactory = cluster.getTypeFactory(); final RelDataType stringType = typeFactory.createJavaType(String.class); final RelDataType integerType = typeFactory.createJavaType(Integer.class); this.rowType = typeFactory.builder().add("s", stringType) .add("i", integerType).build(); }
Example 7
Source File: AggregateReduceFunctionsRule.java From Bats with Apache License 2.0 | 4 votes |
private RexNode reduceRegrSzz( Aggregate oldAggRel, AggregateCall oldCall, List<AggregateCall> newCalls, Map<AggregateCall, RexNode> aggCallMapping, List<RexNode> inputExprs, int xIndex, int yIndex, int nullFilterIndex) { // regr_sxx(x, y) ==> // sum(y * y, x) - sum(y, x) * sum(y, x) / regr_count(x, y) // final RelOptCluster cluster = oldAggRel.getCluster(); final RexBuilder rexBuilder = cluster.getRexBuilder(); final RelDataTypeFactory typeFactory = cluster.getTypeFactory(); final RelDataType argXType = getFieldType(oldAggRel.getInput(), xIndex); final RelDataType argYType = xIndex == yIndex ? argXType : getFieldType(oldAggRel.getInput(), yIndex); final RelDataType nullFilterIndexType = nullFilterIndex == yIndex ? argYType : getFieldType(oldAggRel.getInput(), yIndex); final RelDataType oldCallType = typeFactory.createTypeWithNullability(oldCall.getType(), argXType.isNullable() || argYType.isNullable() || nullFilterIndexType.isNullable()); final RexNode argX = rexBuilder.ensureType(oldCallType, inputExprs.get(xIndex), true); final RexNode argY = rexBuilder.ensureType(oldCallType, inputExprs.get(yIndex), true); final RexNode argNullFilter = rexBuilder.ensureType(oldCallType, inputExprs.get(nullFilterIndex), true); final RexNode argXArgY = rexBuilder.makeCall(SqlStdOperatorTable.MULTIPLY, argX, argY); final int argSquaredOrdinal = lookupOrAdd(inputExprs, argXArgY); final RexNode argXAndYNotNullFilter = rexBuilder.makeCall(SqlStdOperatorTable.AND, rexBuilder.makeCall(SqlStdOperatorTable.AND, rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, argX), rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, argY)), rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, argNullFilter)); final int argXAndYNotNullFilterOrdinal = lookupOrAdd(inputExprs, argXAndYNotNullFilter); final RexNode sumXY = getSumAggregatedRexNodeWithBinding( oldAggRel, oldCall, newCalls, aggCallMapping, argXArgY.getType(), argSquaredOrdinal, argXAndYNotNullFilterOrdinal); final RexNode sumXYCast = rexBuilder.ensureType(oldCallType, sumXY, true); final RexNode sumX = getSumAggregatedRexNode(oldAggRel, oldCall, newCalls, aggCallMapping, rexBuilder, xIndex, argXAndYNotNullFilterOrdinal); final RexNode sumY = xIndex == yIndex ? sumX : getSumAggregatedRexNode(oldAggRel, oldCall, newCalls, aggCallMapping, rexBuilder, yIndex, argXAndYNotNullFilterOrdinal); final RexNode sumXSumY = rexBuilder.makeCall(SqlStdOperatorTable.MULTIPLY, sumX, sumY); final RexNode countArg = getRegrCountRexNode(oldAggRel, oldCall, newCalls, aggCallMapping, ImmutableIntList.of(xIndex), ImmutableList.of(argXType), argXAndYNotNullFilterOrdinal); RexLiteral zero = rexBuilder.makeExactLiteral(BigDecimal.ZERO); RexNode nul = rexBuilder.constantNull(); final RexNode avgSumXSumY = rexBuilder.makeCall(SqlStdOperatorTable.CASE, rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, countArg, zero), nul, rexBuilder.makeCall(SqlStdOperatorTable.DIVIDE, sumXSumY, countArg)); final RexNode avgSumXSumYCast = rexBuilder.ensureType(oldCallType, avgSumXSumY, true); final RexNode result = rexBuilder.makeCall(SqlStdOperatorTable.MINUS, sumXYCast, avgSumXSumYCast); return rexBuilder.makeCast(oldCall.getType(), result); }
Example 8
Source File: ConvertFromJsonConverter.java From dremio-oss with Apache License 2.0 | 4 votes |
public ConvertFromJsonConverter(QueryContext context, RelOptCluster cluster) { this.context = context; this.query = cluster.getMetadataQuery(); this.factory = cluster.getTypeFactory(); }
Example 9
Source File: AggregateReduceFunctionsRule.java From calcite with Apache License 2.0 | 4 votes |
private RexNode reduceRegrSzz( Aggregate oldAggRel, AggregateCall oldCall, List<AggregateCall> newCalls, Map<AggregateCall, RexNode> aggCallMapping, List<RexNode> inputExprs, int xIndex, int yIndex, int nullFilterIndex) { // regr_sxx(x, y) ==> // sum(y * y, x) - sum(y, x) * sum(y, x) / regr_count(x, y) // final RelOptCluster cluster = oldAggRel.getCluster(); final RexBuilder rexBuilder = cluster.getRexBuilder(); final RelDataTypeFactory typeFactory = cluster.getTypeFactory(); final RelDataType argXType = getFieldType(oldAggRel.getInput(), xIndex); final RelDataType argYType = xIndex == yIndex ? argXType : getFieldType(oldAggRel.getInput(), yIndex); final RelDataType nullFilterIndexType = nullFilterIndex == yIndex ? argYType : getFieldType(oldAggRel.getInput(), yIndex); final RelDataType oldCallType = typeFactory.createTypeWithNullability(oldCall.getType(), argXType.isNullable() || argYType.isNullable() || nullFilterIndexType.isNullable()); final RexNode argX = rexBuilder.ensureType(oldCallType, inputExprs.get(xIndex), true); final RexNode argY = rexBuilder.ensureType(oldCallType, inputExprs.get(yIndex), true); final RexNode argNullFilter = rexBuilder.ensureType(oldCallType, inputExprs.get(nullFilterIndex), true); final RexNode argXArgY = rexBuilder.makeCall(SqlStdOperatorTable.MULTIPLY, argX, argY); final int argSquaredOrdinal = lookupOrAdd(inputExprs, argXArgY); final RexNode argXAndYNotNullFilter = rexBuilder.makeCall(SqlStdOperatorTable.AND, rexBuilder.makeCall(SqlStdOperatorTable.AND, rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, argX), rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, argY)), rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, argNullFilter)); final int argXAndYNotNullFilterOrdinal = lookupOrAdd(inputExprs, argXAndYNotNullFilter); final RexNode sumXY = getSumAggregatedRexNodeWithBinding( oldAggRel, oldCall, newCalls, aggCallMapping, argXArgY.getType(), argSquaredOrdinal, argXAndYNotNullFilterOrdinal); final RexNode sumXYCast = rexBuilder.ensureType(oldCallType, sumXY, true); final RexNode sumX = getSumAggregatedRexNode(oldAggRel, oldCall, newCalls, aggCallMapping, rexBuilder, xIndex, argXAndYNotNullFilterOrdinal); final RexNode sumY = xIndex == yIndex ? sumX : getSumAggregatedRexNode(oldAggRel, oldCall, newCalls, aggCallMapping, rexBuilder, yIndex, argXAndYNotNullFilterOrdinal); final RexNode sumXSumY = rexBuilder.makeCall(SqlStdOperatorTable.MULTIPLY, sumX, sumY); final RexNode countArg = getRegrCountRexNode(oldAggRel, oldCall, newCalls, aggCallMapping, ImmutableIntList.of(xIndex), ImmutableList.of(argXType), argXAndYNotNullFilterOrdinal); RexLiteral zero = rexBuilder.makeExactLiteral(BigDecimal.ZERO); RexNode nul = rexBuilder.makeNullLiteral(zero.getType()); final RexNode avgSumXSumY = rexBuilder.makeCall(SqlStdOperatorTable.CASE, rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, countArg, zero), nul, rexBuilder.makeCall(SqlStdOperatorTable.DIVIDE, sumXSumY, countArg)); final RexNode avgSumXSumYCast = rexBuilder.ensureType(oldCallType, avgSumXSumY, true); final RexNode result = rexBuilder.makeCall(SqlStdOperatorTable.MINUS, sumXYCast, avgSumXSumYCast); return rexBuilder.makeCast(oldCall.getType(), result); }
Example 10
Source File: LixToRelTranslator.java From calcite with Apache License 2.0 | 4 votes |
LixToRelTranslator(RelOptCluster cluster, Prepare preparingStmt) { this.cluster = cluster; this.preparingStmt = preparingStmt; this.typeFactory = (JavaTypeFactory) cluster.getTypeFactory(); }