Java Code Examples for org.apache.calcite.tools.Frameworks#withPrepare()
The following examples show how to use
org.apache.calcite.tools.Frameworks#withPrepare() .
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: RexExecutorTest.java From calcite with Apache License 2.0 | 6 votes |
/** * Ensures that for a given context operator, * the correct value is retrieved from the {@link DataContext}. * * @param operator The Operator to check * @param variable The DataContext variable this operator should be bound to * @param value The expected value to retrieve. */ private void testContextLiteral( final SqlOperator operator, final DataContext.Variable variable, final Object value) { Frameworks.withPrepare((cluster, relOptSchema, rootSchema, statement) -> { final RexBuilder rexBuilder = cluster.getRexBuilder(); final RexExecutorImpl executor = new RexExecutorImpl( new SingleValueDataContext(variable.camelName, value)); try { checkConstant(value, builder -> { final List<RexNode> output = new ArrayList<>(); executor.reduce(rexBuilder, ImmutableList.of(rexBuilder.makeCall(operator)), output); return output.get(0); }); } catch (Exception e) { throw TestUtil.rethrow(e); } return null; }); }
Example 2
Source File: RexExecutorTest.java From calcite with Apache License 2.0 | 5 votes |
protected void check(final Action action) throws Exception { Frameworks.withPrepare((cluster, relOptSchema, rootSchema, statement) -> { final RexBuilder rexBuilder = cluster.getRexBuilder(); DataContext dataContext = Schemas.createDataContext(statement.getConnection(), rootSchema); final RexExecutorImpl executor = new RexExecutorImpl(dataContext); action.check(rexBuilder, executor); return null; }); }
Example 3
Source File: MycatRelBuilder.java From Mycat2 with GNU General Public License v3.0 | 4 votes |
public static MycatRelBuilder create(FrameworkConfig config) { return Frameworks.withPrepare(config, (cluster, relOptSchema, rootSchema, statement) -> new MycatRelBuilder(config.getContext(), cluster, relOptSchema)); }
Example 4
Source File: RexImplicationCheckerTest.java From calcite with Apache License 2.0 | 4 votes |
public Fixture() { typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT); rexBuilder = new RexBuilder(typeFactory); boolRelDataType = typeFactory.createJavaType(Boolean.class); intRelDataType = typeFactory.createJavaType(Integer.class); decRelDataType = typeFactory.createJavaType(Double.class); longRelDataType = typeFactory.createJavaType(Long.class); shortDataType = typeFactory.createJavaType(Short.class); byteDataType = typeFactory.createJavaType(Byte.class); floatDataType = typeFactory.createJavaType(Float.class); charDataType = typeFactory.createJavaType(Character.class); dateDataType = typeFactory.createJavaType(Date.class); timestampDataType = typeFactory.createJavaType(Timestamp.class); timeDataType = typeFactory.createJavaType(Time.class); stringDataType = typeFactory.createJavaType(String.class); bl = ref(0, this.boolRelDataType); i = ref(1, intRelDataType); dec = ref(2, decRelDataType); lg = ref(3, longRelDataType); sh = ref(4, shortDataType); by = ref(5, byteDataType); fl = ref(6, floatDataType); ch = ref(7, charDataType); d = ref(8, dateDataType); ts = ref(9, timestampDataType); t = ref(10, timeDataType); str = ref(11, stringDataType); rowType = typeFactory.builder() .add("bool", this.boolRelDataType) .add("int", intRelDataType) .add("dec", decRelDataType) .add("long", longRelDataType) .add("short", shortDataType) .add("byte", byteDataType) .add("float", floatDataType) .add("char", charDataType) .add("date", dateDataType) .add("timestamp", timestampDataType) .add("time", timeDataType) .add("string", stringDataType) .build(); executor = Frameworks.withPrepare( (cluster, relOptSchema, rootSchema, statement) -> new RexExecutorImpl( Schemas.createDataContext(statement.getConnection(), rootSchema))); simplify = new RexSimplify(rexBuilder, RelOptPredicateList.EMPTY, executor) .withParanoid(true); checker = new RexImplicationChecker(rexBuilder, executor, rowType); }