-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### What changes were proposed in this pull request? 1. support basic table DDL and DML operation. (alter table are not supported) 2. add basic table operation to GravitinoCatalog 3. add GravitinoBaseTable class which get schema from Gravitino and do IO with internal spark catalog table. ### Why are the changes needed? Fix: #1529 ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? add spark SQL IT
- Loading branch information
Showing
17 changed files
with
1,069 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...st/src/test/java/com/datastrato/gravitino/integration/test/util/spark/SparkTableInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
|
||
package com.datastrato.gravitino.integration.test.util.spark; | ||
|
||
import com.datastrato.gravitino.spark.ConnectorConstants; | ||
import com.datastrato.gravitino.spark.table.SparkBaseTable; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import lombok.Data; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.spark.sql.types.DataType; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
/** SparkTableInfo is used to check the result in test. */ | ||
@Data | ||
public class SparkTableInfo { | ||
private String tableName; | ||
private String database; | ||
private String comment; | ||
private List<SparkColumnInfo> columns; | ||
private Map<String, String> tableProperties; | ||
private List<String> unknownItems = new ArrayList<>(); | ||
|
||
public SparkTableInfo() {} | ||
|
||
public String getTableName() { | ||
return tableName; | ||
} | ||
|
||
// Include database name and table name | ||
public String getTableIdentifier() { | ||
if (StringUtils.isNotBlank(database)) { | ||
return String.join(".", database, tableName); | ||
} else { | ||
return tableName; | ||
} | ||
} | ||
|
||
static SparkTableInfo create(SparkBaseTable baseTable) { | ||
SparkTableInfo sparkTableInfo = new SparkTableInfo(); | ||
String identifier = baseTable.name(); | ||
String[] items = identifier.split("\\."); | ||
Assertions.assertTrue( | ||
items.length == 2, "Table name format should be $db.$table, but is: " + identifier); | ||
sparkTableInfo.tableName = items[1]; | ||
sparkTableInfo.database = items[0]; | ||
sparkTableInfo.columns = | ||
Arrays.stream(baseTable.schema().fields()) | ||
.map( | ||
sparkField -> | ||
new SparkColumnInfo( | ||
sparkField.name(), | ||
sparkField.dataType(), | ||
sparkField.getComment().isDefined() ? sparkField.getComment().get() : null, | ||
sparkField.nullable())) | ||
.collect(Collectors.toList()); | ||
sparkTableInfo.comment = baseTable.properties().remove(ConnectorConstants.COMMENT); | ||
sparkTableInfo.tableProperties = baseTable.properties(); | ||
return sparkTableInfo; | ||
} | ||
|
||
@Data | ||
public static class SparkColumnInfo { | ||
private String name; | ||
private DataType type; | ||
private String comment; | ||
private boolean isNullable; | ||
|
||
private SparkColumnInfo(String name, DataType type, String comment, boolean isNullable) { | ||
this.name = name; | ||
this.type = type; | ||
this.comment = comment; | ||
this.isNullable = isNullable; | ||
} | ||
|
||
public static SparkColumnInfo of(String name, DataType type) { | ||
return of(name, type, null); | ||
} | ||
|
||
public static SparkColumnInfo of(String name, DataType type, String comment) { | ||
return new SparkColumnInfo(name, type, comment, true); | ||
} | ||
|
||
public static SparkColumnInfo of( | ||
String name, DataType type, String comment, boolean isNullable) { | ||
return new SparkColumnInfo(name, type, comment, isNullable); | ||
} | ||
} | ||
} |
Oops, something went wrong.