Skip to content
Open
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 @@ -20,13 +20,14 @@ package org.apache.paimon.spark

import org.apache.paimon.CoreOptions
import org.apache.paimon.CoreOptions.BucketFunctionType
import org.apache.paimon.options.CatalogOptions.TABLE_TYPE
import org.apache.paimon.options.Options
import org.apache.paimon.spark.catalog.functions.BucketFunction
import org.apache.paimon.spark.read.PaimonSplitScanBuilder
import org.apache.paimon.spark.schema.PaimonMetadataColumn
import org.apache.paimon.spark.util.OptionUtils
import org.apache.paimon.spark.write.{PaimonV2WriteBuilder, PaimonWriteBuilder}
import org.apache.paimon.table.{Table, _}
import org.apache.paimon.table.{CatalogTableType, Table, _}
import org.apache.paimon.table.BucketMode.{BUCKET_UNAWARE, HASH_FIXED, POSTPONE_MODE}

import org.apache.spark.sql.connector.catalog._
Expand Down Expand Up @@ -84,6 +85,12 @@ abstract class PaimonSparkTableBase(val table: Table)
if (properties.containsKey(CoreOptions.PATH.key())) {
properties.put(TableCatalog.PROP_LOCATION, properties.get(CoreOptions.PATH.key()))
}
if (
CatalogTableType.EXTERNAL.toString.equalsIgnoreCase(
dataTable.options().get(TABLE_TYPE.key()))
) {
properties.put(TableCatalog.PROP_EXTERNAL, "true")
}
properties
case _ => Collections.emptyMap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,30 @@ public void testCreateExternalTable() throws IOException {
}
}

@Test
public void testDescribeExternalAndManagedTableType() throws IOException {
try (SparkSession spark = createSessionBuilder().getOrCreate()) {
spark.sql("CREATE DATABASE IF NOT EXISTS test_db");
spark.sql("USE spark_catalog.test_db");

spark.sql("CREATE EXTERNAL TABLE external_table (a INT, bb INT, c STRING)");
assertThat(
spark.sql("DESC FORMATTED external_table")
.filter("col_name = 'Type'")
.head()
.getString(1))
.isEqualTo("EXTERNAL");

spark.sql("CREATE TABLE managed_table (a INT)");
assertThat(
spark.sql("DESC FORMATTED managed_table")
.filter("col_name = 'Type'")
.head()
.getString(1))
.isEqualTo("MANAGED");
}
}

private SparkSession.Builder createSessionBuilder() {
Path warehousePath = new Path("file:" + tempDir.toString());
return SparkSession.builder()
Expand Down
Loading