use of com.hortonworks.streamline.streams.sql.runtime.FieldInfo in project streamline by hortonworks.
the class StreamlineSqlImpl method handleCreateTable.
private void handleCreateTable(SqlCreateTable n, Map<String, DataSource> dataSources) {
List<FieldInfo> fields = updateSchema(n);
DataSource ds = DataSourcesRegistry.construct(n.location(), n.inputFormatClass(), n.outputFormatClass(), fields);
if (ds == null) {
throw new RuntimeException("Cannot construct data source for " + n.tableName());
} else if (dataSources.containsKey(n.tableName())) {
throw new RuntimeException("Duplicated definition for table " + n.tableName());
}
dataSources.put(n.tableName(), ds);
}
use of com.hortonworks.streamline.streams.sql.runtime.FieldInfo in project streamline by hortonworks.
the class StreamlineSqlImpl method updateSchema.
private List<FieldInfo> updateSchema(SqlCreateTable n) {
CompilerUtil.TableBuilderInfo builder = new CompilerUtil.TableBuilderInfo(typeFactory);
List<FieldInfo> fields = new ArrayList<>();
for (ColumnDefinition col : n.fieldList()) {
builder.field(col.name(), col.type(), col.constraint());
RelDataType dataType = col.type().deriveType(typeFactory);
Class<?> javaType = (Class<?>) typeFactory.getJavaClass(dataType);
ColumnConstraint constraint = col.constraint();
boolean isPrimary = constraint != null && constraint instanceof ColumnConstraint.PrimaryKey;
fields.add(new FieldInfo(col.name(), javaType, isPrimary));
}
if (n.parallelism() != null) {
builder.parallelismHint(n.parallelism());
}
Table table = builder.build();
schema.add(n.tableName(), table);
return fields;
}
Aggregations