-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
370eaf2
commit 8d8deba
Showing
6 changed files
with
219 additions
and
2 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
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
85 changes: 85 additions & 0 deletions
85
...k-common/src/main/java/org/apache/paimon/spark/procedure/RefreshObjectTableProcedure.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,85 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.paimon.spark.procedure; | ||
|
||
import org.apache.paimon.table.object.ObjectTable; | ||
|
||
import org.apache.spark.sql.catalyst.InternalRow; | ||
import org.apache.spark.sql.connector.catalog.Identifier; | ||
import org.apache.spark.sql.connector.catalog.TableCatalog; | ||
import org.apache.spark.sql.types.DataTypes; | ||
import org.apache.spark.sql.types.Metadata; | ||
import org.apache.spark.sql.types.StructField; | ||
import org.apache.spark.sql.types.StructType; | ||
|
||
import static org.apache.spark.sql.types.DataTypes.StringType; | ||
|
||
/** Spark procedure to refresh Object Table. */ | ||
public class RefreshObjectTableProcedure extends BaseProcedure { | ||
|
||
private static final ProcedureParameter[] PARAMETERS = | ||
new ProcedureParameter[] {ProcedureParameter.required("table", StringType)}; | ||
|
||
private static final StructType OUTPUT_TYPE = | ||
new StructType( | ||
new StructField[] { | ||
new StructField("file_number", DataTypes.LongType, false, Metadata.empty()) | ||
}); | ||
|
||
protected RefreshObjectTableProcedure(TableCatalog tableCatalog) { | ||
super(tableCatalog); | ||
} | ||
|
||
@Override | ||
public ProcedureParameter[] parameters() { | ||
return PARAMETERS; | ||
} | ||
|
||
@Override | ||
public StructType outputType() { | ||
return OUTPUT_TYPE; | ||
} | ||
|
||
@Override | ||
public InternalRow[] call(InternalRow args) { | ||
Identifier tableIdent = toIdentifier(args.getString(0), PARAMETERS[0].name()); | ||
return modifyPaimonTable( | ||
tableIdent, | ||
table -> { | ||
ObjectTable objectTable = (ObjectTable) table; | ||
long fileNumber = objectTable.refresh(); | ||
InternalRow outputRow = newInternalRow(fileNumber); | ||
return new InternalRow[] {outputRow}; | ||
}); | ||
} | ||
|
||
public static ProcedureBuilder builder() { | ||
return new Builder<RefreshObjectTableProcedure>() { | ||
@Override | ||
public RefreshObjectTableProcedure doBuild() { | ||
return new RefreshObjectTableProcedure(tableCatalog()); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "RefreshObjectTableProcedure"; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...park/paimon-spark-common/src/test/scala/org/apache/paimon/spark/sql/ObjectTableTest.scala
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,62 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.paimon.spark.sql | ||
|
||
import org.apache.paimon.fs.Path | ||
import org.apache.paimon.fs.local.LocalFileIO | ||
import org.apache.paimon.spark.PaimonSparkTestBase | ||
|
||
import org.apache.spark.sql.Row | ||
|
||
class ObjectTableTest extends PaimonSparkTestBase { | ||
|
||
test(s"Paimon object table") { | ||
val objectLocation = new Path(tempDBDir + "/object-location") | ||
val fileIO = LocalFileIO.create | ||
|
||
spark.sql(s""" | ||
|CREATE TABLE T TBLPROPERTIES ( | ||
| 'type' = 'object-table', | ||
| 'object-location' = '$objectLocation' | ||
|) | ||
|""".stripMargin) | ||
|
||
// add new file | ||
fileIO.overwriteFileUtf8(new Path(objectLocation, "f0"), "1,2,3") | ||
spark.sql("CALL sys.refresh_object_table('test.T')") | ||
checkAnswer( | ||
spark.sql("SELECT name, length FROM T"), | ||
Row("f0", 5L) :: Nil | ||
) | ||
|
||
// add new file | ||
fileIO.overwriteFileUtf8(new Path(objectLocation, "f1"), "4,5,6") | ||
spark.sql("CALL sys.refresh_object_table('test.T')") | ||
checkAnswer( | ||
spark.sql("SELECT name, length FROM T"), | ||
Row("f0", 5L) :: Row("f1", 5L) :: Nil | ||
) | ||
|
||
// time travel | ||
checkAnswer( | ||
spark.sql("SELECT name, length FROM T VERSION AS OF 1"), | ||
Row("f0", 5L) :: Nil | ||
) | ||
} | ||
} |