Skip to content

Commit

Permalink
[apache#2587] feat(spark-connector): support iceberg metadataColumnsspo
Browse files Browse the repository at this point in the history
  • Loading branch information
caican00 committed Mar 21, 2024
1 parent ec2a22c commit b7b2b06
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ private List<SparkColumnInfo> getSimpleTableColumn() {

// Helper method to create a simple table, and could use corresponding
// getSimpleTableColumn to check table column.
private void createSimpleTable(String identifier) {
protected void createSimpleTable(String identifier) {
String createTableSql = getCreateSimpleTableString(identifier);
sql(createTableSql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
package com.datastrato.gravitino.integration.test.spark.iceberg;

import com.datastrato.gravitino.integration.test.spark.SparkCommonIT;
import com.datastrato.gravitino.spark.connector.iceberg.SparkIcebergTable;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.catalyst.analysis.ResolvedTable;
import org.apache.spark.sql.catalyst.plans.logical.CommandResult;
import org.apache.spark.sql.catalyst.plans.logical.DescribeRelation;
import org.apache.spark.sql.connector.catalog.Table;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

@Tag("gravitino-docker-it")
Expand All @@ -21,4 +29,20 @@ protected String getCatalogName() {
protected String getProvider() {
return "lakehouse-iceberg";
}

// TODO
@Test
void testMetadataColumns() {
String tableName = "test_metadata_columns";
dropTableIfExists(tableName);
createSimpleTable(tableName);

Dataset ds = getSparkSession().sql("DESC TABLE EXTENDED " + tableName);
CommandResult result = (CommandResult) ds.logicalPlan();
DescribeRelation relation = (DescribeRelation) result.commandLogicalPlan();
ResolvedTable table = (ResolvedTable) relation.child();
Table table1 = table.table();
Assertions.assertTrue(table1 instanceof SparkIcebergTable);
SparkIcebergTable icebergTable = (SparkIcebergTable) table1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import com.datastrato.gravitino.spark.connector.PropertiesConverter;
import com.datastrato.gravitino.spark.connector.table.SparkBaseTable;
import org.apache.spark.sql.connector.catalog.Identifier;
import org.apache.spark.sql.connector.catalog.MetadataColumn;
import org.apache.spark.sql.connector.catalog.SupportsMetadataColumns;
import org.apache.spark.sql.connector.catalog.TableCatalog;

public class SparkIcebergTable extends SparkBaseTable {
public class SparkIcebergTable extends SparkBaseTable implements SupportsMetadataColumns {

public SparkIcebergTable(
Identifier identifier,
Expand All @@ -20,4 +22,9 @@ public SparkIcebergTable(
PropertiesConverter propertiesConverter) {
super(identifier, gravitinoTable, sparkCatalog, propertiesConverter);
}

@Override
public MetadataColumn[] metadataColumns() {
return ((SupportsMetadataColumns) getSparkTable()).metadataColumns();
}
}

0 comments on commit b7b2b06

Please sign in to comment.