Skip to content
Closed
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
4 changes: 2 additions & 2 deletions flink-table/flink-sql-client/src/test/resources/sql/table.q
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ org.apache.flink.table.api.ValidationException: Table with identifier 'default_c

describe non_exist;
[ERROR] Could not execute SQL statement. Reason:
org.apache.flink.table.api.ValidationException: Tables or views with the identifier 'default_catalog.default_database.non_exist' doesn't exist
org.apache.flink.table.api.ValidationException: Tables or views with the identifier 'default_catalog.default_database.non_exist' doesn't exist.
!error

desc non_exist;
[ERROR] Could not execute SQL statement. Reason:
org.apache.flink.table.api.ValidationException: Tables or views with the identifier 'default_catalog.default_database.non_exist' doesn't exist
org.apache.flink.table.api.ValidationException: Tables or views with the identifier 'default_catalog.default_database.non_exist' doesn't exist.
!error

alter table non_exist rename to non_exist2;
Expand Down
4 changes: 2 additions & 2 deletions flink-table/flink-sql-gateway/src/test/resources/sql/table.q
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ org.apache.flink.table.api.ValidationException: Table with identifier 'default_c

describe non_exist;
!output
org.apache.flink.table.api.ValidationException: Tables or views with the identifier 'default_catalog.default_database.non_exist' doesn't exist
org.apache.flink.table.api.ValidationException: Tables or views with the identifier 'default_catalog.default_database.non_exist' doesn't exist.
!error

desc non_exist;
!output
org.apache.flink.table.api.ValidationException: Tables or views with the identifier 'default_catalog.default_database.non_exist' doesn't exist
org.apache.flink.table.api.ValidationException: Tables or views with the identifier 'default_catalog.default_database.non_exist' doesn't exist.
Comment on lines +34 to +39
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like same should be applied for sql client's version

Copy link
Member

Choose a reason for hiding this comment

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

+1 flink-sql-client-test need to add this either. then CliClientITCase will call to run it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is missed. I just fixed it and rebased it to master.

!error

alter table non_exist rename to non_exist2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,77 @@

/** SHOW CREATE statement Util. */
@Internal
class ShowCreateUtil {
public class ShowCreateUtil {

private ShowCreateUtil() {}

public static String buildShowCreateTableRow(
ResolvedCatalogBaseTable<?> table,
ObjectIdentifier tableIdentifier,
boolean isTemporary) {
if (table.getTableKind() == CatalogBaseTable.TableKind.VIEW) {
throw new TableException(
String.format(
"SHOW CREATE TABLE is only supported for tables, but %s is a view. Please use SHOW CREATE VIEW instead.",
tableIdentifier.asSerializableString()));
}
final String printIndent = " ";
StringBuilder sb =
new StringBuilder()
.append(buildCreateFormattedPrefix("TABLE", isTemporary, tableIdentifier));
sb.append(extractFormattedColumns(table, printIndent));
extractFormattedWatermarkSpecs(table, printIndent)
.ifPresent(watermarkSpecs -> sb.append(",\n").append(watermarkSpecs));
extractFormattedPrimaryKey(table, printIndent).ifPresent(pk -> sb.append(",\n").append(pk));
sb.append("\n) ");
extractFormattedComment(table)
.ifPresent(
c -> sb.append(String.format("COMMENT '%s'%s", c, System.lineSeparator())));
extractFormattedPartitionedInfo((ResolvedCatalogTable) table)
.ifPresent(
partitionedInfoFormatted ->
sb.append("PARTITIONED BY (")
.append(partitionedInfoFormatted)
.append(")\n"));
extractFormattedOptions(table, printIndent)
.ifPresent(v -> sb.append("WITH (\n").append(v).append("\n)\n"));
return sb.toString();
}

/** Show create view statement only for views. */
public static String buildShowCreateViewRow(
ResolvedCatalogBaseTable<?> view,
ObjectIdentifier viewIdentifier,
boolean isTemporary) {
if (view.getTableKind() != CatalogBaseTable.TableKind.VIEW) {
throw new TableException(
String.format(
"SHOW CREATE VIEW is only supported for views, but %s is a table. Please use SHOW CREATE TABLE instead.",
viewIdentifier.asSerializableString()));
}
StringBuilder stringBuilder = new StringBuilder();
if (view.getOrigin() instanceof QueryOperationCatalogView) {
throw new TableException(
"SHOW CREATE VIEW is not supported for views registered by Table API.");
} else {
stringBuilder.append(
String.format(
"CREATE %sVIEW %s%s as%s%s",
isTemporary ? "TEMPORARY " : "",
viewIdentifier.asSerializableString(),
String.format("(%s)", extractFormattedColumnNames(view)),
System.lineSeparator(),
((CatalogView) view.getOrigin()).getExpandedQuery()));
}
extractFormattedComment(view)
.ifPresent(
c ->
stringBuilder.append(
String.format(
" COMMENT '%s'%s", c, System.lineSeparator())));
return stringBuilder.toString();
}

static String buildCreateFormattedPrefix(
String tableType, boolean isTemporary, ObjectIdentifier identifier) {
return String.format(
Expand Down Expand Up @@ -153,71 +220,4 @@ static String extractFormattedColumnNames(ResolvedCatalogBaseTable<?> baseTable)
.map(EncodingUtils::escapeIdentifier)
.collect(Collectors.joining(", "));
}

static String buildShowCreateTableRow(
ResolvedCatalogBaseTable<?> table,
ObjectIdentifier tableIdentifier,
boolean isTemporary) {
if (table.getTableKind() == CatalogBaseTable.TableKind.VIEW) {
throw new TableException(
String.format(
"SHOW CREATE TABLE is only supported for tables, but %s is a view. Please use SHOW CREATE VIEW instead.",
tableIdentifier.asSerializableString()));
}
final String printIndent = " ";
StringBuilder sb =
new StringBuilder()
.append(buildCreateFormattedPrefix("TABLE", isTemporary, tableIdentifier));
sb.append(extractFormattedColumns(table, printIndent));
extractFormattedWatermarkSpecs(table, printIndent)
.ifPresent(watermarkSpecs -> sb.append(",\n").append(watermarkSpecs));
extractFormattedPrimaryKey(table, printIndent).ifPresent(pk -> sb.append(",\n").append(pk));
sb.append("\n) ");
extractFormattedComment(table)
.ifPresent(
c -> sb.append(String.format("COMMENT '%s'%s", c, System.lineSeparator())));
extractFormattedPartitionedInfo((ResolvedCatalogTable) table)
.ifPresent(
partitionedInfoFormatted ->
sb.append("PARTITIONED BY (")
.append(partitionedInfoFormatted)
.append(")\n"));
extractFormattedOptions(table, printIndent)
.ifPresent(v -> sb.append("WITH (\n").append(v).append("\n)\n"));
return sb.toString();
}

/** Show create view statement only for views. */
static String buildShowCreateViewRow(
ResolvedCatalogBaseTable<?> view,
ObjectIdentifier viewIdentifier,
boolean isTemporary) {
if (view.getTableKind() != CatalogBaseTable.TableKind.VIEW) {
throw new TableException(
String.format(
"SHOW CREATE VIEW is only supported for views, but %s is a table. Please use SHOW CREATE TABLE instead.",
viewIdentifier.asSerializableString()));
}
StringBuilder stringBuilder = new StringBuilder();
if (view.getOrigin() instanceof QueryOperationCatalogView) {
throw new TableException(
"SHOW CREATE VIEW is not supported for views registered by Table API.");
} else {
stringBuilder.append(
String.format(
"CREATE %sVIEW %s%s as%s%s",
isTemporary ? "TEMPORARY " : "",
viewIdentifier.asSerializableString(),
String.format("(%s)", extractFormattedColumnNames(view)),
System.lineSeparator(),
((CatalogView) view.getOrigin()).getExpandedQuery()));
}
extractFormattedComment(view)
.ifPresent(
c ->
stringBuilder.append(
String.format(
" COMMENT '%s'%s", c, System.lineSeparator())));
return stringBuilder.toString();
}
}
Loading