Search in sources :

Example 1 with CsvTableSink

use of org.apache.flink.table.sinks.CsvTableSink in project flink by apache.

the class TpcdsTestProgram method main.

public static void main(String[] args) throws Exception {
    ParameterTool params = ParameterTool.fromArgs(args);
    String sourceTablePath = params.getRequired("sourceTablePath");
    String queryPath = params.getRequired("queryPath");
    String sinkTablePath = params.getRequired("sinkTablePath");
    Boolean useTableStats = params.getBoolean("useTableStats");
    TableEnvironment tableEnvironment = prepareTableEnv(sourceTablePath, useTableStats);
    // execute TPC-DS queries
    for (String queryId : TPCDS_QUERIES) {
        System.out.println("[INFO]Run TPC-DS query " + queryId + " ...");
        String queryName = QUERY_PREFIX + queryId + QUERY_SUFFIX;
        String queryFilePath = queryPath + FILE_SEPARATOR + queryName;
        String queryString = loadFile2String(queryFilePath);
        Table resultTable = tableEnvironment.sqlQuery(queryString);
        // register sink table
        String sinkTableName = QUERY_PREFIX + queryId + "_sinkTable";
        ((TableEnvironmentInternal) tableEnvironment).registerTableSinkInternal(sinkTableName, new CsvTableSink(sinkTablePath + FILE_SEPARATOR + queryId + RESULT_SUFFIX, COL_DELIMITER, 1, FileSystem.WriteMode.OVERWRITE, resultTable.getSchema().getFieldNames(), resultTable.getSchema().getFieldDataTypes()));
        TableResult tableResult = resultTable.executeInsert(sinkTableName);
        // wait job finish
        tableResult.getJobClient().get().getJobExecutionResult().get();
        System.out.println("[INFO]Run TPC-DS query " + queryId + " success.");
    }
}
Also used : ParameterTool(org.apache.flink.api.java.utils.ParameterTool) ConnectorCatalogTable(org.apache.flink.table.catalog.ConnectorCatalogTable) Table(org.apache.flink.table.api.Table) TableEnvironmentInternal(org.apache.flink.table.api.internal.TableEnvironmentInternal) TableResult(org.apache.flink.table.api.TableResult) CsvTableSink(org.apache.flink.table.sinks.CsvTableSink) TableEnvironment(org.apache.flink.table.api.TableEnvironment)

Example 2 with CsvTableSink

use of org.apache.flink.table.sinks.CsvTableSink in project flink by apache.

the class BatchSQLTestProgram method main.

public static void main(String[] args) throws Exception {
    ParameterTool params = ParameterTool.fromArgs(args);
    String outputPath = params.getRequired("outputPath");
    String sqlStatement = params.getRequired("sqlStatement");
    TableEnvironment tEnv = TableEnvironment.create(EnvironmentSettings.inBatchMode());
    ((TableEnvironmentInternal) tEnv).registerTableSourceInternal("table1", new GeneratorTableSource(10, 100, 60, 0));
    ((TableEnvironmentInternal) tEnv).registerTableSourceInternal("table2", new GeneratorTableSource(5, 0.2f, 60, 5));
    ((TableEnvironmentInternal) tEnv).registerTableSinkInternal("sinkTable", new CsvTableSink(outputPath).configure(new String[] { "f0", "f1" }, new TypeInformation[] { Types.INT, Types.SQL_TIMESTAMP }));
    TableResult result = tEnv.executeSql(sqlStatement);
    // wait job finish
    result.getJobClient().get().getJobExecutionResult().get();
}
Also used : ParameterTool(org.apache.flink.api.java.utils.ParameterTool) TableEnvironmentInternal(org.apache.flink.table.api.internal.TableEnvironmentInternal) TableResult(org.apache.flink.table.api.TableResult) CsvTableSink(org.apache.flink.table.sinks.CsvTableSink) TableEnvironment(org.apache.flink.table.api.TableEnvironment) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation)

Example 3 with CsvTableSink

use of org.apache.flink.table.sinks.CsvTableSink in project flink by apache.

the class CsvTableSinkFactoryTest method testAppendTableSinkFactory.

@Test
public void testAppendTableSinkFactory() {
    DescriptorProperties descriptor = createDescriptor(testingSchema);
    descriptor.putString("update-mode", "append");
    TableSink sink = createTableSink(descriptor);
    assertTrue(sink instanceof CsvTableSink);
    assertEquals(testingSchema.toRowDataType(), sink.getConsumedDataType());
}
Also used : CsvTableSink(org.apache.flink.table.sinks.CsvTableSink) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) TableSink(org.apache.flink.table.sinks.TableSink) CsvTableSink(org.apache.flink.table.sinks.CsvTableSink) Test(org.junit.Test)

Example 4 with CsvTableSink

use of org.apache.flink.table.sinks.CsvTableSink in project flink by apache.

the class CsvTableSinkFactoryTest method testBatchTableSinkFactory.

@Test
public void testBatchTableSinkFactory() {
    DescriptorProperties descriptor = createDescriptor(testingSchema);
    TableSink sink = createTableSink(descriptor);
    assertTrue(sink instanceof CsvTableSink);
    assertEquals(testingSchema.toRowDataType(), sink.getConsumedDataType());
}
Also used : CsvTableSink(org.apache.flink.table.sinks.CsvTableSink) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) TableSink(org.apache.flink.table.sinks.TableSink) CsvTableSink(org.apache.flink.table.sinks.CsvTableSink) Test(org.junit.Test)

Aggregations

CsvTableSink (org.apache.flink.table.sinks.CsvTableSink)4 ParameterTool (org.apache.flink.api.java.utils.ParameterTool)2 TableEnvironment (org.apache.flink.table.api.TableEnvironment)2 TableResult (org.apache.flink.table.api.TableResult)2 TableEnvironmentInternal (org.apache.flink.table.api.internal.TableEnvironmentInternal)2 DescriptorProperties (org.apache.flink.table.descriptors.DescriptorProperties)2 TableSink (org.apache.flink.table.sinks.TableSink)2 Test (org.junit.Test)2 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)1 Table (org.apache.flink.table.api.Table)1 ConnectorCatalogTable (org.apache.flink.table.catalog.ConnectorCatalogTable)1