use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class HiveOutputFormatFactoryTest method testCreateOutputFormat.
@Test
public void testCreateOutputFormat() {
TableSchema schema = TableSchema.builder().field("x", DataTypes.INT()).build();
SerDeInfo serDeInfo = new SerDeInfo("name", LazySimpleSerDe.class.getName(), Collections.emptyMap());
HiveWriterFactory writerFactory = new HiveWriterFactory(new JobConf(), VerifyURIOutputFormat.class, serDeInfo, schema, new String[0], new Properties(), HiveShimLoader.loadHiveShim(HiveShimLoader.getHiveVersion()), false);
HiveOutputFormatFactory factory = new HiveOutputFormatFactory(writerFactory);
org.apache.flink.core.fs.Path path = new org.apache.flink.core.fs.Path(TEST_URI_SCHEME, TEST_URI_AUTHORITY, "/foo/path");
factory.createOutputFormat(path);
}
use of org.apache.flink.table.api.TableSchema in project zeppelin by apache.
the class FlinkSqlInterpreter method callDescribe.
private void callDescribe(String name, InterpreterContext context) throws IOException {
TableSchema schema = tbenv.scan(name.split("\\.")).getSchema();
StringBuilder builder = new StringBuilder();
builder.append("Column\tType\n");
for (int i = 0; i < schema.getFieldCount(); ++i) {
builder.append(schema.getFieldName(i).get() + "\t" + schema.getFieldDataType(i).get() + "\n");
}
context.out.write("%table\n" + builder.toString());
}
use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class CatalogTableImpTest method testToProperties.
@Test
public void testToProperties() {
TableSchema schema = createTableSchema();
Map<String, String> prop = createProperties();
CatalogTable table = new CatalogTableImpl(schema, createPartitionKeys(), prop, TEST);
DescriptorProperties descriptorProperties = new DescriptorProperties(false);
descriptorProperties.putProperties(table.toProperties());
assertEquals(schema, descriptorProperties.getTableSchema(Schema.SCHEMA));
}
use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class CatalogTableImpTest method testNullComment.
@Test
public void testNullComment() {
TableSchema schema = createTableSchema();
Map<String, String> prop = createProperties();
CatalogTable table = new CatalogTableImpl(schema, createPartitionKeys(), prop, null);
assertEquals("", table.getComment());
assertEquals(Optional.of(""), table.getDescription());
}
use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class CsvTableSinkFactoryBase method createTableSink.
protected CsvTableSink createTableSink(Boolean isStreaming, Map<String, String> properties) {
DescriptorProperties params = new DescriptorProperties();
params.putProperties(properties);
// validate
new FileSystemValidator().validate(params);
new OldCsvValidator().validate(params);
new SchemaValidator(isStreaming, false, false).validate(params);
// build
TableSchema tableSchema = TableSchemaUtils.getPhysicalSchema(params.getTableSchema(SCHEMA));
// if a schema is defined, no matter derive schema is set or not, will use the defined
// schema
final boolean hasSchema = params.hasPrefix(FORMAT_FIELDS);
if (hasSchema) {
TableSchema formatSchema = params.getTableSchema(FORMAT_FIELDS);
if (!getFieldLogicalTypes(formatSchema).equals(getFieldLogicalTypes(tableSchema))) {
throw new TableException(String.format("Encodings that differ from the schema are not supported yet for" + " CsvTableSink, format schema is '%s', but table schema is '%s'.", formatSchema, tableSchema));
}
}
String path = params.getString(CONNECTOR_PATH);
String fieldDelimiter = params.getOptionalString(FORMAT_FIELD_DELIMITER).orElse(",");
Optional<String> writeModeParam = params.getOptionalString(FORMAT_WRITE_MODE);
FileSystem.WriteMode writeMode = (writeModeParam.isPresent()) ? FileSystem.WriteMode.valueOf(writeModeParam.get()) : null;
int numFiles = params.getOptionalInt(FORMAT_NUM_FILES).orElse(-1);
// bridge to java.sql.Timestamp/Time/Date
DataType[] dataTypes = Arrays.stream(tableSchema.getFieldDataTypes()).map(dt -> {
switch(dt.getLogicalType().getTypeRoot()) {
case TIMESTAMP_WITHOUT_TIME_ZONE:
return dt.bridgedTo(Timestamp.class);
case TIME_WITHOUT_TIME_ZONE:
return dt.bridgedTo(Time.class);
case DATE:
return dt.bridgedTo(Date.class);
default:
return dt;
}
}).toArray(DataType[]::new);
return new CsvTableSink(path, fieldDelimiter, numFiles, writeMode, tableSchema.getFieldNames(), dataTypes);
}
Aggregations