Skip to content

Commit

Permalink
[spark] Show create table display using paimon (apache#2460)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zouxxyy authored Dec 7, 2023
1 parent 74f85ce commit c7e8432
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public Table createTable(
Transform[] partitions,
Map<String, String> properties)
throws TableAlreadyExistsException, NoSuchNamespaceException {
String provider = properties.get("provider");
String provider = properties.get(TableCatalog.PROP_PROVIDER);
if (usePaimon(provider)) {
return sparkCatalog.createTable(ident, schema, partitions, properties);
} else {
Expand Down Expand Up @@ -284,7 +284,7 @@ public String name() {
}

private boolean usePaimon(String provider) {
return provider == null || "paimon".equalsIgnoreCase(provider);
return provider == null || SparkSource.NAME().equalsIgnoreCase(provider);
}

private T getSessionCatalog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.spark.sql.connector.catalog.SupportsRead;
import org.apache.spark.sql.connector.catalog.SupportsWrite;
import org.apache.spark.sql.connector.catalog.TableCapability;
import org.apache.spark.sql.connector.catalog.TableCatalog;
import org.apache.spark.sql.connector.expressions.FieldReference;
import org.apache.spark.sql.connector.expressions.IdentityTransform;
import org.apache.spark.sql.connector.expressions.Transform;
Expand Down Expand Up @@ -108,10 +109,11 @@ public Map<String, String> properties() {
if (table instanceof DataTable) {
Map<String, String> properties =
new HashMap<>(((DataTable) table).coreOptions().toMap());
if (table.primaryKeys().size() > 0) {
if (!table.primaryKeys().isEmpty()) {
properties.put(
CoreOptions.PRIMARY_KEY.key(), String.join(",", table.primaryKeys()));
}
properties.put(TableCatalog.PROP_PROVIDER, SparkSource.NAME());
return properties;
} else {
return Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ public void testShowCreateTable() {
.isEqualTo(
String.format(
"[[%s"
+ "USING paimon\n"
+ "PARTITIONED BY (b)\n"
+ "COMMENT 'tbl comment'\n"
+ "TBLPROPERTIES (\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected static void writeTable(String tableName, String... values) {
// return of 'SHOW CREATE TABLE' excluding TBLPROPERTIES
protected String showCreateString(String table, String... fieldSpec) {
return String.format(
"CREATE TABLE paimon.default.%s (%s)\n",
"CREATE TABLE paimon.default.%s (%s)\nUSING paimon\n",
table,
Arrays.stream(fieldSpec).map(s -> "\n " + s).collect(Collectors.joining(",")));
}
Expand Down

0 comments on commit c7e8432

Please sign in to comment.