Java Code Examples for org.apache.calcite.avatica.AvaticaUtils#instantiatePlugin()
The following examples show how to use
org.apache.calcite.avatica.AvaticaUtils#instantiatePlugin() .
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: Lattice.java From Quicksql with MIT License | 6 votes |
/** Builds a lattice. */ public Lattice build() { LatticeStatisticProvider.Factory statisticProvider = this.statisticProvider != null ? AvaticaUtils.instantiatePlugin( LatticeStatisticProvider.Factory.class, this.statisticProvider) : Lattices.CACHED_SQL; Preconditions.checkArgument(rootSchema.isRoot(), "must be root schema"); final ImmutableList.Builder<Column> columnBuilder = ImmutableList.<Column>builder() .addAll(baseColumns) .addAll(derivedColumnsByName.values()); return new Lattice(rootSchema, rootNode, auto, algorithm, algorithmMaxMillis, statisticProvider, rowCountEstimate, columnBuilder.build(), ImmutableSortedSet.copyOf(defaultMeasureSet), tileListBuilder.build(), ImmutableListMultimap.copyOf(columnUses)); }
Example 2
Source File: RelJson.java From Quicksql with MIT License | 6 votes |
SqlOperator toOp(RelInput relInput, Map<String, Object> map) { // in case different operator has the same kind, check with both name and kind. String name = map.get("name").toString(); String kind = map.get("kind").toString(); String syntax = map.get("syntax").toString(); SqlKind sqlKind = SqlKind.valueOf(kind); SqlSyntax sqlSyntax = SqlSyntax.valueOf(syntax); List<SqlOperator> operators = new ArrayList<>(); SqlStdOperatorTable.instance().lookupOperatorOverloads( new SqlIdentifier(name, new SqlParserPos(0, 0)), null, sqlSyntax, operators, SqlNameMatchers.liberal()); for (SqlOperator operator: operators) { if (operator.kind == sqlKind) { return operator; } } String class_ = (String) map.get("class"); if (class_ != null) { return AvaticaUtils.instantiatePlugin(SqlOperator.class, class_); } return null; }
Example 3
Source File: ModelHandler.java From Quicksql with MIT License | 6 votes |
public void visit(JsonCustomSchema jsonSchema) { try { final SchemaPlus parentSchema = currentMutableSchema("sub-schema"); checkRequiredAttributes(jsonSchema, "name", "factory"); final SchemaFactory schemaFactory = AvaticaUtils.instantiatePlugin(SchemaFactory.class, jsonSchema.factory); final Schema schema = schemaFactory.create( parentSchema, jsonSchema.name, operandMap(jsonSchema, jsonSchema.operand)); final SchemaPlus schemaPlus = parentSchema.add(jsonSchema.name, schema); populateSchema(jsonSchema, schemaPlus); } catch (Exception e) { throw new RuntimeException("Error instantiating " + jsonSchema, e); } }
Example 4
Source File: ModelHandler.java From Quicksql with MIT License | 6 votes |
public void visit(JsonJdbcSchema jsonSchema) { checkRequiredAttributes(jsonSchema, "name"); final SchemaPlus parentSchema = currentMutableSchema("jdbc schema"); final DataSource dataSource = JdbcSchema.dataSource(jsonSchema.jdbcUrl, jsonSchema.jdbcDriver, jsonSchema.jdbcUser, jsonSchema.jdbcPassword); final JdbcSchema schema; if (jsonSchema.sqlDialectFactory == null || jsonSchema.sqlDialectFactory.isEmpty()) { schema = JdbcSchema.create(parentSchema, jsonSchema.name, dataSource, jsonSchema.jdbcCatalog, jsonSchema.jdbcSchema); } else { SqlDialectFactory factory = AvaticaUtils.instantiatePlugin( SqlDialectFactory.class, jsonSchema.sqlDialectFactory); schema = JdbcSchema.create(parentSchema, jsonSchema.name, dataSource, factory, jsonSchema.jdbcCatalog, jsonSchema.jdbcSchema); } final SchemaPlus schemaPlus = parentSchema.add(jsonSchema.name, schema); populateSchema(jsonSchema, schemaPlus); }
Example 5
Source File: ModelHandler.java From Quicksql with MIT License | 6 votes |
public void visit(JsonCustomTable jsonTable) { try { checkRequiredAttributes(jsonTable, "name", "factory"); final SchemaPlus schema = currentMutableSchema("table"); final TableFactory tableFactory = AvaticaUtils.instantiatePlugin(TableFactory.class, jsonTable.factory); final Table table = tableFactory.create(schema, jsonTable.name, operandMap(null, jsonTable.operand), null); for (JsonColumn column : jsonTable.columns) { column.accept(this); } schema.add(jsonTable.name, table); } catch (Exception e) { throw new RuntimeException("Error instantiating " + jsonTable, e); } }
Example 6
Source File: JournalledJdbcSchema.java From calcite-sql-rewriter with Apache License 2.0 | 6 votes |
private static DataSource parseDataSource(Map<String, Object> operand) throws IOException { final String connection = (String) operand.get("connection"); Map<String, Object> jdbcConfig; if (connection != null) { try (InputStream connConfig = ClassLoader.getSystemResourceAsStream(connection)) { jdbcConfig = new ObjectMapper().readValue( connConfig, new TypeReference<Map<String, Object>>(){} ); } } else { jdbcConfig = operand; } final String dataSourceName = (String) jdbcConfig.get("dataSource"); if (dataSourceName != null) { return AvaticaUtils.instantiatePlugin(DataSource.class, dataSourceName); } final String jdbcUrl = (String) jdbcConfig.get("jdbcUrl"); final String jdbcDriver = (String) jdbcConfig.get("jdbcDriver"); final String jdbcUser = (String) jdbcConfig.get("jdbcUser"); final String jdbcPassword = (String) jdbcConfig.get("jdbcPassword"); return dataSource(jdbcUrl, jdbcDriver, jdbcUser, jdbcPassword); }
Example 7
Source File: Lattice.java From calcite with Apache License 2.0 | 6 votes |
/** Builds a lattice. */ public Lattice build() { LatticeStatisticProvider.Factory statisticProvider = this.statisticProvider != null ? AvaticaUtils.instantiatePlugin( LatticeStatisticProvider.Factory.class, this.statisticProvider) : Lattices.CACHED_SQL; Preconditions.checkArgument(rootSchema.isRoot(), "must be root schema"); final ImmutableList.Builder<Column> columnBuilder = ImmutableList.<Column>builder() .addAll(baseColumns) .addAll(derivedColumnsByName.values()); return new Lattice(rootSchema, rootNode, auto, algorithm, algorithmMaxMillis, statisticProvider, rowCountEstimate, columnBuilder.build(), ImmutableSortedSet.copyOf(defaultMeasureSet), tileListBuilder.build(), ImmutableListMultimap.copyOf(columnUses)); }
Example 8
Source File: RelJson.java From calcite with Apache License 2.0 | 6 votes |
SqlOperator toOp(Map<String, Object> map) { // in case different operator has the same kind, check with both name and kind. String name = map.get("name").toString(); String kind = map.get("kind").toString(); String syntax = map.get("syntax").toString(); SqlKind sqlKind = SqlKind.valueOf(kind); SqlSyntax sqlSyntax = SqlSyntax.valueOf(syntax); List<SqlOperator> operators = new ArrayList<>(); SqlStdOperatorTable.instance().lookupOperatorOverloads( new SqlIdentifier(name, new SqlParserPos(0, 0)), null, sqlSyntax, operators, SqlNameMatchers.liberal()); for (SqlOperator operator: operators) { if (operator.kind == sqlKind) { return operator; } } String class_ = (String) map.get("class"); if (class_ != null) { return AvaticaUtils.instantiatePlugin(SqlOperator.class, class_); } return null; }
Example 9
Source File: ModelHandler.java From calcite with Apache License 2.0 | 6 votes |
public void visit(JsonCustomSchema jsonSchema) { try { final SchemaPlus parentSchema = currentMutableSchema("sub-schema"); checkRequiredAttributes(jsonSchema, "name", "factory"); final SchemaFactory schemaFactory = AvaticaUtils.instantiatePlugin(SchemaFactory.class, jsonSchema.factory); final Schema schema = schemaFactory.create( parentSchema, jsonSchema.name, operandMap(jsonSchema, jsonSchema.operand)); final SchemaPlus schemaPlus = parentSchema.add(jsonSchema.name, schema); populateSchema(jsonSchema, schemaPlus); } catch (Exception e) { throw new RuntimeException("Error instantiating " + jsonSchema, e); } }
Example 10
Source File: ModelHandler.java From calcite with Apache License 2.0 | 6 votes |
public void visit(JsonJdbcSchema jsonSchema) { checkRequiredAttributes(jsonSchema, "name"); final SchemaPlus parentSchema = currentMutableSchema("jdbc schema"); final DataSource dataSource = JdbcSchema.dataSource(jsonSchema.jdbcUrl, jsonSchema.jdbcDriver, jsonSchema.jdbcUser, jsonSchema.jdbcPassword); final JdbcSchema schema; if (jsonSchema.sqlDialectFactory == null || jsonSchema.sqlDialectFactory.isEmpty()) { schema = JdbcSchema.create(parentSchema, jsonSchema.name, dataSource, jsonSchema.jdbcCatalog, jsonSchema.jdbcSchema); } else { SqlDialectFactory factory = AvaticaUtils.instantiatePlugin( SqlDialectFactory.class, jsonSchema.sqlDialectFactory); schema = JdbcSchema.create(parentSchema, jsonSchema.name, dataSource, factory, jsonSchema.jdbcCatalog, jsonSchema.jdbcSchema); } final SchemaPlus schemaPlus = parentSchema.add(jsonSchema.name, schema); populateSchema(jsonSchema, schemaPlus); }
Example 11
Source File: ModelHandler.java From calcite with Apache License 2.0 | 6 votes |
public void visit(JsonCustomTable jsonTable) { try { checkRequiredAttributes(jsonTable, "name", "factory"); final SchemaPlus schema = currentMutableSchema("table"); final TableFactory tableFactory = AvaticaUtils.instantiatePlugin(TableFactory.class, jsonTable.factory); final Table table = tableFactory.create(schema, jsonTable.name, operandMap(null, jsonTable.operand), null); for (JsonColumn column : jsonTable.columns) { column.accept(this); } schema.add(jsonTable.name, table); } catch (Exception e) { throw new RuntimeException("Error instantiating " + jsonTable, e); } }
Example 12
Source File: JdbcSchema.java From Quicksql with MIT License | 5 votes |
/** * Creates a JdbcSchema, taking credentials from a map. * * @param parentSchema Parent schema * @param name Name * @param operand Map of property/value pairs * @return A JdbcSchema */ public static JdbcSchema create( SchemaPlus parentSchema, String name, Map<String, Object> operand) { DataSource dataSource; try { final String dataSourceName = (String) operand.get("dataSource"); if (dataSourceName != null) { dataSource = AvaticaUtils.instantiatePlugin(DataSource.class, dataSourceName); } else { final String jdbcUrl = (String) operand.get("jdbcUrl"); final String jdbcDriver = (String) operand.get("jdbcDriver"); final String jdbcUser = (String) operand.get("jdbcUser"); final String jdbcPassword = (String) operand.get("jdbcPassword"); dataSource = dataSource(jdbcUrl, jdbcDriver, jdbcUser, jdbcPassword); } } catch (Exception e) { throw new RuntimeException("Error while reading dataSource", e); } String jdbcCatalog = (String) operand.get("jdbcCatalog"); String jdbcSchema = (String) operand.get("jdbcSchema"); String sqlDialectFactory = (String) operand.get("sqlDialectFactory"); if (sqlDialectFactory == null || sqlDialectFactory.isEmpty()) { return JdbcSchema.create( parentSchema, name, dataSource, jdbcCatalog, jdbcSchema); } else { SqlDialectFactory factory = AvaticaUtils.instantiatePlugin( SqlDialectFactory.class, sqlDialectFactory); return JdbcSchema.create( parentSchema, name, dataSource, factory, jdbcCatalog, jdbcSchema); } }
Example 13
Source File: JdbcSchema.java From calcite with Apache License 2.0 | 5 votes |
/** * Creates a JdbcSchema, taking credentials from a map. * * @param parentSchema Parent schema * @param name Name * @param operand Map of property/value pairs * @return A JdbcSchema */ public static JdbcSchema create( SchemaPlus parentSchema, String name, Map<String, Object> operand) { DataSource dataSource; try { final String dataSourceName = (String) operand.get("dataSource"); if (dataSourceName != null) { dataSource = AvaticaUtils.instantiatePlugin(DataSource.class, dataSourceName); } else { final String jdbcUrl = (String) operand.get("jdbcUrl"); final String jdbcDriver = (String) operand.get("jdbcDriver"); final String jdbcUser = (String) operand.get("jdbcUser"); final String jdbcPassword = (String) operand.get("jdbcPassword"); dataSource = dataSource(jdbcUrl, jdbcDriver, jdbcUser, jdbcPassword); } } catch (Exception e) { throw new RuntimeException("Error while reading dataSource", e); } String jdbcCatalog = (String) operand.get("jdbcCatalog"); String jdbcSchema = (String) operand.get("jdbcSchema"); String sqlDialectFactory = (String) operand.get("sqlDialectFactory"); if (sqlDialectFactory == null || sqlDialectFactory.isEmpty()) { return JdbcSchema.create( parentSchema, name, dataSource, jdbcCatalog, jdbcSchema); } else { SqlDialectFactory factory = AvaticaUtils.instantiatePlugin( SqlDialectFactory.class, sqlDialectFactory); return JdbcSchema.create( parentSchema, name, dataSource, factory, jdbcCatalog, jdbcSchema); } }