Search in sources :

Example 51 with TableEnvironment

use of org.apache.flink.table.api.TableEnvironment in project flink by apache.

the class CatalogITCase method testCreateCatalogFromUserClassLoader.

@Test
public void testCreateCatalogFromUserClassLoader() throws Exception {
    final String className = "UserCatalogFactory";
    URLClassLoader classLoader = ClassLoaderUtils.withRoot(temporaryFolder.newFolder()).addResource("META-INF/services/org.apache.flink.table.factories.Factory", "UserCatalogFactory").addClass(className, "import org.apache.flink.configuration.ConfigOption;\n" + "import org.apache.flink.table.catalog.Catalog;\n" + "import org.apache.flink.table.catalog.GenericInMemoryCatalog;\n" + "import org.apache.flink.table.factories.CatalogFactory;\n" + "\n" + "import java.util.Collections;\n" + "import java.util.Set;\n" + "\n" + "public class UserCatalogFactory implements CatalogFactory {\n" + "    @Override\n" + "    public Catalog createCatalog(Context context) {\n" + "        return new GenericInMemoryCatalog(context.getName());\n" + "    }\n" + "\n" + "    @Override\n" + "    public String factoryIdentifier() {\n" + "        return \"userCatalog\";\n" + "    }\n" + "\n" + "    @Override\n" + "    public Set<ConfigOption<?>> requiredOptions() {\n" + "        return Collections.emptySet();\n" + "    }\n" + "\n" + "    @Override\n" + "    public Set<ConfigOption<?>> optionalOptions() {\n" + "        return Collections.emptySet();\n" + "    }\n" + "}").build();
    try (TemporaryClassLoaderContext context = TemporaryClassLoaderContext.of(classLoader)) {
        TableEnvironment tableEnvironment = getTableEnvironment();
        tableEnvironment.executeSql("CREATE CATALOG cat WITH ('type'='userCatalog')");
        assertTrue(tableEnvironment.getCatalog("cat").isPresent());
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) TemporaryClassLoaderContext(org.apache.flink.util.TemporaryClassLoaderContext) TableEnvironment(org.apache.flink.table.api.TableEnvironment) StreamTableEnvironment(org.apache.flink.table.api.bridge.java.StreamTableEnvironment) Test(org.junit.Test)

Example 52 with TableEnvironment

use of org.apache.flink.table.api.TableEnvironment in project flink by apache.

the class FileSystemTableSourceTest method setup.

@Before
public void setup() {
    util = streamTestUtil(TableConfig.getDefault());
    TableEnvironment tEnv = util.getTableEnv();
    String srcTableDdl = "CREATE TABLE MyTable (\n" + "  a bigint,\n" + "  b int,\n" + "  c varchar\n" + ") with (\n" + " 'connector' = 'filesystem'," + " 'format' = 'testcsv'," + " 'path' = '/tmp')";
    tEnv.executeSql(srcTableDdl);
    String srcTableWithMetaDdl = "CREATE TABLE MyTableWithMeta (\n" + "  a bigint,\n" + "  b int,\n" + "  c varchar,\n" + "  filemeta STRING METADATA FROM 'file.path'\n" + ") with (\n" + " 'connector' = 'filesystem'," + " 'format' = 'testcsv'," + " 'path' = '/tmp')";
    tEnv.executeSql(srcTableWithMetaDdl);
    String sinkTableDdl = "CREATE TABLE MySink (\n" + "  a bigint,\n" + "  b int,\n" + "  c varchar\n" + ") with (\n" + "  'connector' = 'values',\n" + "  'table-sink-class' = 'DEFAULT')";
    tEnv.executeSql(sinkTableDdl);
}
Also used : TableEnvironment(org.apache.flink.table.api.TableEnvironment) Before(org.junit.Before)

Example 53 with TableEnvironment

use of org.apache.flink.table.api.TableEnvironment in project flink by apache.

the class FileSystemTableSinkTest method testFileSystemTableSinkWithParallelismInStreaming.

@Test
public void testFileSystemTableSinkWithParallelismInStreaming() {
    final int parallelism = 5;
    final TableEnvironment tEnv = TableEnvironment.create(EnvironmentSettings.inStreamingMode());
    tEnv.getConfig().set(ExecutionConfigOptions.TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM, 8);
    final String testSourceTableName = "test_source_table";
    tEnv.executeSql(buildSourceTableSql(testSourceTableName, false));
    // verify operator parallelisms when compaction is not enabled
    final String testSinkTableName = "test_sink_table";
    tEnv.executeSql(buildSinkTableSql(testSinkTableName, parallelism, false));
    final String sql0 = buildInsertIntoSql(testSinkTableName, testSourceTableName);
    final String actualNormal = tEnv.explainSql(sql0, ExplainDetail.JSON_EXECUTION_PLAN);
    final String expectedNormal = readFromResource("/explain/filesystem/testFileSystemTableSinkWithParallelismInStreamingSql0.out");
    assertEquals(replaceNodeIdInOperator(replaceStreamNodeId(replaceStageId(expectedNormal))), replaceNodeIdInOperator(replaceStreamNodeId(replaceStageId(actualNormal))));
    // verify operator parallelisms when compaction is enabled
    final String testCompactSinkTableName = "test_compact_sink_table";
    tEnv.executeSql(buildSinkTableSql(testCompactSinkTableName, parallelism, true));
    final String sql1 = buildInsertIntoSql(testCompactSinkTableName, testSourceTableName);
    final String actualCompact = tEnv.explainSql(sql1, ExplainDetail.JSON_EXECUTION_PLAN);
    final String expectedCompact = readFromResource("/explain/filesystem/testFileSystemTableSinkWithParallelismInStreamingSql1.out");
    assertEquals(replaceNodeIdInOperator(replaceStreamNodeId(replaceStageId(expectedCompact))), replaceNodeIdInOperator(replaceStreamNodeId(replaceStageId(actualCompact))));
}
Also used : TableEnvironment(org.apache.flink.table.api.TableEnvironment) Test(org.junit.Test)

Example 54 with TableEnvironment

use of org.apache.flink.table.api.TableEnvironment in project flink by apache.

the class FileSystemTableSinkTest method testExceptionWhenSettingParallelismWithUpdatingQuery.

@Test
public void testExceptionWhenSettingParallelismWithUpdatingQuery() {
    final TableEnvironment tEnv = TableEnvironment.create(EnvironmentSettings.inStreamingMode());
    final String testSourceTableName = "test_source_table";
    tEnv.executeSql(buildSourceTableSql(testSourceTableName, false));
    final String testSinkTableName = "test_sink_table";
    tEnv.executeSql(buildSinkTableSql(testSinkTableName, 10, false));
    String sql = String.format("INSERT INTO %s SELECT DISTINCT * FROM %s", testSinkTableName, testSourceTableName);
    assertThrows("filesystem sink doesn't support setting parallelism (10) by 'sink.parallelism' when the input stream is not INSERT only.", ValidationException.class, () -> tEnv.explainSql(sql));
}
Also used : TableEnvironment(org.apache.flink.table.api.TableEnvironment) Test(org.junit.Test)

Example 55 with TableEnvironment

use of org.apache.flink.table.api.TableEnvironment in project zeppelin by apache.

the class Flink113Shims method startMultipleInsert.

@Override
public void startMultipleInsert(Object tblEnv, InterpreterContext context) throws Exception {
    StatementSet statementSet = ((TableEnvironment) tblEnv).createStatementSet();
    statementSetMap.put(context.getParagraphId(), statementSet);
}
Also used : StatementSet(org.apache.flink.table.api.StatementSet) TableEnvironment(org.apache.flink.table.api.TableEnvironment) BatchTableEnvironment(org.apache.flink.table.api.bridge.scala.BatchTableEnvironment)

Aggregations

TableEnvironment (org.apache.flink.table.api.TableEnvironment)137 Test (org.junit.Test)95 Row (org.apache.flink.types.Row)58 StreamTableEnvironment (org.apache.flink.table.api.bridge.java.StreamTableEnvironment)38 Table (org.apache.flink.table.api.Table)27 ObjectPath (org.apache.flink.table.catalog.ObjectPath)19 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)14 ArrayList (java.util.ArrayList)13 CatalogTable (org.apache.flink.table.catalog.CatalogTable)12 HashMap (java.util.HashMap)11 EnvironmentSettings (org.apache.flink.table.api.EnvironmentSettings)10 CatalogBaseTable (org.apache.flink.table.catalog.CatalogBaseTable)10 TableResult (org.apache.flink.table.api.TableResult)8 File (java.io.File)7 Constructor (java.lang.reflect.Constructor)7 TableImpl (org.apache.flink.table.api.internal.TableImpl)7 TableException (org.apache.flink.table.api.TableException)5 List (java.util.List)4 Configuration (org.apache.flink.configuration.Configuration)4 TableSchema (org.apache.flink.table.api.TableSchema)4