org.apache.flink.table.catalog.CatalogTableImpl Java Examples

The following examples show how to use org.apache.flink.table.catalog.CatalogTableImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testAlterTableAddPkConstraintEnforced() throws Exception {
	Catalog catalog = new GenericInMemoryCatalog("default", "default");
	catalogManager.registerCatalog("cat1", catalog);
	catalog.createDatabase("db1", new CatalogDatabaseImpl(new HashMap<>(), null), true);
	CatalogTable catalogTable = new CatalogTableImpl(
			TableSchema.builder()
					.field("a", DataTypes.STRING().notNull())
					.field("b", DataTypes.BIGINT().notNull())
					.field("c", DataTypes.BIGINT())
					.build(),
			new HashMap<>(),
			"tb1");
	catalogManager.setCurrentCatalog("cat1");
	catalogManager.setCurrentDatabase("db1");
	catalog.createTable(new ObjectPath("db1", "tb1"), catalogTable, true);
	// Test alter table add enforced
	thrown.expect(ValidationException.class);
	thrown.expectMessage("Flink doesn't support ENFORCED mode for PRIMARY KEY constaint. "
			+ "ENFORCED/NOT ENFORCED  controls if the constraint checks are performed on the "
			+ "incoming/outgoing data. Flink does not own the data therefore the "
			+ "only supported mode is the NOT ENFORCED mode");
	parse("alter table tb1 add constraint ct1 primary key(a, b)",
			SqlDialect.DEFAULT);
}
 
Example #2
Source File: HiveCatalogDataTypeTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private CatalogTable createCatalogTable(DataType[] types) {
	String[] colNames = new String[types.length];

	for (int i = 0; i < types.length; i++) {
		colNames[i] = String.format("%s_%d", types[i].toString().toLowerCase(), i);
	}

	TableSchema schema = TableSchema.builder()
		.fields(colNames, types)
		.build();

	return new CatalogTableImpl(
		schema,
		new HashMap<String, String>() {{
			put("is_streaming", "false");
			put(CatalogConfig.IS_GENERIC, String.valueOf(false));
		}},
		""
	);
}
 
Example #3
Source File: HiveTableFactoryTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericTable() throws Exception {
	TableSchema schema = TableSchema.builder()
		.field("name", DataTypes.STRING())
		.field("age", DataTypes.INT())
		.build();

	Map<String, String> properties = new HashMap<>();
	properties.put(CatalogConfig.IS_GENERIC, String.valueOf(true));
	properties.put("connector", "COLLECTION");

	catalog.createDatabase("mydb", new CatalogDatabaseImpl(new HashMap<>(), ""), true);
	ObjectPath path = new ObjectPath("mydb", "mytable");
	CatalogTable table = new CatalogTableImpl(schema, properties, "csv table");
	catalog.createTable(path, table, true);
	Optional<TableFactory> opt = catalog.getTableFactory();
	assertTrue(opt.isPresent());
	HiveTableFactory tableFactory = (HiveTableFactory) opt.get();
	TableSource tableSource = tableFactory.createTableSource(path, table);
	assertTrue(tableSource instanceof StreamTableSource);
	TableSink tableSink = tableFactory.createTableSink(path, table);
	assertTrue(tableSink instanceof StreamTableSink);
}
 
Example #4
Source File: HiveTableFactoryTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testHiveTable() throws Exception {
	TableSchema schema = TableSchema.builder()
		.field("name", DataTypes.STRING())
		.field("age", DataTypes.INT())
		.build();

	Map<String, String> properties = new HashMap<>();

	catalog.createDatabase("mydb", new CatalogDatabaseImpl(new HashMap<>(), ""), true);
	ObjectPath path = new ObjectPath("mydb", "mytable");
	CatalogTable table = new CatalogTableImpl(schema, properties, "hive table");
	catalog.createTable(path, table, true);
	Optional<TableFactory> opt = catalog.getTableFactory();
	assertTrue(opt.isPresent());
	HiveTableFactory tableFactory = (HiveTableFactory) opt.get();
	TableSink tableSink = tableFactory.createTableSink(path, table);
	assertTrue(tableSink instanceof HiveTableSink);
	TableSource tableSource = tableFactory.createTableSource(path, table);
	assertTrue(tableSource instanceof HiveTableSource);
}
 
Example #5
Source File: KuduCatalog.java    From bahir-flink with Apache License 2.0 6 votes vote down vote up
@Override
public CatalogTable getTable(ObjectPath tablePath) throws TableNotExistException {
    checkNotNull(tablePath);

    if (!tableExists(tablePath)) {
        throw new TableNotExistException(getName(), tablePath);
    }

    String tableName = tablePath.getObjectName();

    try {
        KuduTable kuduTable = kuduClient.openTable(tableName);

        CatalogTableImpl table = new CatalogTableImpl(
                KuduTableUtils.kuduToFlinkSchema(kuduTable.getSchema()),
                createTableProperties(tableName, kuduTable.getSchema().getPrimaryKeyColumns()),
                tableName);

        return table;
    } catch (KuduException e) {
        throw new CatalogException(e);
    }
}
 
Example #6
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws TableAlreadyExistException, DatabaseNotExistException {
	final ObjectPath path1 = new ObjectPath(catalogManager.getCurrentDatabase(), "t1");
	final ObjectPath path2 = new ObjectPath(catalogManager.getCurrentDatabase(), "t2");
	final TableSchema tableSchema = TableSchema.builder()
		.field("a", DataTypes.BIGINT())
		.field("b", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.field("c", DataTypes.INT())
		.field("d", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.build();
	Map<String, String> properties = new HashMap<>();
	properties.put("connector", "COLLECTION");
	final CatalogTable catalogTable =  new CatalogTableImpl(tableSchema, properties, "");
	catalog.createTable(path1, catalogTable, true);
	catalog.createTable(path2, catalogTable, true);
}
 
Example #7
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws TableAlreadyExistException, DatabaseNotExistException {
	final ObjectPath path1 = new ObjectPath(catalogManager.getCurrentDatabase(), "t1");
	final ObjectPath path2 = new ObjectPath(catalogManager.getCurrentDatabase(), "t2");
	final TableSchema tableSchema = TableSchema.builder()
		.field("a", DataTypes.BIGINT())
		.field("b", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.field("c", DataTypes.INT())
		.field("d", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.build();
	Map<String, String> properties = new HashMap<>();
	properties.put("connector", "COLLECTION");
	final CatalogTable catalogTable =  new CatalogTableImpl(tableSchema, properties, "");
	catalog.createTable(path1, catalogTable, true);
	catalog.createTable(path2, catalogTable, true);
}
 
Example #8
Source File: HiveTableFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TableSource<RowData> createTableSource(TableSourceFactory.Context context) {
	CatalogTable table = checkNotNull(context.getTable());
	Preconditions.checkArgument(table instanceof CatalogTableImpl);

	boolean isGeneric = Boolean.parseBoolean(table.getProperties().get(CatalogConfig.IS_GENERIC));

	if (!isGeneric) {
		return new HiveTableSource(
				new JobConf(hiveConf),
				context.getConfiguration(),
				context.getObjectIdentifier().toObjectPath(),
				table);
	} else {
		return TableFactoryUtil.findAndCreateTableSource(context);
	}
}
 
Example #9
Source File: HiveTableFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TableSink createTableSink(TableSinkFactory.Context context) {
	CatalogTable table = checkNotNull(context.getTable());
	Preconditions.checkArgument(table instanceof CatalogTableImpl);

	boolean isGeneric = Boolean.parseBoolean(table.getProperties().get(CatalogConfig.IS_GENERIC));

	if (!isGeneric) {
		return new HiveTableSink(
				context.getConfiguration().get(
						HiveOptions.TABLE_EXEC_HIVE_FALLBACK_MAPRED_WRITER),
				context.isBounded(),
				new JobConf(hiveConf),
				context.getObjectIdentifier(),
				table);
	} else {
		return TableFactoryUtil.findAndCreateTableSink(context);
	}
}
 
Example #10
Source File: HiveCatalogTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateHiveTable() {
	Map<String, String> map = new HashMap<>(new FileSystem().path("/test_path").toProperties());

	map.put(CatalogConfig.IS_GENERIC, String.valueOf(false));

	Table hiveTable = HiveTableUtil.instantiateHiveTable(
		new ObjectPath("test", "test"),
		new CatalogTableImpl(
			schema,
			map,
			null
		),
		HiveTestUtils.createHiveConf());

	Map<String, String> prop = hiveTable.getParameters();
	assertEquals(prop.remove(CatalogConfig.IS_GENERIC), String.valueOf(false));
	assertTrue(prop.keySet().stream().noneMatch(k -> k.startsWith(CatalogConfig.FLINK_PROPERTY_PREFIX)));
}
 
Example #11
Source File: HiveCatalogGenericMetadataTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericTableSchema() throws Exception {
	catalog.createDatabase(db1, createDb(), false);

	TableSchema tableSchema = TableSchema.builder()
			.fields(new String[]{"col1", "col2", "col3"},
					new DataType[]{DataTypes.TIMESTAMP(3), DataTypes.TIMESTAMP(6), DataTypes.TIMESTAMP(9)})
			.watermark("col3", "col3", DataTypes.TIMESTAMP(9))
			.build();

	ObjectPath tablePath = new ObjectPath(db1, "generic_table");
	try {
		catalog.createTable(tablePath,
				new CatalogTableImpl(tableSchema, getBatchTableProperties(), TEST_COMMENT),
				false);

		assertEquals(tableSchema, catalog.getTable(tablePath).getSchema());
	} finally {
		catalog.dropTable(tablePath, true);
	}
}
 
Example #12
Source File: HiveCatalogHiveMetadataTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void checkStatistics(int inputStat, int expectStat) throws Exception {
	catalog.dropTable(path1, true);

	Map<String, String> properties = new HashMap<>();
	properties.put(CatalogConfig.IS_GENERIC, "false");
	properties.put(StatsSetupConst.ROW_COUNT, String.valueOf(inputStat));
	properties.put(StatsSetupConst.NUM_FILES, String.valueOf(inputStat));
	properties.put(StatsSetupConst.TOTAL_SIZE, String.valueOf(inputStat));
	properties.put(StatsSetupConst.RAW_DATA_SIZE, String.valueOf(inputStat));
	CatalogTable catalogTable = new CatalogTableImpl(
			TableSchema.builder().field("f0", DataTypes.INT()).build(),
			properties,
			"");
	catalog.createTable(path1, catalogTable, false);

	CatalogTableStatistics statistics = catalog.getTableStatistics(path1);
	assertEquals(expectStat, statistics.getRowCount());
	assertEquals(expectStat, statistics.getFileCount());
	assertEquals(expectStat, statistics.getRawDataSize());
	assertEquals(expectStat, statistics.getTotalSize());
}
 
Example #13
Source File: HiveCatalogDataTypeTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private CatalogTable createCatalogTable(DataType[] types) {
	String[] colNames = new String[types.length];

	for (int i = 0; i < types.length; i++) {
		colNames[i] = String.format("%s_%d", types[i].toString().toLowerCase(), i);
	}

	TableSchema schema = TableSchema.builder()
		.fields(colNames, types)
		.build();

	return new CatalogTableImpl(
		schema,
		new HashMap<String, String>() {{
			put("is_streaming", "false");
			put(CatalogConfig.IS_GENERIC, String.valueOf(false));
		}},
		""
	);
}
 
Example #14
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws TableAlreadyExistException, DatabaseNotExistException {
	catalogManager.setCatalogTableSchemaResolver(new CatalogTableSchemaResolver(new ParserMock(), true));
	final ObjectPath path1 = new ObjectPath(catalogManager.getCurrentDatabase(), "t1");
	final ObjectPath path2 = new ObjectPath(catalogManager.getCurrentDatabase(), "t2");
	final TableSchema tableSchema = TableSchema.builder()
		.field("a", DataTypes.BIGINT())
		.field("b", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.field("c", DataTypes.INT())
		.field("d", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.build();
	Map<String, String> properties = new HashMap<>();
	properties.put("connector", "COLLECTION");
	final CatalogTable catalogTable =  new CatalogTableImpl(tableSchema, properties, "");
	catalog.createTable(path1, catalogTable, true);
	catalog.createTable(path2, catalogTable, true);
}
 
Example #15
Source File: HiveCatalogHiveMetadataTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableWithConstraints() throws Exception {
	Assume.assumeTrue(HiveVersionTestUtil.HIVE_310_OR_LATER);
	HiveCatalog hiveCatalog = (HiveCatalog) catalog;
	hiveCatalog.createDatabase(db1, createDb(), false);
	TableSchema.Builder builder = TableSchema.builder();
	builder.fields(
			new String[]{"x", "y", "z"},
			new DataType[]{DataTypes.INT().notNull(), DataTypes.TIMESTAMP(9).notNull(), DataTypes.BIGINT()});
	builder.primaryKey("pk_name", new String[]{"x"});
	hiveCatalog.createTable(path1, new CatalogTableImpl(builder.build(), getBatchTableProperties(), null), false);
	CatalogTable catalogTable = (CatalogTable) hiveCatalog.getTable(path1);
	assertTrue("PK not present", catalogTable.getSchema().getPrimaryKey().isPresent());
	UniqueConstraint pk = catalogTable.getSchema().getPrimaryKey().get();
	assertEquals("pk_name", pk.getName());
	assertEquals(Collections.singletonList("x"), pk.getColumns());
	assertFalse(catalogTable.getSchema().getFieldDataTypes()[0].getLogicalType().isNullable());
	assertFalse(catalogTable.getSchema().getFieldDataTypes()[1].getLogicalType().isNullable());
	assertTrue(catalogTable.getSchema().getFieldDataTypes()[2].getLogicalType().isNullable());

	hiveCatalog.dropDatabase(db1, false, true);
}
 
Example #16
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableLikeNestedWatermark() {
	CatalogTableImpl catalogTable = new CatalogTableImpl(
		TableSchema.builder()
			.field("f0", DataTypes.INT().notNull())
			.field("f1", DataTypes.ROW(DataTypes.FIELD("tmstmp", DataTypes.TIMESTAMP(3))))
			.build(),
		Collections.emptyMap(),
		null
	);
	catalogManager.createTable(catalogTable, ObjectIdentifier.of("builtin", "default", "sourceTable"), false);

	final String sql = "create table derivedTable(\n" +
		"  a int,\n" +
		"  watermark for f1.t as f1.t - interval '5' second\n" +
		")\n" +
		"like sourceTable";

	thrown.expect(ValidationException.class);
	thrown.expectMessage("The rowtime attribute field 'f1.t' is not defined in the table schema," +
		" at line 3, column 20\n" +
		"Nested field 't' was not found in a composite type:" +
		" ROW<`tmstmp` TIMESTAMP(3)>.");
	parseAndConvert(sql);
}
 
Example #17
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableLikeInvalidWatermark() {
	CatalogTableImpl catalogTable = new CatalogTableImpl(
		TableSchema.builder()
			.field("f0", DataTypes.INT().notNull())
			.build(),
		Collections.emptyMap(),
		null
	);
	catalogManager.createTable(catalogTable, ObjectIdentifier.of("builtin", "default", "sourceTable"), false);

	final String sql = "create table derivedTable(\n" +
		"  a int,\n" +
		"  watermark for f1 as `f1` - interval '5' second\n" +
		")\n" +
		"like sourceTable";

	thrown.expect(ValidationException.class);
	thrown.expectMessage("The rowtime attribute field 'f1' is not defined in the table schema," +
		" at line 3, column 17\n" +
		"Available fields: ['f0', 'a']");
	parseAndConvert(sql);
}
 
Example #18
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableLikeInvalidPartition() {
	CatalogTableImpl catalogTable = new CatalogTableImpl(
		TableSchema.builder()
			.field("f0", DataTypes.INT().notNull())
			.build(),
		Collections.emptyMap(),
		null
	);
	catalogManager.createTable(catalogTable, ObjectIdentifier.of("builtin", "default", "sourceTable"), false);

	final String sql = "create table derivedTable(\n" +
		"  a int\n" +
		")\n" +
		"PARTITIONED BY (f3)\n" +
		"like sourceTable";

	thrown.expect(ValidationException.class);
	thrown.expectMessage("Partition column 'f3' not defined in the table schema. Available columns: ['f0', 'a']");
	parseAndConvert(sql);
}
 
Example #19
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testAlterTableAddUniqueConstraint() throws Exception {
	Catalog catalog = new GenericInMemoryCatalog("default", "default");
	catalogManager.registerCatalog("cat1", catalog);
	catalog.createDatabase("db1", new CatalogDatabaseImpl(new HashMap<>(), null), true);
	CatalogTable catalogTable = new CatalogTableImpl(
			TableSchema.builder()
					.field("a", DataTypes.STRING().notNull())
					.field("b", DataTypes.BIGINT().notNull())
					.build(),
			new HashMap<>(),
			"tb1");
	catalogManager.setCurrentCatalog("cat1");
	catalogManager.setCurrentDatabase("db1");
	catalog.createTable(new ObjectPath("db1", "tb1"), catalogTable, true);
	// Test alter add table constraint.
	thrown.expect(UnsupportedOperationException.class);
	thrown.expectMessage("UNIQUE constraint is not supported yet");
	parse("alter table tb1 add constraint ct1 unique(a, b) not enforced",
			SqlDialect.DEFAULT);
}
 
Example #20
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testAlterTableAddUniqueConstraintEnforced() throws Exception {
	Catalog catalog = new GenericInMemoryCatalog("default", "default");
	catalogManager.registerCatalog("cat1", catalog);
	catalog.createDatabase("db1", new CatalogDatabaseImpl(new HashMap<>(), null), true);
	CatalogTable catalogTable = new CatalogTableImpl(
			TableSchema.builder()
					.field("a", DataTypes.STRING().notNull())
					.field("b", DataTypes.BIGINT().notNull())
					.field("c", DataTypes.BIGINT())
					.build(),
			new HashMap<>(),
			"tb1");
	catalogManager.setCurrentCatalog("cat1");
	catalogManager.setCurrentDatabase("db1");
	catalog.createTable(new ObjectPath("db1", "tb1"), catalogTable, true);
	// Test alter table add enforced
	thrown.expect(UnsupportedOperationException.class);
	thrown.expectMessage("UNIQUE constraint is not supported yet");
	parse("alter table tb1 add constraint ct1 unique(a, b)",
			SqlDialect.DEFAULT);
}
 
Example #21
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws TableAlreadyExistException, DatabaseNotExistException {
	catalogManager.setCatalogTableSchemaResolver(new CatalogTableSchemaResolver(parser, isStreamingMode));
	final ObjectPath path1 = new ObjectPath(catalogManager.getCurrentDatabase(), "t1");
	final ObjectPath path2 = new ObjectPath(catalogManager.getCurrentDatabase(), "t2");
	final TableSchema tableSchema = TableSchema.builder()
		.field("a", DataTypes.BIGINT())
		.field("b", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.field("c", DataTypes.INT())
		.field("d", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.build();
	Map<String, String> properties = new HashMap<>();
	properties.put("connector", "COLLECTION");
	final CatalogTable catalogTable =  new CatalogTableImpl(tableSchema, properties, "");
	catalog.createTable(path1, catalogTable, true);
	catalog.createTable(path2, catalogTable, true);
}
 
Example #22
Source File: CatalogStatisticsTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetStatsFromCatalogForCatalogTableImpl() throws Exception {
	Map<String, String> properties = new HashMap<>();
	properties.put("connector.type", "filesystem");
	properties.put("connector.property-version", "1");
	properties.put("connector.path", "/path/to/csv");

	properties.put("format.type", "csv");
	properties.put("format.property-version", "1");
	properties.put("format.field-delimiter", ";");

	catalog.createTable(
			new ObjectPath(databaseName, "T1"),
			new CatalogTableImpl(tableSchema, properties, ""),
			false);
	catalog.createTable(
			new ObjectPath(databaseName, "T2"),
			new CatalogTableImpl(tableSchema, properties, ""),
			false);

	alterTableStatistics(catalog, "T1");
	assertStatistics(tEnv, "T1");

	alterTableStatisticsWithUnknownRowCount(catalog, "T2");
	assertTableStatisticsWithUnknownRowCount(tEnv, "T2");
}
 
Example #23
Source File: CatalogConstraintTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithoutPrimaryKey() throws Exception {
	TableSchema tableSchema = TableSchema.builder().fields(
			new String[] { "a", "b", "c" },
			new DataType[] { DataTypes.BIGINT(), DataTypes.STRING(), DataTypes.INT() }
	).build();
	Map<String, String> properties = buildCatalogTableProperties(tableSchema);

	catalog.createTable(
			new ObjectPath(databaseName, "T1"),
			new CatalogTableImpl(tableSchema, properties, ""),
			false);

	RelNode t1 = TableTestUtil.toRelNode(tEnv.sqlQuery("select * from T1"));
	FlinkRelMetadataQuery mq = FlinkRelMetadataQuery.reuseOrCreate(t1.getCluster().getMetadataQuery());
	assertEquals(ImmutableSet.of(), mq.getUniqueKeys(t1));
}
 
Example #24
Source File: CatalogConstraintTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithPrimaryKey() throws Exception {
	TableSchema tableSchema = TableSchema.builder().fields(
			new String[] { "a", "b", "c" },
			new DataType[] { DataTypes.STRING(), DataTypes.BIGINT().notNull(), DataTypes.INT() }
	).primaryKey("b").build();
	Map<String, String> properties = buildCatalogTableProperties(tableSchema);

	catalog.createTable(
			new ObjectPath(databaseName, "T1"),
			new CatalogTableImpl(tableSchema, properties, ""),
			false);

	RelNode t1 = TableTestUtil.toRelNode(tEnv.sqlQuery("select * from T1"));
	FlinkRelMetadataQuery mq = FlinkRelMetadataQuery.reuseOrCreate(t1.getCluster().getMetadataQuery());
	assertEquals(ImmutableSet.of(ImmutableBitSet.of(1)), mq.getUniqueKeys(t1));
}
 
Example #25
Source File: ConnectTableDescriptorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testProperties() {
	AtomicReference<CatalogTableImpl> reference = new AtomicReference<>();
	Registration registration = (path, table) -> reference.set((CatalogTableImpl) table);
	ConnectTableDescriptor descriptor = new StreamTableDescriptor(
			registration, new FileSystem().path("myPath"))
			.withFormat(new FormatDescriptor("myFormat", 1) {
				@Override
				protected Map<String, String> toFormatProperties() {
					return new HashMap<>();
				}
			})
			.withSchema(new Schema()
					.field("f0", DataTypes.INT())
					.rowtime(new Rowtime().timestampsFromField("f0")));
	descriptor.createTemporaryTable("myTable");

	Assert.assertEquals(descriptor.toProperties(), reference.get().toProperties());
}
 
Example #26
Source File: HiveTableSinkITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private CatalogTable createHiveCatalogTable(TableSchema tableSchema, int numPartCols) {
	if (numPartCols == 0) {
		return new CatalogTableImpl(
			tableSchema,
			new HashMap<String, String>() {{
				// creating a hive table needs explicit is_generic=false flag
				put(CatalogConfig.IS_GENERIC, String.valueOf(false));
			}},
			"");
	}
	String[] partCols = new String[numPartCols];
	System.arraycopy(tableSchema.getFieldNames(), tableSchema.getFieldNames().length - numPartCols, partCols, 0, numPartCols);
	return new CatalogTableImpl(
		tableSchema,
		Arrays.asList(partCols),
		new HashMap<String, String>() {{
			// creating a hive table needs explicit is_generic=false flag
			put(CatalogConfig.IS_GENERIC, String.valueOf(false));
		}},
		"");
}
 
Example #27
Source File: DataGenTableSourceFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static DynamicTableSource createSource(TableSchema schema, Map<String, String> options) {
	return FactoryUtil.createTableSource(
			null,
			ObjectIdentifier.of("", "", ""),
			new CatalogTableImpl(schema, options, ""),
			new Configuration(),
			Thread.currentThread().getContextClassLoader());
}
 
Example #28
Source File: PrintSinkFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrint() {
	Map<String, String> properties = new HashMap<>();
	properties.put("connector", "print");
	properties.put(PRINT_IDENTIFIER.key(), "my_print");
	properties.put(STANDARD_ERROR.key(), "true");

	DynamicTableSink sink = FactoryUtil.createTableSink(
			null,
			ObjectIdentifier.of("", "", ""),
			new CatalogTableImpl(TEST_SCHEMA, properties, ""),
			new Configuration(),
			Thread.currentThread().getContextClassLoader());
	Assert.assertEquals("Print to System.err", sink.asSummaryString());
}
 
Example #29
Source File: BlackHoleSinkFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testBlackHole() {
	Map<String, String> properties = new HashMap<>();
	properties.put("connector", "blackhole");

	DynamicTableSink sink = FactoryUtil.createTableSink(
			null,
			ObjectIdentifier.of("", "", ""),
			new CatalogTableImpl(TEST_SCHEMA, properties, ""),
			new Configuration(),
			Thread.currentThread().getContextClassLoader());

	assertEquals("BlackHole", sink.asSummaryString());
}
 
Example #30
Source File: JsonFormatFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static DynamicTableSink createTableSink(Map<String, String> options) {
	return FactoryUtil.createTableSink(
			null,
			ObjectIdentifier.of("default", "default", "t1"),
			new CatalogTableImpl(SCHEMA, options, "Mock sink table"),
			new Configuration(),
			JsonFormatFactoryTest.class.getClassLoader());
}