org.apache.calcite.sql.validate.SqlConformance Java Examples
The following examples show how to use
org.apache.calcite.sql.validate.SqlConformance.
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: SqlDialect.java From calcite with Apache License 2.0 | 6 votes |
private ContextImpl(DatabaseProduct databaseProduct, String databaseProductName, String databaseVersion, int databaseMajorVersion, int databaseMinorVersion, String literalQuoteString, String literalEscapedQuoteString, String identifierQuoteString, Casing quotedCasing, Casing unquotedCasing, boolean caseSensitive, SqlConformance conformance, NullCollation nullCollation, RelDataTypeSystem dataTypeSystem, JethroDataSqlDialect.JethroInfo jethroInfo) { this.databaseProduct = Objects.requireNonNull(databaseProduct); this.databaseProductName = databaseProductName; this.databaseVersion = databaseVersion; this.databaseMajorVersion = databaseMajorVersion; this.databaseMinorVersion = databaseMinorVersion; this.literalQuoteString = literalQuoteString; this.literalEscapedQuoteString = literalEscapedQuoteString; this.identifierQuoteString = identifierQuoteString; this.quotedCasing = Objects.requireNonNull(quotedCasing); this.unquotedCasing = Objects.requireNonNull(unquotedCasing); this.caseSensitive = caseSensitive; this.conformance = Objects.requireNonNull(conformance); this.nullCollation = Objects.requireNonNull(nullCollation); this.dataTypeSystem = Objects.requireNonNull(dataTypeSystem); this.jethroInfo = Objects.requireNonNull(jethroInfo); }
Example #2
Source File: PlannerContext.java From flink with Apache License 2.0 | 6 votes |
/** * Returns the SQL parser config for this environment including a custom Calcite configuration. */ private SqlParser.Config getSqlParserConfig() { return JavaScalaConversionUtil.<SqlParser.Config>toJava(getCalciteConfig(tableConfig).getSqlParserConfig()).orElseGet( // we use Java lex because back ticks are easier than double quotes in programming // and cases are preserved () -> { SqlConformance conformance = getSqlConformance(); return SqlParser .configBuilder() .setParserFactory(FlinkSqlParserFactories.create(conformance)) .setConformance(conformance) .setLex(Lex.JAVA) .setIdentifierMaxLength(256) .build(); } ); }
Example #3
Source File: RexToLixTranslator.java From calcite with Apache License 2.0 | 6 votes |
/** * Translates a {@link RexProgram} to a sequence of expressions and * declarations. * * @param program Program to be translated * @param typeFactory Type factory * @param conformance SQL conformance * @param list List of statements, populated with declarations * @param outputPhysType Output type, or null * @param root Root expression * @param inputGetter Generates expressions for inputs * @param correlates Provider of references to the values of correlated * variables * @return Sequence of expressions, optional condition */ public static List<Expression> translateProjects(RexProgram program, JavaTypeFactory typeFactory, SqlConformance conformance, BlockBuilder list, PhysType outputPhysType, Expression root, InputGetter inputGetter, Function1<String, InputGetter> correlates) { List<Type> storageTypes = null; if (outputPhysType != null) { final RelDataType rowType = outputPhysType.getRowType(); storageTypes = new ArrayList<>(rowType.getFieldCount()); for (int i = 0; i < rowType.getFieldCount(); i++) { storageTypes.add(outputPhysType.getJavaFieldType(i)); } } return new RexToLixTranslator(program, typeFactory, root, inputGetter, list, new RexBuilder(typeFactory), conformance, null) .setCorrelates(correlates) .translateList(program.getProjectList(), storageTypes); }
Example #4
Source File: RexToLixTranslator.java From calcite with Apache License 2.0 | 6 votes |
private RexToLixTranslator(RexProgram program, JavaTypeFactory typeFactory, Expression root, InputGetter inputGetter, BlockBuilder list, RexBuilder builder, SqlConformance conformance, Function1<String, InputGetter> correlates) { this.program = program; // may be null this.typeFactory = Objects.requireNonNull(typeFactory); this.conformance = Objects.requireNonNull(conformance); this.root = Objects.requireNonNull(root); this.inputGetter = inputGetter; this.list = Objects.requireNonNull(list); this.builder = Objects.requireNonNull(builder); this.correlates = correlates; // may be null }
Example #5
Source File: SqlDialect.java From calcite with Apache License 2.0 | 6 votes |
/** Returns the {@link SqlConformance} that matches this dialect. * * <p>The base implementation returns its best guess, based upon * {@link #databaseProduct}; sub-classes may override. */ @Nonnull public SqlConformance getConformance() { switch (databaseProduct) { case UNKNOWN: case CALCITE: return SqlConformanceEnum.DEFAULT; case BIG_QUERY: return SqlConformanceEnum.BIG_QUERY; case MYSQL: return SqlConformanceEnum.MYSQL_5; case ORACLE: return SqlConformanceEnum.ORACLE_10; case MSSQL: return SqlConformanceEnum.SQL_SERVER_2008; default: return SqlConformanceEnum.PRAGMATIC_2003; } }
Example #6
Source File: SqlToRelTestBase.java From calcite with Apache License 2.0 | 6 votes |
protected TesterImpl(DiffRepository diffRepos, boolean enableDecorrelate, boolean enableTrim, boolean enableExpand, boolean enableLateDecorrelate, boolean enableTypeCoercion, SqlTestFactory.MockCatalogReaderFactory catalogReaderFactory, Function<RelOptCluster, RelOptCluster> clusterFactory, SqlToRelConverter.Config config, SqlConformance conformance, Context context) { this.diffRepos = diffRepos; this.enableDecorrelate = enableDecorrelate; this.enableTrim = enableTrim; this.enableExpand = enableExpand; this.enableLateDecorrelate = enableLateDecorrelate; this.enableTypeCoercion = enableTypeCoercion; this.catalogReaderFactory = catalogReaderFactory; this.clusterFactory = clusterFactory; this.config = config; this.conformance = conformance; this.context = context; }
Example #7
Source File: ImmutableBeans.java From calcite with Apache License 2.0 | 6 votes |
private static Object convertDefault(Object defaultValue, String propertyName, Class<?> propertyType) { if (propertyType.equals(SqlConformance.class)) { // Workaround for SqlConformance because it is actually not a Enum. propertyType = SqlConformanceEnum.class; } if (defaultValue == null || !propertyType.isEnum()) { return defaultValue; } for (Object enumConstant : propertyType.getEnumConstants()) { if (((Enum) enumConstant).name().equals(defaultValue)) { return enumConstant; } } throw new IllegalArgumentException("property '" + propertyName + "' is an enum but its default value " + defaultValue + " is not a valid enum constant"); }
Example #8
Source File: SqlTestFactory.java From calcite with Apache License 2.0 | 6 votes |
protected SqlTestFactory(ImmutableMap<String, Object> options, MockCatalogReaderFactory catalogReaderFactory, ValidatorFactory validatorFactory) { this.options = options; this.catalogReaderFactory = catalogReaderFactory; this.validatorFactory = validatorFactory; this.operatorTable = Suppliers.memoize( () -> createOperatorTable((SqlOperatorTable) options.get("operatorTable"))); this.typeFactory = Suppliers.memoize( () -> createTypeFactory((SqlConformance) options.get("conformance"))); Boolean caseSensitive = (Boolean) options.get("caseSensitive"); this.catalogReader = Suppliers.memoize( () -> catalogReaderFactory.create(typeFactory.get(), caseSensitive).init()); this.parserConfig = Suppliers.memoize( () -> createParserConfig(options)); }
Example #9
Source File: HiveRexExecutorImpl.java From marble with Apache License 2.0 | 5 votes |
private String compile(RexBuilder rexBuilder, List<RexNode> constExps, RexToLixTranslator.InputGetter getter, RelDataType rowType) { final RexProgramBuilder programBuilder = new RexProgramBuilder(rowType, rexBuilder); for (RexNode node : constExps) { programBuilder.addProject( node, "c" + programBuilder.getProjectList().size()); } final JavaTypeFactoryImpl javaTypeFactory = new JavaTypeFactoryImpl(rexBuilder.getTypeFactory().getTypeSystem()); final BlockBuilder blockBuilder = new BlockBuilder(); final ParameterExpression root0_ = Expressions.parameter(Object.class, "root0"); final ParameterExpression root_ = DataContext.ROOT; blockBuilder.add( Expressions.declare( Modifier.FINAL, root_, Expressions.convert_(root0_, DataContext.class))); final SqlConformance conformance = SqlConformanceEnum.HIVE; final RexProgram program = programBuilder.getProgram(); final List<Expression> expressions = RexToLixTranslator.translateProjects(program, javaTypeFactory, conformance, blockBuilder, null, root_, getter, null); blockBuilder.add( Expressions.return_(null, Expressions.newArrayInit(Object[].class, expressions))); final MethodDeclaration methodDecl = Expressions.methodDecl(Modifier.PUBLIC, Object[].class, BuiltInMethod.FUNCTION1_APPLY.method.getName(), ImmutableList.of(root0_), blockBuilder.toBlock()); String code = Expressions.toString(methodDecl); if (CalcitePrepareImpl.DEBUG) { Util.debugCode(System.out, code); } return code; }
Example #10
Source File: AbstractSqlTester.java From calcite with Apache License 2.0 | 5 votes |
public SqlTester withConformance(SqlConformance conformance) { if (conformance == null) { conformance = SqlConformanceEnum.DEFAULT; } final SqlTester tester = with("conformance", conformance); if (conformance instanceof SqlConformanceEnum) { return tester .withConnectionFactory( CalciteAssert.EMPTY_CONNECTION_FACTORY .with(CalciteConnectionProperty.CONFORMANCE, conformance)); } else { return tester; } }
Example #11
Source File: SqlValidatorImpl.java From dremio-oss with Apache License 2.0 | 5 votes |
protected SqlValidatorImpl( FlattenOpCounter flattenCount, SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, SqlConformance conformance) { super(opTab, catalogReader, typeFactory, conformance); this.flattenCount = flattenCount; }
Example #12
Source File: SqlParser.java From Bats with Apache License 2.0 | 5 votes |
private ConfigImpl(int identifierMaxLength, Casing quotedCasing, Casing unquotedCasing, Quoting quoting, boolean caseSensitive, SqlConformance conformance, SqlParserImplFactory parserFactory) { this.identifierMaxLength = identifierMaxLength; this.caseSensitive = caseSensitive; this.conformance = Objects.requireNonNull(conformance); this.quotedCasing = Objects.requireNonNull(quotedCasing); this.unquotedCasing = Objects.requireNonNull(unquotedCasing); this.quoting = Objects.requireNonNull(quoting); this.parserFactory = Objects.requireNonNull(parserFactory); }
Example #13
Source File: FlinkSqlParserFactories.java From flink with Apache License 2.0 | 5 votes |
public static SqlParserImplFactory create(SqlConformance conformance) { if (conformance == FlinkSqlConformance.HIVE) { return FlinkHiveSqlParserImpl.FACTORY; } else { return FlinkSqlParserImpl.FACTORY; } }
Example #14
Source File: FlinkDDLDataTypeTest.java From flink with Apache License 2.0 | 5 votes |
TestFactory( Map<String, Object> options, SqlTestFactory.MockCatalogReaderFactory catalogReaderFactory, SqlTestFactory.ValidatorFactory validatorFactory) { this.options = options; this.validatorFactory = validatorFactory; this.operatorTable = createOperatorTable((SqlOperatorTable) options.get("operatorTable")); this.typeFactory = createTypeFactory((SqlConformance) options.get("conformance")); Boolean caseSensitive = (Boolean) options.get("caseSensitive"); this.catalogReader = catalogReaderFactory.create(typeFactory, caseSensitive).init(); this.parserConfig = createParserConfig(options); }
Example #15
Source File: FlinkDDLDataTypeTest.java From flink with Apache License 2.0 | 5 votes |
private static SqlParser.Config createParserConfig(Map<String, Object> options) { return SqlParser.configBuilder() .setQuoting((Quoting) options.get("quoting")) .setUnquotedCasing((Casing) options.get("unquotedCasing")) .setQuotedCasing((Casing) options.get("quotedCasing")) .setConformance((SqlConformance) options.get("conformance")) .setCaseSensitive((boolean) options.get("caseSensitive")) .setParserFactory((SqlParserImplFactory) options.get("parserFactory")) .build(); }
Example #16
Source File: RexToLixTranslator.java From calcite with Apache License 2.0 | 5 votes |
public static Expression translateTableFunction(JavaTypeFactory typeFactory, SqlConformance conformance, BlockBuilder blockBuilder, Expression root, RexCall rexCall, Expression inputEnumerable, PhysType inputPhysType, PhysType outputPhysType) { return new RexToLixTranslator(null, typeFactory, root, null, blockBuilder, new RexBuilder(typeFactory), conformance, null) .translateTableFunction(rexCall, inputEnumerable, inputPhysType, outputPhysType); }
Example #17
Source File: FlinkDDLDataTypeTest.java From flink with Apache License 2.0 | 5 votes |
public SqlValidator getValidator() { final SqlConformance conformance = (SqlConformance) options.get("conformance"); final boolean enableTypeCoercion = (boolean) options.get("enableTypeCoercion"); return validatorFactory.create(operatorTable, catalogReader, typeFactory, conformance) .setEnableTypeCoercion(enableTypeCoercion); }
Example #18
Source File: RexToLixTranslator.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a translator for translating aggregate functions. */ public static RexToLixTranslator forAggregation(JavaTypeFactory typeFactory, BlockBuilder list, InputGetter inputGetter, SqlConformance conformance) { final ParameterExpression root = DataContext.ROOT; return new RexToLixTranslator(null, typeFactory, root, inputGetter, list, new RexBuilder(typeFactory), conformance, null); }
Example #19
Source File: RexToLixTranslator.java From calcite with Apache License 2.0 | 5 votes |
public static Expression translateCondition(RexProgram program, JavaTypeFactory typeFactory, BlockBuilder list, InputGetter inputGetter, Function1<String, InputGetter> correlates, SqlConformance conformance) { if (program.getCondition() == null) { return RexImpTable.TRUE_EXPR; } final ParameterExpression root = DataContext.ROOT; RexToLixTranslator translator = new RexToLixTranslator(program, typeFactory, root, inputGetter, list, new RexBuilder(typeFactory), conformance, null); translator = translator.setCorrelates(correlates); return translator.translate( program.getCondition(), RexImpTable.NullAs.FALSE); }
Example #20
Source File: EnumerableTableFunctionScan.java From calcite with Apache License 2.0 | 5 votes |
private Result tvfImplementorBasedImplement( EnumerableRelImplementor implementor, Prefer pref) { final JavaTypeFactory typeFactory = implementor.getTypeFactory(); final BlockBuilder builder = new BlockBuilder(); final EnumerableRel child = (EnumerableRel) getInputs().get(0); final Result result = implementor.visitChild(this, 0, child, pref); final PhysType physType = PhysTypeImpl.of( typeFactory, getRowType(), pref.prefer(result.format)); final Expression inputEnumerable = builder.append( "_input", result.block, false); final SqlConformance conformance = (SqlConformance) implementor.map.getOrDefault("_conformance", SqlConformanceEnum.DEFAULT); builder.add( RexToLixTranslator.translateTableFunction( typeFactory, conformance, builder, DataContext.ROOT, (RexCall) getCall(), inputEnumerable, result.physType, physType ) ); return implementor.result(physType, builder.toBlock()); }
Example #21
Source File: SqlToRelConverterTest.java From calcite with Apache License 2.0 | 5 votes |
Sql(String sql, boolean decorrelate, Tester tester, boolean trim, UnaryOperator<SqlToRelConverter.ConfigBuilder> config, SqlConformance conformance) { this.sql = sql; this.decorrelate = decorrelate; this.tester = tester; this.trim = trim; this.config = config; this.conformance = conformance; }
Example #22
Source File: SqlParser.java From calcite with Apache License 2.0 | 5 votes |
private ConfigImpl(int identifierMaxLength, Casing quotedCasing, Casing unquotedCasing, Quoting quoting, boolean caseSensitive, SqlConformance conformance, SqlParserImplFactory parserFactory) { this.identifierMaxLength = identifierMaxLength; this.caseSensitive = caseSensitive; this.conformance = Objects.requireNonNull(conformance); this.quotedCasing = Objects.requireNonNull(quotedCasing); this.unquotedCasing = Objects.requireNonNull(unquotedCasing); this.quoting = Objects.requireNonNull(quoting); this.parserFactory = Objects.requireNonNull(parserFactory); }
Example #23
Source File: SqlDialect.java From calcite with Apache License 2.0 | 5 votes |
@Nonnull public Context withConformance(SqlConformance conformance) { return new ContextImpl(databaseProduct, databaseProductName, databaseVersion, databaseMajorVersion, databaseMinorVersion, literalQuoteString, literalEscapedQuoteString, identifierQuoteString, quotedCasing, unquotedCasing, caseSensitive, conformance, nullCollation, dataTypeSystem, jethroInfo); }
Example #24
Source File: RexExecutorImpl.java From calcite with Apache License 2.0 | 5 votes |
private static String compile(RexBuilder rexBuilder, List<RexNode> constExps, RexToLixTranslator.InputGetter getter, RelDataType rowType) { final RexProgramBuilder programBuilder = new RexProgramBuilder(rowType, rexBuilder); for (RexNode node : constExps) { programBuilder.addProject( node, "c" + programBuilder.getProjectList().size()); } final JavaTypeFactoryImpl javaTypeFactory = new JavaTypeFactoryImpl(rexBuilder.getTypeFactory().getTypeSystem()); final BlockBuilder blockBuilder = new BlockBuilder(); final ParameterExpression root0_ = Expressions.parameter(Object.class, "root0"); final ParameterExpression root_ = DataContext.ROOT; blockBuilder.add( Expressions.declare( Modifier.FINAL, root_, Expressions.convert_(root0_, DataContext.class))); final SqlConformance conformance = SqlConformanceEnum.DEFAULT; final RexProgram program = programBuilder.getProgram(); final List<Expression> expressions = RexToLixTranslator.translateProjects(program, javaTypeFactory, conformance, blockBuilder, null, root_, getter, null); blockBuilder.add( Expressions.return_(null, Expressions.newArrayInit(Object[].class, expressions))); final MethodDeclaration methodDecl = Expressions.methodDecl(Modifier.PUBLIC, Object[].class, BuiltInMethod.FUNCTION1_APPLY.method.getName(), ImmutableList.of(root0_), blockBuilder.toBlock()); String code = Expressions.toString(methodDecl); if (CalciteSystemProperty.DEBUG.value()) { Util.debugCode(System.out, code); } return code; }
Example #25
Source File: SqlTestFactory.java From calcite with Apache License 2.0 | 5 votes |
public static SqlParser.Config createParserConfig(ImmutableMap<String, Object> options) { return SqlParser.configBuilder() .setQuoting((Quoting) options.get("quoting")) .setUnquotedCasing((Casing) options.get("unquotedCasing")) .setQuotedCasing((Casing) options.get("quotedCasing")) .setConformance((SqlConformance) options.get("conformance")) .setCaseSensitive((boolean) options.get("caseSensitive")) .build(); }
Example #26
Source File: SqlTestFactory.java From calcite with Apache License 2.0 | 5 votes |
public SqlValidator getValidator() { final SqlConformance conformance = (SqlConformance) options.get("conformance"); final boolean lenientOperatorLookup = (boolean) options.get("lenientOperatorLookup"); final boolean enableTypeCoercion = (boolean) options.get("enableTypeCoercion"); final SqlValidator.Config config = SqlValidator.Config.DEFAULT .withSqlConformance(conformance) .withTypeCoercionEnabled(enableTypeCoercion) .withLenientOperatorLookup(lenientOperatorLookup); return validatorFactory.create(operatorTable.get(), catalogReader.get(), typeFactory.get(), config); }
Example #27
Source File: BatsOptimizerTest.java From Bats with Apache License 2.0 | 5 votes |
static Pair<SqlNode, SqlValidator> testSqlValidator() throws Exception { String sql = "select * from my_schema.test where f1=1 or f2=2 order by f3 limit 2"; sql = "select * from test"; sql = "select * from my_schema2.test2"; sql = "select sum(f1),max(f2) from test"; sql = "select t1.f1,sum(Distinct f1) as sumf1 from test as t1 " + "where f2>20 group by f1 having f1>10 order by f1 limit 2"; // sql = "insert into test(f1,f2,f3) values(1,2,3)"; // sql = "update test set f1=100 where f2>10"; // sql = "delete from test where f2>10"; SqlNode sqlNode = parse(sql); SqlOperatorTable opTab = SqlStdOperatorTable.instance(); RelDataTypeFactory typeFactory = createJavaTypeFactory(); SqlValidatorCatalogReader catalogReader = createCalciteCatalogReader(typeFactory); SqlConformance conformance = SqlConformanceEnum.DEFAULT; List<String> names = new ArrayList<>(); names.add("my_schema"); names.add("test"); catalogReader.getTable(names); SqlValidator sqlValidator = SqlValidatorUtil.newValidator(opTab, catalogReader, typeFactory, conformance); sqlNode = sqlValidator.validate(sqlNode); // System.out.println(sqlNode); sql = "insert into test(f1,f2,f3) values(1,2,3)"; // sqlNode = parse(sql); // sqlNode = sqlValidator.validate(sqlNode); return new Pair<>(sqlNode, sqlValidator); }
Example #28
Source File: CalciteConnectionConfig.java From Bats with Apache License 2.0 | 4 votes |
/** @see CalciteConnectionProperty#CONFORMANCE */ SqlConformance conformance();
Example #29
Source File: JaninoRexCompiler.java From calcite with Apache License 2.0 | 4 votes |
public Scalar compile(List<RexNode> nodes, RelDataType inputRowType) { final RexProgramBuilder programBuilder = new RexProgramBuilder(inputRowType, rexBuilder); for (RexNode node : nodes) { programBuilder.addProject(node, null); } final RexProgram program = programBuilder.getProgram(); final BlockBuilder builder = new BlockBuilder(); final ParameterExpression context_ = Expressions.parameter(Context.class, "context"); final ParameterExpression outputValues_ = Expressions.parameter(Object[].class, "outputValues"); final JavaTypeFactoryImpl javaTypeFactory = new JavaTypeFactoryImpl(rexBuilder.getTypeFactory().getTypeSystem()); // public void execute(Context, Object[] outputValues) final RexToLixTranslator.InputGetter inputGetter = new RexToLixTranslator.InputGetterImpl( ImmutableList.of( Pair.of( Expressions.field(context_, BuiltInMethod.CONTEXT_VALUES.field), PhysTypeImpl.of(javaTypeFactory, inputRowType, JavaRowFormat.ARRAY, false)))); final Function1<String, RexToLixTranslator.InputGetter> correlates = a0 -> { throw new UnsupportedOperationException(); }; final Expression root = Expressions.field(context_, BuiltInMethod.CONTEXT_ROOT.field); final SqlConformance conformance = SqlConformanceEnum.DEFAULT; // TODO: get this from implementor final List<Expression> list = RexToLixTranslator.translateProjects(program, javaTypeFactory, conformance, builder, null, root, inputGetter, correlates); for (int i = 0; i < list.size(); i++) { builder.add( Expressions.statement( Expressions.assign( Expressions.arrayIndex(outputValues_, Expressions.constant(i)), list.get(i)))); } return baz(context_, outputValues_, builder.toBlock()); }
Example #30
Source File: SqlParser.java From Bats with Apache License 2.0 | 4 votes |
public SqlConformance conformance() { return conformance; }