Search in sources :

Example 1 with RelSchemaProvider

use of org.apache.samza.sql.interfaces.RelSchemaProvider in project samza by apache.

the class SamzaExecutor method getTableSchema.

@Override
public SqlSchema getTableSchema(ExecutionContext context, String tableName) throws ExecutorException {
    /*
     *  currently Shell works only for systems that has Avro schemas
     */
    int execId = execIdSeq.incrementAndGet();
    Map<String, String> staticConfigs = fetchSamzaSqlConfig(execId);
    Config samzaSqlConfig = new MapConfig(staticConfigs);
    SqlSchema sqlSchema;
    try {
        SqlIOResolver ioResolver = SamzaSqlApplicationConfig.createIOResolver(samzaSqlConfig);
        SqlIOConfig sourceInfo = ioResolver.fetchSourceInfo(tableName);
        RelSchemaProvider schemaProvider = SamzaSqlApplicationConfig.initializePlugin("RelSchemaProvider", sourceInfo.getRelSchemaProviderName(), samzaSqlConfig, SamzaSqlApplicationConfig.CFG_FMT_REL_SCHEMA_PROVIDER_DOMAIN, (o, c) -> ((RelSchemaProviderFactory) o).create(sourceInfo.getSystemStream(), c));
        sqlSchema = schemaProvider.getSqlSchema();
    } catch (SamzaException ex) {
        throw new ExecutorException(ex);
    }
    return sqlSchema;
}
Also used : SqlIOConfig(org.apache.samza.sql.interfaces.SqlIOConfig) ExecutorException(org.apache.samza.sql.client.exceptions.ExecutorException) SqlSchema(org.apache.samza.sql.schema.SqlSchema) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) SqlIOConfig(org.apache.samza.sql.interfaces.SqlIOConfig) SqlIOResolver(org.apache.samza.sql.interfaces.SqlIOResolver) RelSchemaProvider(org.apache.samza.sql.interfaces.RelSchemaProvider) SamzaException(org.apache.samza.SamzaException)

Example 2 with RelSchemaProvider

use of org.apache.samza.sql.interfaces.RelSchemaProvider in project samza by apache.

the class QueryPlanner method registerSourceSchemas.

private void registerSourceSchemas(SchemaPlus rootSchema) {
    RelSchemaConverter relSchemaConverter = new RelSchemaConverter();
    for (SqlIOConfig ssc : systemStreamConfigBySource.values()) {
        SchemaPlus previousLevelSchema = rootSchema;
        List<String> sourceParts = ssc.getSourceParts();
        RelSchemaProvider relSchemaProvider = relSchemaProviders.get(ssc.getSource());
        for (int sourcePartIndex = 0; sourcePartIndex < sourceParts.size(); sourcePartIndex++) {
            String sourcePart = sourceParts.get(sourcePartIndex);
            if (sourcePartIndex < sourceParts.size() - 1) {
                SchemaPlus sourcePartSchema = previousLevelSchema.getSubSchema(sourcePart);
                if (sourcePartSchema == null) {
                    sourcePartSchema = previousLevelSchema.add(sourcePart, new AbstractSchema());
                }
                previousLevelSchema = sourcePartSchema;
            } else {
                // If the source part is the last one, then fetch the schema corresponding to the stream and register.
                RelDataType relationalSchema = getSourceRelSchema(relSchemaProvider, relSchemaConverter);
                previousLevelSchema.add(sourcePart, createTableFromRelSchema(relationalSchema));
                break;
            }
        }
    }
}
Also used : SqlIOConfig(org.apache.samza.sql.interfaces.SqlIOConfig) AbstractSchema(org.apache.calcite.schema.impl.AbstractSchema) SchemaPlus(org.apache.calcite.schema.SchemaPlus) RelSchemaProvider(org.apache.samza.sql.interfaces.RelSchemaProvider) RelDataType(org.apache.calcite.rel.type.RelDataType)

Aggregations

RelSchemaProvider (org.apache.samza.sql.interfaces.RelSchemaProvider)2 SqlIOConfig (org.apache.samza.sql.interfaces.SqlIOConfig)2 RelDataType (org.apache.calcite.rel.type.RelDataType)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1 AbstractSchema (org.apache.calcite.schema.impl.AbstractSchema)1 SamzaException (org.apache.samza.SamzaException)1 ExecutorException (org.apache.samza.sql.client.exceptions.ExecutorException)1 SqlIOResolver (org.apache.samza.sql.interfaces.SqlIOResolver)1 SamzaSqlApplicationConfig (org.apache.samza.sql.runner.SamzaSqlApplicationConfig)1 SqlSchema (org.apache.samza.sql.schema.SqlSchema)1