/** 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"); return new Lattice(rootSchema, ImmutableList.copyOf(nodes), auto, algorithm, algorithmMaxMillis, statisticProvider, rowCountEstimate, columns, defaultMeasureListBuilder.build(), tileListBuilder.build()); }
/** 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()); }
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); }
public T apply(ConnectionProperty connectionProperty, String s) { if (s == null) { if (defaultInstance != null) { return defaultInstance; } if (!connectionProperty.required()) { return null; } throw new RuntimeException("Required property '" + connectionProperty.camelName() + "' not specified"); } return AvaticaUtils.instantiatePlugin(pluginClass, s); } };
public T apply(ConnectionProperty connectionProperty, String s) { if (s == null) { if (defaultInstance != null) { return defaultInstance; } if (!connectionProperty.required()) { return null; } throw new RuntimeException("Required property '" + connectionProperty.camelName() + "' not specified"); } return AvaticaUtils.instantiatePlugin(pluginClass, s); } };
public T apply(ConnectionProperty connectionProperty, String s) { if (s == null) { if (defaultInstance != null) { return defaultInstance; } if (!connectionProperty.required()) { return null; } throw new RuntimeException("Required property '" + connectionProperty.camelName() + "' not specified"); } return AvaticaUtils.instantiatePlugin(pluginClass, s); } };
if (dataSourceName != null) { dataSource = AvaticaUtils.instantiatePlugin(DataSource.class, dataSourceName); } else { final String jdbcUrl = (String) operand.get("jdbcUrl"); parentSchema, name, dataSource, jdbcCatalog, jdbcSchema); } else { SqlDialectFactory factory = AvaticaUtils.instantiatePlugin( SqlDialectFactory.class, sqlDialectFactory); return JdbcSchema.create(
if (dataSourceName != null) { dataSource = AvaticaUtils.instantiatePlugin(DataSource.class, dataSourceName); } else { final String jdbcUrl = (String) operand.get("jdbcUrl"); parentSchema, name, dataSource, jdbcCatalog, jdbcSchema); } else { SqlDialectFactory factory = AvaticaUtils.instantiatePlugin( SqlDialectFactory.class, sqlDialectFactory); return JdbcSchema.create(
private SqlOperator toOp(String op, Map<String, Object> map) { // TODO: build a map, for more efficient lookup // TODO: look up based on SqlKind final List<SqlOperator> operatorList = SqlStdOperatorTable.instance().getOperatorList(); for (SqlOperator operator : operatorList) { if (operator.getName().equals(op)) { return operator; } } String class_ = (String) map.get("class"); if (class_ != null) { return AvaticaUtils.instantiatePlugin(SqlOperator.class, class_); } return null; }
private SqlOperator toOp(String op, Map<String, Object> map) { // TODO: build a map, for more efficient lookup // TODO: look up based on SqlKind final List<SqlOperator> operatorList = SqlStdOperatorTable.instance().getOperatorList(); for (SqlOperator operator : operatorList) { if (operator.getName().equals(op)) { return operator; } } String class_ = (String) map.get("class"); if (class_ != null) { return AvaticaUtils.instantiatePlugin(SqlOperator.class, class_); } return null; }
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); } }
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); } }
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); } }
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); } }
@Test public void testInstantiatePlugin() { final String s = AvaticaUtils.instantiatePlugin(String.class, "java.lang.String"); assertThat(s, is("")); // No default constructor or INSTANCE member try { final Integer i = AvaticaUtils.instantiatePlugin(Integer.class, "java.lang.Integer"); fail("expected error, got " + i); } catch (Throwable e) { assertThat(e.getMessage(), is("Property 'java.lang.Integer' not valid for plugin type java.lang.Integer")); } final BigInteger b = AvaticaUtils.instantiatePlugin(BigInteger.class, "java.math.BigInteger#ONE"); assertThat(b, is(BigInteger.ONE)); try { final BigInteger b2 = AvaticaUtils.instantiatePlugin(BigInteger.class, "java.math.BigInteger.ONE"); fail("expected error, got " + b2); } catch (Throwable e) { assertThat(e.getMessage(), is("Property 'java.math.BigInteger.ONE' not valid for plugin type java.math.BigInteger")); } }
@Test public void testInstantiatePlugin() { final String s = AvaticaUtils.instantiatePlugin(String.class, "java.lang.String"); assertThat(s, is("")); // No default constructor or INSTANCE member try { final Integer i = AvaticaUtils.instantiatePlugin(Integer.class, "java.lang.Integer"); fail("expected error, got " + i); } catch (Throwable e) { assertThat(e.getMessage(), is("Property 'java.lang.Integer' not valid for plugin type java.lang.Integer")); } final BigInteger b = AvaticaUtils.instantiatePlugin(BigInteger.class, "java.math.BigInteger#ONE"); assertThat(b, is(BigInteger.ONE)); try { final BigInteger b2 = AvaticaUtils.instantiatePlugin(BigInteger.class, "java.math.BigInteger.ONE"); fail("expected error, got " + b2); } catch (Throwable e) { assertThat(e.getMessage(), is("Property 'java.math.BigInteger.ONE' not valid for plugin type java.math.BigInteger")); } }
@Test public void testInstantiatePlugin() { final String s = AvaticaUtils.instantiatePlugin(String.class, "java.lang.String"); assertThat(s, is("")); // No default constructor or INSTANCE member try { final Integer i = AvaticaUtils.instantiatePlugin(Integer.class, "java.lang.Integer"); fail("expected error, got " + i); } catch (Throwable e) { assertThat(e.getMessage(), is("Property 'java.lang.Integer' not valid for plugin type java.lang.Integer")); } final BigInteger b = AvaticaUtils.instantiatePlugin(BigInteger.class, "java.math.BigInteger#ONE"); assertThat(b, is(BigInteger.ONE)); try { final BigInteger b2 = AvaticaUtils.instantiatePlugin(BigInteger.class, "java.math.BigInteger.ONE"); fail("expected error, got " + b2); } catch (Throwable e) { assertThat(e.getMessage(), is("Property 'java.math.BigInteger.ONE' not valid for plugin type java.math.BigInteger")); } } }
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); }
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); }