columnNames.build(), columnTypes.build(), tableMetadata.getOwner(), temporaryName, connectionUrl,
@Override public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata) { checkArgument(!isNullOrEmpty(tableMetadata.getOwner()), "Table owner is null or empty"); SchemaTableName schemaTableName = tableMetadata.getTable(); String schemaName = schemaTableName.getSchemaName(); String tableName = schemaTableName.getTableName(); List<String> partitionedBy = getPartitionedBy(tableMetadata.getProperties()); List<HiveColumnHandle> columnHandles = getColumnHandles(connectorId, tableMetadata, ImmutableSet.copyOf(partitionedBy)); HiveStorageFormat hiveStorageFormat = getHiveStorageFormat(tableMetadata.getProperties()); Map<String, String> additionalTableParameters = tableParameterCodec.encode(tableMetadata.getProperties()); LocationHandle locationHandle = locationService.forNewTable(session.getQueryId(), schemaName, tableName); Path targetPath = locationService.targetPathRoot(locationHandle); createDirectory(hdfsEnvironment, targetPath); createTable(schemaName, tableName, tableMetadata.getOwner(), columnHandles, hiveStorageFormat, partitionedBy, additionalTableParameters, targetPath); }
@Override public HiveOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorNewTableLayout> layout) { checkNoRollback(); verifyJvmTimeZone(); checkArgument(!isNullOrEmpty(tableMetadata.getOwner()), "Table owner is null or empty"); HiveStorageFormat hiveStorageFormat = getHiveStorageFormat(tableMetadata.getProperties()); List<String> partitionedBy = getPartitionedBy(tableMetadata.getProperties()); Map<String, String> additionalTableParameters = tableParameterCodec.encode(tableMetadata.getProperties()); // get the root directory for the database SchemaTableName schemaTableName = tableMetadata.getTable(); String schemaName = schemaTableName.getSchemaName(); String tableName = schemaTableName.getTableName(); List<HiveColumnHandle> columnHandles = getColumnHandles(connectorId, tableMetadata, ImmutableSet.copyOf(partitionedBy)); HiveOutputTableHandle result = new HiveOutputTableHandle( connectorId, schemaName, tableName, columnHandles, session.getQueryId(), locationService.forNewTable(session.getQueryId(), schemaName, tableName), hiveStorageFormat, partitionedBy, tableMetadata.getOwner(), additionalTableParameters); setRollback(() -> rollbackCreateTable(result)); return result; }
assertEquals(tableMetadata.getOwner(), session.getUser());
@Override public void createTable(final ConnectorSession session, final ConnectorTableMetadata tableMetadata) { Preconditions.checkArgument(!Strings.isNullOrEmpty(tableMetadata.getOwner()), "Table owner is null or empty"); final SchemaTableName schemaTableName = tableMetadata.getTable(); if (tableDao.getBySourceDatabaseTableName(connectorId.toString(), schemaTableName.getSchemaName(), schemaTableName.getTableName()) != null) { throw new TableAlreadyExistsException(schemaTableName); } final Database database = databaseDao .getBySourceDatabaseName(connectorId.toString(), schemaTableName.getSchemaName()); if (database == null) { throw new SchemaNotFoundException(schemaTableName.getSchemaName()); } final Table table = new Table(); table.setName(schemaTableName.getTableName()); table.setDatabase(database); final Location location = converterUtil.toLocation(tableMetadata); if (location != null) { location.setTable(table); table.setLocation(location); } tableDao.save(table); }
protected void doCreateTable(SchemaTableName tableName, HiveStorageFormat storageFormat) throws Exception { ConnectorSession session = newSession(); ConnectorTransactionHandle transaction = newTransaction(); ConnectorMetadata metadata = newMetadata(); // begin creating the table ConnectorTableMetadata tableMetadata = new ConnectorTableMetadata(tableName, CREATE_TABLE_COLUMNS, createTableProperties(storageFormat), session.getUser()); ConnectorOutputTableHandle outputHandle = metadata.beginCreateTable(session, tableMetadata, Optional.empty()); // write the data ConnectorPageSink sink = pageSinkProvider.createPageSink(transaction, session, outputHandle); sink.appendPage(CREATE_TABLE_DATA.toPage(), null); Collection<Slice> fragments = sink.finish(); // verify all new files start with the unique prefix for (String filePath : listAllDataFiles(outputHandle)) { assertTrue(new Path(filePath).getName().startsWith(getFilePrefix(outputHandle))); } // commit the table metadata.finishCreateTable(session, outputHandle, fragments); // load the new table ConnectorTableHandle tableHandle = getTableHandle(metadata, tableName); List<ColumnHandle> columnHandles = ImmutableList.copyOf(metadata.getColumnHandles(session, tableHandle).values()); // verify the metadata tableMetadata = metadata.getTableMetadata(session, getTableHandle(metadata, tableName)); assertEquals(tableMetadata.getOwner(), session.getUser()); assertEquals(tableMetadata.getColumns(), CREATE_TABLE_COLUMNS); // verify the data MaterializedResult result = readTable(tableHandle, columnHandles, session, TupleDomain.all(), OptionalInt.empty(), Optional.of(storageFormat)); assertEqualsIgnoreOrder(result.getMaterializedRows(), CREATE_TABLE_DATA.getMaterializedRows()); }
assertEquals(tableMetadata.getOwner(), tableOwner); assertEquals(tableMetadata.getColumns(), columns);
/** * Creates location. * @param tableMetadata table info * @return location */ public Location toLocation(final ConnectorTableMetadata tableMetadata) { Location location = null; if (tableMetadata instanceof ConnectorTableDetailMetadata) { final ConnectorTableDetailMetadata tableDetailMetadata = (ConnectorTableDetailMetadata) tableMetadata; location = fromStorageInfo(tableDetailMetadata.getStorageInfo(), tableDetailMetadata.getOwner()); } else { location = new Location(); final Info info = new Info(); info.setLocation(location); info.setOwner(tableMetadata.getOwner()); location.setInfo(info); } final Schema schema = new Schema(); schema.setLocation(location); schema.setFields(toFields(tableMetadata, schema)); location.setSchema(schema); return location; }
assertEquals(tableMetadata.getOwner(), session.getUser());
assertEquals(tableMetadata.getOwner(), session.getUser()); assertEquals(tableMetadata.getColumns(), CREATE_TABLE_COLUMNS);