File tree Expand file tree Collapse file tree
fluss-spark-common/src/main/scala/org/apache/fluss/spark
fluss-spark-ut/src/test/scala/org/apache/fluss/spark Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,8 +105,28 @@ object SparkConversions {
105105 org.apache.fluss.metadata.TableChange .set(p.property(), p.value())
106106 case p : TableChange .RemoveProperty =>
107107 org.apache.fluss.metadata.TableChange .reset(p.property())
108+ case p : TableChange .AddColumn =>
109+ if (p.fieldNames().length != 1 ) {
110+ throw new UnsupportedOperationException (
111+ s " Adding nested columns is not supported: ${p.fieldNames().mkString(" ." )}" )
112+ }
113+ org.apache.fluss.metadata.TableChange .addColumn(
114+ p.fieldNames().head,
115+ SparkToFlussTypeVisitor .visit(p.dataType()).copy(p.isNullable()),
116+ p.comment(),
117+ toFlussColumnPosition(p.position()))
108118 // TODO Add full support for table changes
109119 case _ => throw new UnsupportedOperationException (" Unsupported table change" )
110120 }
111121 }
122+
123+ private def toFlussColumnPosition (position : TableChange .ColumnPosition )
124+ : org.apache.fluss.metadata.TableChange .ColumnPosition = {
125+ position match {
126+ case _ : TableChange .First => org.apache.fluss.metadata.TableChange .ColumnPosition .first()
127+ case p : TableChange .After =>
128+ org.apache.fluss.metadata.TableChange .ColumnPosition .after(p.column())
129+ case _ => org.apache.fluss.metadata.TableChange .ColumnPosition .last()
130+ }
131+ }
112132}
Original file line number Diff line number Diff line change @@ -36,6 +36,23 @@ class SparkCatalogTest extends FlussSparkTestBase {
3636
3737 protected def lakeFormat : Option [DataLakeFormat ] = None
3838
39+ test(" Catalog: add columns" ) {
40+ withTable(" t" ) {
41+ sql(" CREATE TABLE t (id int, name string)" )
42+
43+ sql(" ALTER TABLE t ADD COLUMN age bigint" )
44+ checkAnswer(
45+ sql(" DESC t" ),
46+ Row (" id" , " int" , null ) ::
47+ Row (" name" , " string" , null ) ::
48+ Row (" age" , " bigint" , null ) :: Nil )
49+
50+ val table = admin.getTableInfo(createTablePath(" t" )).get()
51+ assertThat(table.getRowType.getFieldCount).isEqualTo(3 )
52+ assertThat(table.getRowType.getFieldNames).containsExactly(" id" , " name" , " age" )
53+ }
54+ }
55+
3956 test(" Catalog: namespaces" ) {
4057 // Always a default database 'fluss'.
4158 checkAnswer(sql(" SHOW DATABASES" ), Row (DEFAULT_DATABASE ) :: Nil )
You can’t perform that action at this time.
0 commit comments