Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, Con
if (retryMode != NO_RETRIES) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support query retries");
}
if (tableMetadata.getComment().isPresent()) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment");
}

checkNoRollback();

Expand Down Expand Up @@ -136,6 +139,9 @@ private void rollbackCreateTable(AccumuloTable table)
@Override
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting)
{
if (tableMetadata.getComment().isPresent()) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment");
}
client.createTable(tableMetadata);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_DROP_COLUMN:
return false;

case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
return false;

case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_COMMENT_ON_COLUMN:
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ protected JdbcOutputTableHandle createTable(ConnectorSession session, ConnectorT

protected String createTableSql(RemoteTableName remoteTableName, List<String> columns, ConnectorTableMetadata tableMetadata)
{
if (tableMetadata.getComment().isPresent()) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment");
}
checkArgument(tableMetadata.getProperties().isEmpty(), "Unsupported table properties: %s", tableMetadata.getProperties());
return format("CREATE TABLE %s (%s)", quoted(remoteTableName), join(", ", columns));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS:
return false;

case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_COMMENT_ON_COLUMN:
case SUPPORTS_ADD_COLUMN_WITH_COMMENT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import static io.trino.plugin.bigquery.BigQueryTableHandle.BigQueryPartitionType.INGESTION;
import static io.trino.plugin.bigquery.BigQueryType.toField;
import static io.trino.plugin.bigquery.BigQueryUtil.isWildcardTable;
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;
Expand Down Expand Up @@ -371,6 +372,9 @@ public void dropSchema(ConnectorSession session, String schemaName)
@Override
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting)
{
if (tableMetadata.getComment().isPresent()) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment");
}
try {
createTable(session, tableMetadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_RENAME_TABLE:
case SUPPORTS_NOT_NULL_CONSTRAINT:
case SUPPORTS_CREATE_TABLE_WITH_DATA:
case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
case SUPPORTS_DELETE:
case SUPPORTS_INSERT:
case SUPPORTS_ADD_COLUMN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, Con

private CassandraOutputTableHandle createTable(ConnectorTableMetadata tableMetadata)
{
if (tableMetadata.getComment().isPresent()) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment");
}
ImmutableList.Builder<String> columnNames = ImmutableList.builder();
ImmutableList.Builder<Type> columnTypes = ImmutableList.builder();
ImmutableList.Builder<ExtraColumnMetadata> columnExtra = ImmutableList.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_CREATE_VIEW:
return false;

case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
return false;

case SUPPORTS_RENAME_TABLE:
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,20 @@ public void testCommentTable()
assertThatThrownBy(super::testCommentTable)
.hasMessageContaining("Code: 62, e.displayText() = DB::Exception: Syntax error");
}

@Override
public void testCreateTableWithTableComment()
{
// Table comment is unsupported in old ClickHouse version
assertThatThrownBy(super::testCreateTableWithTableComment)
.hasMessageMatching("(?s).* Syntax error: .* COMMENT 'test comment'.*");
}

@Override
public void testCreateTableAsSelectWithTableComment()
{
// Table comment is unsupported in old ClickHouse version
assertThatThrownBy(super::testCreateTableAsSelectWithTableComment)
.hasMessageMatching("(?s).* Syntax error: .* COMMENT 'test comment'.*");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public ConnectorTableMetadata getTableMetadata(ConnectorSession session, Connect
tableHandle.getSchemaTableName(),
columns,
properties.buildOrThrow(),
Optional.empty());
Optional.ofNullable(tableHandle.getMetadataEntry().getDescription()));
}

@Override
Expand Down Expand Up @@ -626,7 +626,8 @@ public void createTable(ConnectorSession session, ConnectorTableMetadata tableMe
CREATE_TABLE_OPERATION,
session,
nodeVersion,
nodeId);
nodeId,
tableMetadata.getComment());

setRollback(() -> deleteRecursivelyIfExists(new HdfsContext(session), hdfsEnvironment, deltaLogDirectory));
transactionLogWriter.flush();
Expand Down Expand Up @@ -735,7 +736,8 @@ public DeltaLakeOutputTableHandle beginCreateTable(ConnectorSession session, Con
tableMetadata.getColumns().stream().map(column -> toColumnHandle(column, partitionedBy)).collect(toImmutableList()),
location,
DeltaLakeTableProperties.getCheckpointInterval(tableMetadata.getProperties()),
external);
external,
tableMetadata.getComment());
}

private Optional<String> getSchemaLocation(Database database)
Expand Down Expand Up @@ -885,7 +887,8 @@ public Optional<ConnectorOutputMetadata> finishCreateTable(
CREATE_TABLE_AS_OPERATION,
session,
nodeVersion,
nodeId);
nodeId,
handle.getComment());
appendAddFileEntries(transactionLogWriter, dataFileInfos, handle.getPartitionedBy(), true);
transactionLogWriter.flush();
PrincipalPrivileges principalPrivileges = buildInitialPrivilegeSet(table.getOwner().orElseThrow());
Expand Down Expand Up @@ -960,7 +963,8 @@ public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle
ADD_COLUMN_OPERATION,
session,
nodeVersion,
nodeId);
nodeId,
Optional.ofNullable(handle.getMetadataEntry().getDescription()));
transactionLogWriter.flush();
}
catch (Exception e) {
Expand All @@ -978,7 +982,8 @@ private static void appendTableEntries(
String operation,
ConnectorSession session,
String nodeVersion,
String nodeId)
String nodeId,
Optional<String> comment)
{
long createdTime = System.currentTimeMillis();
transactionLogWriter.appendCommitInfoEntry(
Expand All @@ -1002,7 +1007,7 @@ private static void appendTableEntries(
new MetadataEntry(
tableId,
null,
null,
comment.orElse(null),
new Format("parquet", ImmutableMap.of()),
serializeSchemaAsJson(columns),
partitionColumnNames,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class DeltaLakeOutputTableHandle
private final String location;
private final Optional<Long> checkpointInterval;
private final boolean external;
private final Optional<String> comment;

@JsonCreator
public DeltaLakeOutputTableHandle(
Expand All @@ -43,14 +44,16 @@ public DeltaLakeOutputTableHandle(
@JsonProperty("inputColumns") List<DeltaLakeColumnHandle> inputColumns,
@JsonProperty("location") String location,
@JsonProperty("checkpointInterval") Optional<Long> checkpointInterval,
@JsonProperty("external") boolean external)
@JsonProperty("external") boolean external,
@JsonProperty("comment") Optional<String> comment)
{
this.schemaName = requireNonNull(schemaName, "schemaName is null");
this.tableName = requireNonNull(tableName, "tableName is null");
this.inputColumns = ImmutableList.copyOf(inputColumns);
this.location = requireNonNull(location, "location is null");
this.checkpointInterval = checkpointInterval;
this.external = external;
this.comment = requireNonNull(comment, "comment is null");
}

@JsonProperty
Expand Down Expand Up @@ -97,4 +100,10 @@ public boolean isExternal()
{
return external;
}

@JsonProperty
public Optional<String> getComment()
{
return comment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -521,23 +521,30 @@ private DeltaLakeTransactionLogEntry buildTxnEntry(ConnectorSession session, Blo
return DeltaLakeTransactionLogEntry.transactionEntry(result);
}

@Nullable
private String getString(Block block, int position)
{
if (block.isNull(position)) {
return null;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it add support for reading checkpoint files we didn't read before?
Should we have a test?

Also, should we have this for getLong, getInt, getByte methods?
If there are supposed to be called on non-null values only, we should probably
have checkArgument(block.isNull(position))` in them

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not new support. It returned an empty character before this change.
TestCheckpointEntryIterator covers both non-empty and null cases.

Added checkArgument to those three methods.

return block.getSlice(position, 0, block.getSliceLength(position)).toString(UTF_8);
}

private long getLong(Block block, int position)
{
checkArgument(!block.isNull(position));
return block.getLong(position, 0);
}

private int getInt(Block block, int position)
{
checkArgument(!block.isNull(position));
return block.getInt(position, 0);
}

private byte getByte(Block block, int position)
{
checkArgument(!block.isNull(position));
return block.getByte(position, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ private static ConnectorPageSink createPageSink(Path outputPath, DeltaLakeWriter
getColumnHandles(),
outputPath.toString(),
Optional.of(deltaLakeConfig.getDefaultCheckpointWritingInterval()),
true);
true,
Optional.empty());

DeltaLakePageSinkProvider provider = new DeltaLakePageSinkProvider(
new GroupByHashPageIndexerFactory(new JoinCompiler(new TypeOperators()), new BlockTypeOperators()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public void testReadMetadataEntry()
.isEqualTo(
new MetadataEntry(
"b6aeffad-da73-4dde-b68e-937e468b1fde",
"",
"",
null,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is "name" a table name? shouldn't it be present?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null,
new MetadataEntry.Format("parquet", Map.of()),
"{\"type\":\"struct\",\"fields\":[" +
"{\"name\":\"name\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}}," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ public void dropSchema(ConnectorSession session, String schemaName)
@Override
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting)
{
if (tableMetadata.getComment().isPresent()) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment");
}
clientSession.createTable(tableMetadata, ignoreExisting);
}

Expand Down Expand Up @@ -329,6 +332,9 @@ public ConnectorOutputTableHandle beginCreateTable(
if (retryMode != NO_RETRIES) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support query retries");
}
if (tableMetadata.getComment().isPresent()) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment");
}
PartitionDesign design = KuduTableProperties.getPartitionDesign(tableMetadata.getProperties());
boolean generateUUID = !design.hasPartitions();
ConnectorTableMetadata finalTableMetadata = tableMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_DELETE:
return true;
case SUPPORTS_RENAME_SCHEMA:
case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_COMMENT_ON_COLUMN:
case SUPPORTS_ARRAY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static io.trino.spi.StandardErrorCode.ALREADY_EXISTS;
import static io.trino.spi.StandardErrorCode.NOT_FOUND;
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static io.trino.spi.StandardErrorCode.SCHEMA_NOT_EMPTY;
import static io.trino.spi.connector.RetryMode.NO_RETRIES;
import static io.trino.spi.connector.SampleType.SYSTEM;
Expand Down Expand Up @@ -235,6 +236,9 @@ public synchronized void createTable(ConnectorSession session, ConnectorTableMet
@Override
public synchronized MemoryOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorTableLayout> layout, RetryMode retryMode)
{
if (tableMetadata.getComment().isPresent()) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment");
}
checkSchemaExists(tableMetadata.getTable().getSchemaName());
checkTableNotExists(tableMetadata.getTable());
long tableId = nextTableId.getAndIncrement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_RENAME_COLUMN:
return false;

case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_COMMENT_ON_COLUMN:
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_JOIN_PUSHDOWN_WITH_DISTINCT_FROM:
return false;

case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
return false;

case SUPPORTS_COMMENT_ON_TABLE:
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,9 @@ public Optional<String> getTableComment(ResultSet resultSet)
@Override
public JdbcOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata)
{
if (tableMetadata.getComment().isPresent()) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment");
}
SchemaTableName schemaTableName = tableMetadata.getTable();
String schema = schemaTableName.getSchemaName();
String table = schemaTableName.getTableName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_AGGREGATION_PUSHDOWN:
return false;

case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_COMMENT_ON_COLUMN:
case SUPPORTS_ADD_COLUMN_WITH_COMMENT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,9 @@ public Optional<String> getTableComment(ResultSet resultSet)
@Override
public JdbcOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata)
{
if (tableMetadata.getComment().isPresent()) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment");
}
SchemaTableName schemaTableName = tableMetadata.getTable();
String schema = schemaTableName.getSchemaName();
String table = schemaTableName.getTableName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_AGGREGATION_PUSHDOWN:
return false;

case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_COMMENT_ON_COLUMN:
case SUPPORTS_ADD_COLUMN_WITH_COMMENT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_JOIN_PUSHDOWN:
return true;

case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_ADD_COLUMN_WITH_COMMENT:
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@ public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, Con
if (retryMode != NO_RETRIES) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support query retries");
}
if (tableMetadata.getComment().isPresent()) {
throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment");
}

if (viewExists(session, tableMetadata.getTable())) {
throw new TrinoException(ALREADY_EXISTS, "View already exists: " + tableMetadata.getTable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
return true;
case SUPPORTS_CREATE_SCHEMA:
case SUPPORTS_RENAME_SCHEMA:
case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_COMMENT_ON_COLUMN:
case SUPPORTS_ADD_COLUMN_WITH_COMMENT:
Expand Down
Loading