org.apache.flink.table.catalog.exceptions.TableAlreadyExistException Java Examples

The following examples show how to use org.apache.flink.table.catalog.exceptions.TableAlreadyExistException. 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
@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 #2
Source File: DatabaseCalciteSchemaTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCatalogTable() throws TableAlreadyExistException, DatabaseNotExistException {
	GenericInMemoryCatalog catalog = new GenericInMemoryCatalog(catalogName, databaseName);
	DatabaseCalciteSchema calciteSchema = new DatabaseCalciteSchema(true,
		databaseName,
		catalogName,
		catalog);

	catalog.createTable(new ObjectPath(databaseName, tableName), new TestCatalogBaseTable(), false);
	Table table = calciteSchema.getTable(tableName);

	assertThat(table, instanceOf(TableSourceTable.class));
	TableSourceTable tableSourceTable = (TableSourceTable) table;
	assertThat(tableSourceTable.tableSource(), instanceOf(TestExternalTableSource.class));
	assertThat(tableSourceTable.isStreamingMode(), is(true));
}
 
Example #3
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
		throws TableAlreadyExistException, DatabaseNotExistException {
	checkNotNull(tablePath);
	checkNotNull(table);

	if (!databaseExists(tablePath.getDatabaseName())) {
		throw new DatabaseNotExistException(getName(), tablePath.getDatabaseName());
	}

	if (tableExists(tablePath)) {
		if (!ignoreIfExists) {
			throw new TableAlreadyExistException(getName(), tablePath);
		}
	} else {
		tables.put(tablePath, table.copy());

		if (isPartitionedTable(tablePath)) {
			partitions.put(tablePath, new LinkedHashMap<>());
			partitionStats.put(tablePath, new LinkedHashMap<>());
			partitionColumnStats.put(tablePath, new LinkedHashMap<>());
		}
	}
}
 
Example #4
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 #5
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 #6
Source File: DatabaseCalciteSchemaTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCatalogTable() throws TableAlreadyExistException, DatabaseNotExistException {
	GenericInMemoryCatalog catalog = new GenericInMemoryCatalog(catalogName, databaseName);
	CatalogManager catalogManager = CatalogManagerMocks.preparedCatalogManager()
		.defaultCatalog(catalogName, catalog)
		.build();
	catalogManager.setCatalogTableSchemaResolver(new CatalogTableSchemaResolver(new ParserMock(), true));

	DatabaseCalciteSchema calciteSchema = new DatabaseCalciteSchema(
		true,
		databaseName,
		catalogName,
		catalogManager,
		new TableConfig());

	catalog.createTable(new ObjectPath(databaseName, tableName), new TestCatalogBaseTable(), false);
	Table table = calciteSchema.getTable(tableName);

	assertThat(table, instanceOf(TableSourceTable.class));
	TableSourceTable tableSourceTable = (TableSourceTable) table;
	assertThat(tableSourceTable.tableSource(), instanceOf(TestExternalTableSource.class));
	assertThat(tableSourceTable.isStreamingMode(), is(true));
}
 
Example #7
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
		throws TableAlreadyExistException, DatabaseNotExistException {
	checkNotNull(tablePath);
	checkNotNull(table);

	if (!databaseExists(tablePath.getDatabaseName())) {
		throw new DatabaseNotExistException(getName(), tablePath.getDatabaseName());
	}

	if (tableExists(tablePath)) {
		if (!ignoreIfExists) {
			throw new TableAlreadyExistException(getName(), tablePath);
		}
	} else {
		tables.put(tablePath, table.copy());

		if (isPartitionedTable(tablePath)) {
			partitions.put(tablePath, new LinkedHashMap<>());
			partitionStats.put(tablePath, new LinkedHashMap<>());
			partitionColumnStats.put(tablePath, new LinkedHashMap<>());
		}
	}
}
 
Example #8
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 #9
Source File: KuduCatalog.java    From bahir-flink with Apache License 2.0 6 votes vote down vote up
public void createTable(KuduTableInfo tableInfo, boolean ignoreIfExists) throws CatalogException, TableAlreadyExistException {
    ObjectPath path = getObjectPath(tableInfo.getName());
    if (tableExists(path)) {
        if (ignoreIfExists) {
            return;
        } else {
            throw new TableAlreadyExistException(getName(), path);
        }
    }

    try {
        kuduClient.createTable(tableInfo.getName(), tableInfo.getSchema(), tableInfo.getCreateTableOptions());
    } catch (
            KuduException e) {
        throw new CatalogException("Could not create table " + tableInfo.getName(), e);
    }
}
 
Example #10
Source File: DependencyTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Catalog createCatalog(String name, Map<String, String> properties) {
	// Developers may already have their own production/testing hive-site.xml set in their environment,
	// and Flink tests should avoid using those hive-site.xml.
	// Thus, explicitly create a testing HiveConf for unit tests here
	Catalog hiveCatalog = HiveTestUtils.createHiveCatalog(name, properties.get(HiveCatalogValidator.CATALOG_HIVE_VERSION));

	// Creates an additional database to test tableEnv.useDatabase() will switch current database of the catalog
	hiveCatalog.open();
	try {
		hiveCatalog.createDatabase(
			ADDITIONAL_TEST_DATABASE,
			new CatalogDatabaseImpl(new HashMap<>(), null),
			false);
		hiveCatalog.createTable(
			new ObjectPath(ADDITIONAL_TEST_DATABASE, TEST_TABLE),
			new CatalogTableImpl(
				TableSchema.builder()
					.field("testcol", DataTypes.INT())
					.build(),
				new HashMap<String, String>() {{
					put(CatalogConfig.IS_GENERIC, String.valueOf(false));
				}},
				""
			),
			false
		);
		// create a table to test parameterized types
		hiveCatalog.createTable(new ObjectPath("default", TABLE_WITH_PARAMETERIZED_TYPES),
				tableWithParameterizedTypes(),
				false);
	} catch (DatabaseAlreadyExistException | TableAlreadyExistException | DatabaseNotExistException e) {
		throw new CatalogException(e);
	}

	return hiveCatalog;
}
 
Example #11
Source File: CatalogTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateView_TableAlreadyExistException() throws Exception {
	catalog.createDatabase(db1, createDb(), false);
	catalog.createTable(path1, createView(), false);

	exception.expect(TableAlreadyExistException.class);
	exception.expectMessage("Table (or view) db1.t1 already exists in Catalog");
	catalog.createTable(path1, createView(), false);
}
 
Example #12
Source File: CatalogTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testRenameTable_TableAlreadyExistException() throws Exception {
	catalog.createDatabase(db1, createDb(), false);
	CatalogTable table = createTable();
	catalog.createTable(path1, table, false);
	catalog.createTable(path3, createAnotherTable(), false);

	exception.expect(TableAlreadyExistException.class);
	exception.expectMessage("Table (or view) db1.t2 already exists in Catalog");
	catalog.renameTable(path1, t2, false);
}
 
Example #13
Source File: CatalogTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateTable_TableAlreadyExistException() throws Exception {
	catalog.createDatabase(db1, createDb(), false);
	catalog.createTable(path1,  createTable(), false);

	exception.expect(TableAlreadyExistException.class);
	exception.expectMessage("Table (or view) db1.t1 already exists in Catalog");
	catalog.createTable(path1, createTable(), false);
}
 
Example #14
Source File: HiveCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists)
		throws TableNotExistException, TableAlreadyExistException, CatalogException {
	checkNotNull(tablePath, "tablePath cannot be null");
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(newTableName), "newTableName cannot be null or empty");

	try {
		// alter_table() doesn't throw a clear exception when target table doesn't exist.
		// Thus, check the table existence explicitly
		if (tableExists(tablePath)) {
			ObjectPath newPath = new ObjectPath(tablePath.getDatabaseName(), newTableName);
			// alter_table() doesn't throw a clear exception when new table already exists.
			// Thus, check the table existence explicitly
			if (tableExists(newPath)) {
				throw new TableAlreadyExistException(getName(), newPath);
			} else {
				Table table = getHiveTable(tablePath);
				table.setTableName(newTableName);
				client.alter_table(tablePath.getDatabaseName(), tablePath.getObjectName(), table);
			}
		} else if (!ignoreIfNotExists) {
			throw new TableNotExistException(getName(), tablePath);
		}
	} catch (TException e) {
		throw new CatalogException(
			String.format("Failed to rename table %s", tablePath.getFullName()), e);
	}
}
 
Example #15
Source File: KuduCatalog.java    From bahir-flink with Apache License 2.0 5 votes vote down vote up
@Override
public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists) throws TableAlreadyExistException {
    Map<String, String> tableProperties = table.getProperties();
    TableSchema tableSchema = table.getSchema();

    Set<String> optionalProperties = new HashSet<>(Arrays.asList(KUDU_REPLICAS));
    Set<String> requiredProperties = new HashSet<>(Arrays.asList(KUDU_HASH_COLS));

    if (!tableSchema.getPrimaryKey().isPresent()) {
        requiredProperties.add(KUDU_PRIMARY_KEY_COLS);
    }

    if (!tableProperties.keySet().containsAll(requiredProperties)) {
        throw new CatalogException("Missing required property. The following properties must be provided: " +
                requiredProperties.toString());
    }

    Set<String> permittedProperties = Sets.union(requiredProperties, optionalProperties);
    if (!permittedProperties.containsAll(tableProperties.keySet())) {
        throw new CatalogException("Unpermitted properties were given. The following properties are allowed:" +
                permittedProperties.toString());
    }

    String tableName = tablePath.getObjectName();

    KuduTableInfo tableInfo = KuduTableUtils.createTableInfo(tableName, tableSchema, tableProperties);

    createTable(tableInfo, ignoreIfExists);
}
 
Example #16
Source File: FlinkSqlParser.java    From sylph with Apache License 2.0 5 votes vote down vote up
private void translateJoin(JoinInfo joinInfo, Map<String, CreateTable> batchTables)
{
    Table streamTable = getTable(tableEnv, joinInfo.getStreamTable());
    RowTypeInfo streamRowType = (RowTypeInfo) streamTable.getSchema().toRowType();
    DataStream<Row> inputStream = tableEnv.toAppendStream(streamTable, org.apache.flink.types.Row.class);
    inputStream.getTransformation().setOutputType(streamRowType);

    //get batch table schema
    CreateTable batchTable = requireNonNull(batchTables.get(joinInfo.getBatchTable().getName()), "batch table [" + joinInfo.getJoinTableName() + "] not exits");
    RowTypeInfo batchTableRowType = StreamSqlUtil.schemaToRowTypeInfo(StreamSqlUtil.getTableSchema(batchTable));
    List<SelectField> joinSelectFields = getAllSelectFields(joinInfo, streamRowType, batchTableRowType);

    //It is recommended to do keyby first.
    JoinContext joinContext = JoinContextImpl.createContext(joinInfo, streamRowType, joinSelectFields);
    RealTimeTransForm transForm = getJoinTransForm(joinContext, batchTable);
    DataStream<Row> joinResultStream = AsyncFunctionHelper.translate(inputStream, transForm);

    //set schema
    RowTypeInfo rowTypeInfo = getJoinOutScheam(joinSelectFields);
    joinResultStream.getTransformation().setOutputType(rowTypeInfo);
    //--register tmp joinTable

    Catalog catalog = tableEnv.getCatalog(tableEnv.getCurrentCatalog()).get();
    if (catalog.tableExists(ObjectPath.fromString(joinInfo.getJoinTableName()))) {
        Table table = tableEnv.fromDataStream(joinResultStream);
        CatalogBaseTable tableTable = new QueryOperationCatalogView(table.getQueryOperation());
        try {
            catalog.createTable(ObjectPath.fromString(joinInfo.getJoinTableName()), tableTable, true);
        }
        catch (TableAlreadyExistException | DatabaseNotExistException e) {
            e.printStackTrace();
        }
        //tableEnv.replaceRegisteredTable(joinInfo.getJoinTableName(), new RelTable(table.getRelNode()));
    }
    else {
        tableEnv.registerDataStream(joinInfo.getJoinTableName(), joinResultStream);
    }
    //next update join select query
    joinQueryUpdate(joinInfo, rowTypeInfo.getFieldNames());
}
 
Example #17
Source File: DependencyTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Catalog createCatalog(String name, Map<String, String> properties) {
	// Test HiveCatalogFactory.createCatalog
	// But not use it for testing purpose
	assertTrue(super.createCatalog(name, properties) != null);

	// Developers may already have their own production/testing hive-site.xml set in their environment,
	// and Flink tests should avoid using those hive-site.xml.
	// Thus, explicitly create a testing HiveConf for unit tests here
	Catalog hiveCatalog = HiveTestUtils.createHiveCatalog(name, properties.get(HiveCatalogValidator.CATALOG_HIVE_VERSION));

	// Creates an additional database to test tableEnv.useDatabase() will switch current database of the catalog
	hiveCatalog.open();
	try {
		hiveCatalog.createDatabase(
			ADDITIONAL_TEST_DATABASE,
			new CatalogDatabaseImpl(new HashMap<>(), null),
			false);
		hiveCatalog.createTable(
			new ObjectPath(ADDITIONAL_TEST_DATABASE, TEST_TABLE),
			new CatalogTableImpl(
				TableSchema.builder()
					.field("testcol", DataTypes.INT())
					.build(),
				new HashMap<String, String>() {{
					put(CatalogConfig.IS_GENERIC, String.valueOf(true));
				}},
				""
			),
			false
		);
	} catch (DatabaseAlreadyExistException | TableAlreadyExistException | DatabaseNotExistException e) {
		throw new CatalogException(e);
	}

	return hiveCatalog;
}
 
Example #18
Source File: HiveCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists)
		throws TableNotExistException, TableAlreadyExistException, CatalogException {
	checkNotNull(tablePath, "tablePath cannot be null");
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(newTableName), "newTableName cannot be null or empty");

	try {
		// alter_table() doesn't throw a clear exception when target table doesn't exist.
		// Thus, check the table existence explicitly
		if (tableExists(tablePath)) {
			ObjectPath newPath = new ObjectPath(tablePath.getDatabaseName(), newTableName);
			// alter_table() doesn't throw a clear exception when new table already exists.
			// Thus, check the table existence explicitly
			if (tableExists(newPath)) {
				throw new TableAlreadyExistException(getName(), newPath);
			} else {
				Table table = getHiveTable(tablePath);
				table.setTableName(newTableName);
				client.alter_table(tablePath.getDatabaseName(), tablePath.getObjectName(), table);
			}
		} else if (!ignoreIfNotExists) {
			throw new TableNotExistException(getName(), tablePath);
		}
	} catch (TException e) {
		throw new CatalogException(
			String.format("Failed to rename table %s", tablePath.getFullName()), e);
	}
}
 
Example #19
Source File: CatalogTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateView_TableAlreadyExistException() throws Exception {
	catalog.createDatabase(db1, createDb(), false);
	catalog.createTable(path1, createView(), false);

	exception.expect(TableAlreadyExistException.class);
	exception.expectMessage("Table (or view) db1.t1 already exists in Catalog");
	catalog.createTable(path1, createView(), false);
}
 
Example #20
Source File: CatalogTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testRenameTable_TableAlreadyExistException() throws Exception {
	catalog.createDatabase(db1, createDb(), false);
	CatalogTable table = createTable();
	catalog.createTable(path1, table, false);
	catalog.createTable(path3, createAnotherTable(), false);

	exception.expect(TableAlreadyExistException.class);
	exception.expectMessage("Table (or view) db1.t2 already exists in Catalog");
	catalog.renameTable(path1, t2, false);
}
 
Example #21
Source File: JavaTableEnvironmentITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = TableAlreadyExistException.class)
public void testRegisterExistingDatasetTable() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	BatchTableEnvironment tableEnv = BatchTableEnvironment.create(env, config());

	DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
	tableEnv.registerDataSet("MyTable", ds);
	DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 =
			CollectionDataSets.getSmall5TupleDataSet(env);
	// Must fail. Name is already used for different table.
	tableEnv.registerDataSet("MyTable", ds2);
}
 
Example #22
Source File: CatalogTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateTable_TableAlreadyExistException() throws Exception {
	catalog.createDatabase(db1, createDb(), false);
	catalog.createTable(path1,  createTable(), false);

	exception.expect(TableAlreadyExistException.class);
	exception.expectMessage("Table (or view) db1.t1 already exists in Catalog");
	catalog.createTable(path1, createTable(), false);
}
 
Example #23
Source File: PulsarCatalog.java    From pulsar-flink with Apache License 2.0 4 votes vote down vote up
@Override
public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists) throws TableNotExistException, TableAlreadyExistException, CatalogException {
    throw new UnsupportedOperationException();
}
 
Example #24
Source File: AbstractReadOnlyCatalog.java    From bahir-flink with Apache License 2.0 4 votes vote down vote up
@Override
public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists) throws TableAlreadyExistException {
    throw UNSUPPORTED_ERR;
}
 
Example #25
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists)
		throws TableNotExistException, TableAlreadyExistException {
	checkNotNull(tablePath);
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(newTableName));

	if (tableExists(tablePath)) {
		ObjectPath newPath = new ObjectPath(tablePath.getDatabaseName(), newTableName);

		if (tableExists(newPath)) {
			throw new TableAlreadyExistException(getName(), newPath);
		} else {
			tables.put(newPath, tables.remove(tablePath));

			// table statistics
			if (tableStats.containsKey(tablePath)) {
				tableStats.put(newPath, tableStats.remove(tablePath));
			}

			// table column statistics
			if (tableColumnStats.containsKey(tablePath)) {
				tableColumnStats.put(newPath, tableColumnStats.remove(tablePath));
			}

			// partitions
			if (partitions.containsKey(tablePath)) {
				partitions.put(newPath, partitions.remove(tablePath));
			}

			// partition statistics
			if (partitionStats.containsKey(tablePath)) {
				partitionStats.put(newPath, partitionStats.remove(tablePath));
			}

			// partition column statistics
			if (partitionColumnStats.containsKey(tablePath)) {
				partitionColumnStats.put(newPath, partitionColumnStats.remove(tablePath));
			}
		}
	} else if (!ignoreIfNotExists) {
		throw new TableNotExistException(getName(), tablePath);
	}
}
 
Example #26
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists)
		throws TableNotExistException, TableAlreadyExistException {
	checkNotNull(tablePath);
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(newTableName));

	if (tableExists(tablePath)) {
		ObjectPath newPath = new ObjectPath(tablePath.getDatabaseName(), newTableName);

		if (tableExists(newPath)) {
			throw new TableAlreadyExistException(getName(), newPath);
		} else {
			tables.put(newPath, tables.remove(tablePath));

			// table statistics
			if (tableStats.containsKey(tablePath)) {
				tableStats.put(newPath, tableStats.remove(tablePath));
			}

			// table column statistics
			if (tableColumnStats.containsKey(tablePath)) {
				tableColumnStats.put(newPath, tableColumnStats.remove(tablePath));
			}

			// partitions
			if (partitions.containsKey(tablePath)) {
				partitions.put(newPath, partitions.remove(tablePath));
			}

			// partition statistics
			if (partitionStats.containsKey(tablePath)) {
				partitionStats.put(newPath, partitionStats.remove(tablePath));
			}

			// partition column statistics
			if (partitionColumnStats.containsKey(tablePath)) {
				partitionColumnStats.put(newPath, partitionColumnStats.remove(tablePath));
			}
		}
	} else if (!ignoreIfNotExists) {
		throw new TableNotExistException(getName(), tablePath);
	}
}
 
Example #27
Source File: AbstractJdbcCatalog.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists) throws TableAlreadyExistException, DatabaseNotExistException, CatalogException {
	throw new UnsupportedOperationException();
}
 
Example #28
Source File: AbstractJdbcCatalog.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists) throws TableNotExistException, TableAlreadyExistException, CatalogException {
	throw new UnsupportedOperationException();
}
 
Example #29
Source File: Catalog.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new table or view.
 *
 * @param tablePath path of the table or view to be created
 * @param table the table definition
 * @param ignoreIfExists flag to specify behavior when a table or view already exists at the given path:
 *                       if set to false, it throws a TableAlreadyExistException,
 *                       if set to true, do nothing.
 * @throws TableAlreadyExistException if table already exists and ignoreIfExists is false
 * @throws DatabaseNotExistException if the database in tablePath doesn't exist
 * @throws CatalogException in case of any runtime exception
 */
void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
	throws TableAlreadyExistException, DatabaseNotExistException, CatalogException;
 
Example #30
Source File: Catalog.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new table or view.
 *
 * @param tablePath path of the table or view to be created
 * @param table the table definition
 * @param ignoreIfExists flag to specify behavior when a table or view already exists at the given path:
 *                       if set to false, it throws a TableAlreadyExistException,
 *                       if set to true, do nothing.
 * @throws TableAlreadyExistException if table already exists and ignoreIfExists is false
 * @throws DatabaseNotExistException if the database in tablePath doesn't exist
 * @throws CatalogException in case of any runtime exception
 */
void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
	throws TableAlreadyExistException, DatabaseNotExistException, CatalogException;