forked from apache/gravitino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apache#2447] feat(spark-connector): support alter table AddColumn an…
…d DropColumn for spark-connector
- Loading branch information
Showing
3 changed files
with
127 additions
and
1 deletion.
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
55 changes: 55 additions & 0 deletions
55
.../test/java/com/datastrato/gravitino/spark/connector/catalog/TestTransformTableChange.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,55 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
|
||
package com.datastrato.gravitino.spark.connector.catalog; | ||
|
||
import java.util.Arrays; | ||
import org.apache.spark.sql.connector.catalog.TableChange; | ||
import org.apache.spark.sql.types.DataTypes; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestTransformTableChange { | ||
|
||
@Test | ||
void testTransformAddColumn() { | ||
TableChange sparkChange = TableChange.addColumn(new String[] {"col1"}, DataTypes.StringType); | ||
com.datastrato.gravitino.rel.TableChange gravitinoChange = | ||
GravitinoCatalog.transformTableChange(sparkChange); | ||
|
||
TableChange.AddColumn sparkAddColumn = (TableChange.AddColumn) sparkChange; | ||
Assertions.assertTrue( | ||
gravitinoChange instanceof com.datastrato.gravitino.rel.TableChange.AddColumn); | ||
com.datastrato.gravitino.rel.TableChange.AddColumn gravitinoAddColumn = | ||
(com.datastrato.gravitino.rel.TableChange.AddColumn) gravitinoChange; | ||
|
||
Assertions.assertEquals(1, sparkAddColumn.fieldNames().length); | ||
Assertions.assertEquals(1, gravitinoAddColumn.fieldName().length); | ||
Assertions.assertEquals( | ||
Arrays.stream(sparkAddColumn.fieldNames()).findFirst(), | ||
Arrays.stream(gravitinoAddColumn.fieldName()).findFirst()); | ||
Assertions.assertEquals(sparkAddColumn.dataType(), gravitinoAddColumn.getDataType()); | ||
} | ||
|
||
@Test | ||
void testTransformDeleteColumn() { | ||
TableChange sparkChange = TableChange.deleteColumn(new String[] {"col1"}, true); | ||
com.datastrato.gravitino.rel.TableChange gravitinoChange = | ||
GravitinoCatalog.transformTableChange(sparkChange); | ||
|
||
TableChange.DeleteColumn sparkDeleteColumn = (TableChange.DeleteColumn) sparkChange; | ||
Assertions.assertTrue( | ||
gravitinoChange instanceof com.datastrato.gravitino.rel.TableChange.DeleteColumn); | ||
com.datastrato.gravitino.rel.TableChange.DeleteColumn gravitinoDeleteColumn = | ||
(com.datastrato.gravitino.rel.TableChange.DeleteColumn) gravitinoChange; | ||
|
||
Assertions.assertEquals(1, sparkDeleteColumn.fieldNames().length); | ||
Assertions.assertEquals(1, gravitinoDeleteColumn.fieldName().length); | ||
Assertions.assertEquals( | ||
Arrays.stream(sparkDeleteColumn.fieldNames()).findFirst(), | ||
Arrays.stream(gravitinoDeleteColumn.fieldName()).findFirst()); | ||
Assertions.assertEquals(sparkDeleteColumn.ifExists(), gravitinoDeleteColumn.getIfExists()); | ||
} | ||
} |