org.apache.calcite.config.CalciteConnectionProperty Java Examples
The following examples show how to use
org.apache.calcite.config.CalciteConnectionProperty.
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: SqlExprToRexConverterImpl.java From flink with Apache License 2.0 | 6 votes |
/** * Creates a catalog reader that contains a single {@link Table} with temporary table name * and specified {@code rowType}. * * @param rowType table row type * @return the {@link CalciteCatalogReader} instance */ private static CalciteCatalogReader createSingleTableCatalogReader( boolean lenientCaseSensitivity, FrameworkConfig config, FlinkTypeFactory typeFactory, RelDataType rowType) { // connection properties boolean caseSensitive = !lenientCaseSensitivity && config.getParserConfig().caseSensitive(); Properties properties = new Properties(); properties.put( CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(caseSensitive)); CalciteConnectionConfig connectionConfig = new CalciteConnectionConfigImpl(properties); // prepare root schema final RowTypeSpecifiedTable table = new RowTypeSpecifiedTable(rowType); final Map<String, Table> tableMap = Collections.singletonMap(TEMPORARY_TABLE_NAME, table); CalciteSchema schema = CalciteSchemaBuilder.asRootSchema(new TableSpecifiedSchema(tableMap)); return new FlinkCalciteCatalogReader( schema, new ArrayList<>(new ArrayList<>()), typeFactory, connectionConfig); }
Example #2
Source File: Frameworks.java From calcite with Apache License 2.0 | 6 votes |
/** * Initializes a container then calls user-specified code with a planner * and statement. * * @param action Callback containing user-specified code * @return Return value from action */ public static <R> R withPrepare(FrameworkConfig config, BasePrepareAction<R> action) { try { final Properties info = new Properties(); if (config.getTypeSystem() != RelDataTypeSystem.DEFAULT) { info.setProperty(CalciteConnectionProperty.TYPE_SYSTEM.camelName(), config.getTypeSystem().getClass().getName()); } Connection connection = DriverManager.getConnection("jdbc:calcite:", info); final CalciteServerStatement statement = connection.createStatement() .unwrap(CalciteServerStatement.class); return new CalcitePrepareImpl().perform(statement, config, action); } catch (Exception e) { throw new RuntimeException(e); } }
Example #3
Source File: Schemas.java From calcite with Apache License 2.0 | 6 votes |
/** Parses and validates a SQL query. For use within Calcite only. */ public static CalcitePrepare.ParseResult parse( final CalciteConnection connection, final CalciteSchema schema, final List<String> schemaPath, final String sql) { final CalcitePrepare prepare = CalcitePrepare.DEFAULT_FACTORY.apply(); final ImmutableMap<CalciteConnectionProperty, String> propValues = ImmutableMap.of(); final CalcitePrepare.Context context = makeContext(connection, schema, schemaPath, null, propValues); CalcitePrepare.Dummy.push(context); try { return prepare.parse(context, sql); } finally { CalcitePrepare.Dummy.pop(context); } }
Example #4
Source File: Schemas.java From calcite with Apache License 2.0 | 6 votes |
/** Parses and validates a SQL query and converts to relational algebra. For * use within Calcite only. */ public static CalcitePrepare.ConvertResult convert( final CalciteConnection connection, final CalciteSchema schema, final List<String> schemaPath, final String sql) { final CalcitePrepare prepare = CalcitePrepare.DEFAULT_FACTORY.apply(); final ImmutableMap<CalciteConnectionProperty, String> propValues = ImmutableMap.of(); final CalcitePrepare.Context context = makeContext(connection, schema, schemaPath, null, propValues); CalcitePrepare.Dummy.push(context); try { return prepare.convert(context, sql); } finally { CalcitePrepare.Dummy.pop(context); } }
Example #5
Source File: Schemas.java From calcite with Apache License 2.0 | 6 votes |
/** Analyzes a view. For use within Calcite only. */ public static CalcitePrepare.AnalyzeViewResult analyzeView( final CalciteConnection connection, final CalciteSchema schema, final List<String> schemaPath, final String viewSql, List<String> viewPath, boolean fail) { final CalcitePrepare prepare = CalcitePrepare.DEFAULT_FACTORY.apply(); final ImmutableMap<CalciteConnectionProperty, String> propValues = ImmutableMap.of(); final CalcitePrepare.Context context = makeContext(connection, schema, schemaPath, viewPath, propValues); CalcitePrepare.Dummy.push(context); try { return prepare.analyzeView(context, viewSql, fail); } finally { CalcitePrepare.Dummy.pop(context); } }
Example #6
Source File: TpcdsLatticeSuggesterTest.java From calcite with Apache License 2.0 | 6 votes |
Tester tpcds() { final SchemaPlus rootSchema = Frameworks.createRootSchema(true); final double scaleFactor = 0.01d; final SchemaPlus schema = rootSchema.add("tpcds", new TpcdsSchema(scaleFactor)); final FrameworkConfig config = Frameworks.newConfigBuilder() .parserConfig(SqlParser.Config.DEFAULT) .context( Contexts.of( new CalciteConnectionConfigImpl(new Properties()) .set(CalciteConnectionProperty.CONFORMANCE, SqlConformanceEnum.LENIENT.name()))) .defaultSchema(schema) .build(); return withConfig(config); }
Example #7
Source File: TableFunctionTest.java From calcite with Apache License 2.0 | 6 votes |
@Test void testCrossApply() { final String q1 = "select *\n" + "from (values 2, 5) as t (c)\n" + "cross apply table(\"s\".\"fibonacci2\"(c))"; final String q2 = "select *\n" + "from (values 2, 5) as t (c)\n" + "cross apply table(\"s\".\"fibonacci2\"(t.c))"; for (String q : new String[] {q1, q2}) { with() .with(CalciteConnectionProperty.CONFORMANCE, SqlConformanceEnum.LENIENT) .query(q) .returnsUnordered("C=2; N=1", "C=2; N=1", "C=2; N=2", "C=5; N=1", "C=5; N=1", "C=5; N=2", "C=5; N=3", "C=5; N=5"); } }
Example #8
Source File: SqlToRelConverterTest.java From calcite with Apache License 2.0 | 6 votes |
/** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-2323">[CALCITE-2323] * Validator should allow alternative nullCollations for ORDER BY in * OVER</a>. */ @Test void testUserDefinedOrderByOver() { String sql = "select deptno,\n" + " rank() over(partition by empno order by deptno)\n" + "from emp\n" + "order by row_number() over(partition by empno order by deptno)"; Properties properties = new Properties(); properties.setProperty( CalciteConnectionProperty.DEFAULT_NULL_COLLATION.camelName(), NullCollation.LOW.name()); CalciteConnectionConfigImpl connectionConfig = new CalciteConnectionConfigImpl(properties); TesterImpl tester = new TesterImpl(getDiffRepos(), false, false, true, false, true, null, null, SqlToRelConverter.Config.DEFAULT, SqlConformanceEnum.DEFAULT, Contexts.of(connectionConfig)); sql(sql).with(tester).ok(); }
Example #9
Source File: EnumerableBatchNestedLoopJoinTest.java From calcite with Apache License 2.0 | 5 votes |
private CalciteAssert.AssertThat tester(boolean forceDecorrelate, Object schema) { return CalciteAssert.that() .with(CalciteConnectionProperty.LEX, Lex.JAVA) .with(CalciteConnectionProperty.FORCE_DECORRELATE, forceDecorrelate) .withSchema("s", new ReflectiveSchema(schema)); }
Example #10
Source File: EnumerableHashJoinTest.java From calcite with Apache License 2.0 | 5 votes |
private CalciteAssert.AssertThat tester(boolean forceDecorrelate, Object schema) { return CalciteAssert.that() .with(CalciteConnectionProperty.LEX, Lex.JAVA) .with(CalciteConnectionProperty.FORCE_DECORRELATE, forceDecorrelate) .withSchema("s", new ReflectiveSchema(schema)); }
Example #11
Source File: EnumerableSortedAggregateTest.java From calcite with Apache License 2.0 | 5 votes |
private CalciteAssert.AssertThat tester(boolean forceDecorrelate, Object schema) { return CalciteAssert.that() .with(CalciteConnectionProperty.LEX, Lex.JAVA) .with(CalciteConnectionProperty.FORCE_DECORRELATE, forceDecorrelate) .withSchema("s", new ReflectiveSchema(schema)); }
Example #12
Source File: MetricsSqlQueryService.java From nifi with Apache License 2.0 | 5 votes |
private CalciteConnection createConnection() { final Properties properties = new Properties(); properties.put(CalciteConnectionProperty.LEX.camelName(), Lex.MYSQL_ANSI.name()); try { final Connection connection = DriverManager.getConnection("jdbc:calcite:", properties); return connection.unwrap(CalciteConnection.class); } catch (final Exception e) { throw new ProcessException(e); } }
Example #13
Source File: EnumerableCorrelateTest.java From calcite with Apache License 2.0 | 5 votes |
private CalciteAssert.AssertThat tester(boolean forceDecorrelate, Object schema) { return CalciteAssert.that() .with(CalciteConnectionProperty.LEX, Lex.JAVA) .with(CalciteConnectionProperty.FORCE_DECORRELATE, forceDecorrelate) .withSchema("s", new ReflectiveSchema(schema)); }
Example #14
Source File: TableFunctionTest.java From calcite with Apache License 2.0 | 5 votes |
/** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-2004">[CALCITE-2004] * Wrong plan generated for left outer apply with table function</a>. */ @Test void testLeftOuterApply() { final String sql = "select *\n" + "from (values 4) as t (c)\n" + "left join lateral table(\"s\".\"fibonacci2\"(c)) as R(n) on c=n"; with() .with(CalciteConnectionProperty.CONFORMANCE, SqlConformanceEnum.LENIENT) .query(sql) .returnsUnordered("C=4; N=null"); }
Example #15
Source File: EnumerableJoinTest.java From calcite with Apache License 2.0 | 5 votes |
private CalciteAssert.AssertThat tester(boolean forceDecorrelate, Object schema) { return CalciteAssert.that() .with(CalciteConnectionProperty.LEX, Lex.JAVA) .with(CalciteConnectionProperty.FORCE_DECORRELATE, forceDecorrelate) .withSchema("s", new ReflectiveSchema(schema)); }
Example #16
Source File: RelMdPercentageOriginalRowsTest.java From calcite with Apache License 2.0 | 5 votes |
/** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-2894">[CALCITE-2894] * NullPointerException thrown by RelMdPercentageOriginalRows when explaining * plan with all attributes</a>. */ @Test void testExplainAllAttributesSemiJoinUnionCorrelate() { CalciteAssert.that() .with(CalciteConnectionProperty.LEX, Lex.JAVA) .with(CalciteConnectionProperty.FORCE_DECORRELATE, false) .withSchema("s", new ReflectiveSchema(new JdbcTest.HrSchema())) .query( "select deptno, name from depts where deptno in (\n" + " select e.deptno from emps e where exists (select 1 from depts d where d.deptno=e.deptno)\n" + " union select e.deptno from emps e where e.salary > 10000) ") .explainMatches("including all attributes ", CalciteAssert.checkResultContains("EnumerableCorrelate")); }
Example #17
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 #18
Source File: CalciteAssert.java From calcite with Apache License 2.0 | 5 votes |
static void assertPrepare( Connection connection, String sql, boolean materializationsEnabled, final Function<RelNode, Void> convertChecker, final Function<RelNode, Void> substitutionChecker) { try (Closer closer = new Closer()) { if (convertChecker != null) { closer.add( Hook.TRIMMED.addThread((Consumer<RelNode>) convertChecker::apply)); } if (substitutionChecker != null) { closer.add( Hook.SUB.addThread( (Consumer<RelNode>) substitutionChecker::apply)); } ((CalciteConnection) connection).getProperties().setProperty( CalciteConnectionProperty.MATERIALIZATIONS_ENABLED.camelName(), Boolean.toString(materializationsEnabled)); ((CalciteConnection) connection).getProperties().setProperty( CalciteConnectionProperty.CREATE_MATERIALIZATIONS.camelName(), Boolean.toString(materializationsEnabled)); PreparedStatement statement = connection.prepareStatement(sql); statement.close(); connection.close(); } catch (Throwable e) { String message = "With materializationsEnabled=" + materializationsEnabled; if (!TestUtil.hasMessage(e, sql)) { message += ", sql=" + sql; } throw TestUtil.rethrow(e, message); } }
Example #19
Source File: Schemas.java From calcite with Apache License 2.0 | 5 votes |
private static CalciteConnectionConfig mutate(CalciteConnectionConfig config, ImmutableMap<CalciteConnectionProperty, String> propValues) { for (Map.Entry<CalciteConnectionProperty, String> e : propValues.entrySet()) { config = ((CalciteConnectionConfigImpl) config).set(e.getKey(), e.getValue()); } return config; }
Example #20
Source File: CalciteAssert.java From calcite with Apache License 2.0 | 5 votes |
public AssertThat with(Config config) { switch (config) { case EMPTY: return EMPTY; case REGULAR: return with(SchemaSpec.HR, SchemaSpec.REFLECTIVE_FOODMART, SchemaSpec.POST); case REGULAR_PLUS_METADATA: return with(SchemaSpec.HR, SchemaSpec.REFLECTIVE_FOODMART); case GEO: return with(SchemaSpec.GEO) .with(CalciteConnectionProperty.CONFORMANCE, SqlConformanceEnum.LENIENT); case LINGUAL: return with(SchemaSpec.LINGUAL); case JDBC_FOODMART: return with(CalciteAssert.SchemaSpec.JDBC_FOODMART); case FOODMART_CLONE: return with(SchemaSpec.CLONE_FOODMART); case JDBC_FOODMART_WITH_LATTICE: return with(SchemaSpec.JDBC_FOODMART_WITH_LATTICE); case JDBC_SCOTT: return with(SchemaSpec.JDBC_SCOTT); case SCOTT: return with(SchemaSpec.SCOTT); case SPARK: return with(CalciteConnectionProperty.SPARK, true); case AUX: return with(SchemaSpec.AUX, SchemaSpec.POST); default: throw Util.unexpected(config); } }
Example #21
Source File: CalciteAssert.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a {@link FrameworkConfig} that does not decorrelate. */ private FrameworkConfig forceDecorrelate(FrameworkConfig config) { return Frameworks.newConfigBuilder(config) .context( Contexts.of(new CalciteConnectionConfigImpl(new Properties()) .set(CalciteConnectionProperty.FORCE_DECORRELATE, Boolean.toString(false)))) .build(); }
Example #22
Source File: QueryRecord.java From nifi with Apache License 2.0 | 5 votes |
private CalciteConnection createConnection() { final Properties properties = new Properties(); properties.put(CalciteConnectionProperty.LEX.camelName(), Lex.MYSQL_ANSI.name()); try { final Connection connection = DriverManager.getConnection("jdbc:calcite:", properties); final CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); return calciteConnection; } catch (final Exception e) { throw new ProcessException(e); } }
Example #23
Source File: SqlConverter.java From Bats with Apache License 2.0 | 5 votes |
/** * Creates {@link CalciteConnectionConfigImpl} instance with specified caseSensitive property. * * @param caseSensitive is case sensitive. * @return {@link CalciteConnectionConfigImpl} instance */ private static CalciteConnectionConfigImpl getConnectionConfig(boolean caseSensitive) { Properties properties = new Properties(); properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(caseSensitive)); return new CalciteConnectionConfigImpl(properties); }
Example #24
Source File: TableEnv.java From marble with Apache License 2.0 | 5 votes |
private CalciteConnectionConfig createDefaultConnectionConfig( SqlParser.Config sqlParserConfig) { Properties prop = new Properties(); prop.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(sqlParserConfig.caseSensitive())); return new CalciteConnectionConfigImpl(prop); }
Example #25
Source File: KarelDbMain.java From kareldb with Apache License 2.0 | 5 votes |
public static Meta create(KarelDbConfig config) { try { Map<String, String> configs = config.originalsStrings(); Properties properties = new Properties(); properties.put(CalciteConnectionProperty.SCHEMA_FACTORY.camelName(), SchemaFactory.class.getName()); properties.put(CalciteConnectionProperty.SCHEMA.camelName(), "default"); properties.put(CalciteConnectionProperty.PARSER_FACTORY.camelName(), "org.apache.calcite.sql.parser.parserextension.ExtensionSqlParserImpl#FACTORY"); properties.put("schema.kind", "io.kareldb.kafka.KafkaSchema"); for (Map.Entry<String, String> entry : configs.entrySet()) { properties.put("schema." + entry.getKey(), entry.getValue()); } boolean testMode = false; if (testMode) { // Single connection for testing final Connection connection = DriverManager.getConnection(Driver.CONNECT_STRING_PREFIX, properties); return new MetaImpl((AvaticaConnection) connection); } else { // Multi-connection support return new JdbcMeta(Driver.CONNECT_STRING_PREFIX, properties); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
Example #26
Source File: BaseJDBCTestCase.java From kareldb with Apache License 2.0 | 5 votes |
protected Properties createProperties() { Properties properties = new Properties(); properties.put(CalciteConnectionProperty.SCHEMA_FACTORY.camelName(), SchemaFactory.class.getName()); properties.put(CalciteConnectionProperty.PARSER_FACTORY.camelName(), "org.apache.calcite.sql.parser.parserextension.ExtensionSqlParserImpl#FACTORY"); properties.put("schema.kind", "io.kareldb.kafka.KafkaSchema"); properties.put("schema.kafkacache.bootstrap.servers", bootstrapServers); properties.put("schema.rocksdb.enable", "true"); properties.put("schema.rocksdb.root.dir", tempDir.getAbsolutePath()); return properties; }
Example #27
Source File: FlinkCalciteCatalogReaderTest.java From flink with Apache License 2.0 | 5 votes |
@Before public void init() { rootSchemaPlus = CalciteSchema.createRootSchema(true, false).plus(); Properties prop = new Properties(); prop.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), "false"); CalciteConnectionConfigImpl calciteConnConfig = new CalciteConnectionConfigImpl(prop); catalogReader = new FlinkCalciteCatalogReader( CalciteSchema.from(rootSchemaPlus), Collections.emptyList(), typeFactory, calciteConnConfig); }
Example #28
Source File: HiveTableEnv.java From marble with Apache License 2.0 | 5 votes |
public static TableEnv getTableEnv() { TableConfig tableConfig = new TableConfig(); tableConfig.setSqlOperatorTable( ChainedSqlOperatorTable.of(HiveSqlOperatorTable.instance(), SqlStdOperatorTable.instance())); tableConfig.setSqlParserConfig(SqlParser .configBuilder() .setLex(Lex.JAVA).setCaseSensitive(false).setConformance( SqlConformanceEnum.HIVE) .setParserFactory(HiveSqlParserImpl.FACTORY) .build()); // tableConfig.setRelDataTypeSystem(new HiveTypeSystemImpl()); Properties prop = new Properties(); prop.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(tableConfig.getSqlParserConfig().caseSensitive())); tableConfig.setCalciteConnectionConfig( new CalciteConnectionConfigImpl(prop)); tableConfig.setConvertletTable(new HiveConvertletTable()); RexExecutor rexExecutor = new HiveRexExecutorImpl( Schemas.createDataContext(null, null)); tableConfig.setRexExecutor(rexExecutor); TableEnv tableEnv = new HiveTableEnv(tableConfig); //add table functions tableEnv.addFunction("", "explode", "org.apache.calcite.adapter.hive.udtf.UDTFExplode", "eval"); return tableEnv; }
Example #29
Source File: SqlValidatorUtil.java From calcite with Apache License 2.0 | 5 votes |
/** * Creates a catalog reader that contains a single {@link Table} with temporary table name * and specified {@code rowType}. * * <p>Make this method public so that other systems can also use it. * * @param caseSensitive whether to match case sensitively * @param tableName table name to register with * @param typeFactory type factory * @param rowType table row type * @return the {@link CalciteCatalogReader} instance */ public static CalciteCatalogReader createSingleTableCatalogReader( boolean caseSensitive, String tableName, RelDataTypeFactory typeFactory, RelDataType rowType) { // connection properties Properties properties = new Properties(); properties.put( CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(caseSensitive)); CalciteConnectionConfig connectionConfig = new CalciteConnectionConfigImpl(properties); // prepare root schema final ExplicitRowTypeTable table = new ExplicitRowTypeTable(rowType); final Map<String, Table> tableMap = Collections.singletonMap(tableName, table); CalciteSchema schema = CalciteSchema.createRootSchema( false, false, "", new ExplicitTableSchema(tableMap)); return new CalciteCatalogReader( schema, new ArrayList<>(new ArrayList<>()), typeFactory, connectionConfig); }
Example #30
Source File: QuarkDriver.java From quark with Apache License 2.0 | 5 votes |
@Override protected Collection<ConnectionProperty> getConnectionProperties() { final List<ConnectionProperty> list = new ArrayList<ConnectionProperty>(); Collections.addAll(list, BuiltInConnectionProperty.values()); Collections.addAll(list, CalciteConnectionProperty.values()); return list; }