forked from apache/paimon
-
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.
[core] Sort some system table query result (apache#4306)
- Loading branch information
Showing
5 changed files
with
137 additions
and
20 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
84 changes: 84 additions & 0 deletions
84
...aimon-spark-common/src/test/scala/org/apache/paimon/spark/sql/PaimonSystemTableTest.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,84 @@ | ||
/* | ||
* 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.spark.PaimonSparkTestBase | ||
|
||
import org.apache.spark.sql.Row | ||
|
||
class PaimonSystemTableTest extends PaimonSparkTestBase { | ||
|
||
test("system table: sort tags table") { | ||
spark.sql(s""" | ||
|CREATE TABLE T (id STRING, name STRING) | ||
|USING PAIMON | ||
|""".stripMargin) | ||
|
||
spark.sql(s"INSERT INTO T VALUES(1, 'a')") | ||
|
||
spark.sql("CALL paimon.sys.create_tag(table => 'test.T', tag => '2024-10-02')") | ||
spark.sql("CALL paimon.sys.create_tag(table => 'test.T', tag => '2024-10-01')") | ||
spark.sql("CALL paimon.sys.create_tag(table => 'test.T', tag => '2024-10-04')") | ||
spark.sql("CALL paimon.sys.create_tag(table => 'test.T', tag => '2024-10-03')") | ||
|
||
checkAnswer( | ||
spark.sql("select tag_name from `T$tags`"), | ||
Row("2024-10-01") :: Row("2024-10-02") :: Row("2024-10-03") :: Row("2024-10-04") :: Nil) | ||
} | ||
|
||
test("system table: sort partitions table") { | ||
spark.sql(s""" | ||
|CREATE TABLE T (a INT, b STRING,dt STRING,hh STRING) | ||
|PARTITIONED BY (dt, hh) | ||
|TBLPROPERTIES ('primary-key'='a,dt,hh', 'bucket' = '3') | ||
|""".stripMargin) | ||
|
||
spark.sql("INSERT INTO T VALUES(1, 'a', '2024-10-10', '01')") | ||
spark.sql("INSERT INTO T VALUES(3, 'c', '2024-10-10', '23')") | ||
spark.sql("INSERT INTO T VALUES(2, 'b', '2024-10-10', '12')") | ||
spark.sql("INSERT INTO T VALUES(5, 'f', '2024-10-09', '02')") | ||
spark.sql("INSERT INTO T VALUES(4, 'd', '2024-10-09', '01')") | ||
|
||
checkAnswer(spark.sql("select count(*) from `T$partitions`"), Row(5) :: Nil) | ||
checkAnswer( | ||
spark.sql("select partition from `T$partitions`"), | ||
Row("[2024-10-09, 01]") :: Row("[2024-10-09, 02]") :: Row("[2024-10-10, 01]") :: Row( | ||
"[2024-10-10, 12]") :: Row("[2024-10-10, 23]") :: Nil | ||
) | ||
} | ||
|
||
test("system table: sort buckets table") { | ||
spark.sql(s""" | ||
|CREATE TABLE T (a INT, b STRING,dt STRING,hh STRING) | ||
|PARTITIONED BY (dt, hh) | ||
|TBLPROPERTIES ('primary-key'='a,dt,hh', 'bucket' = '3') | ||
|""".stripMargin) | ||
|
||
spark.sql("INSERT INTO T VALUES(1, 'a', '2024-10-10', '01')") | ||
spark.sql("INSERT INTO T VALUES(2, 'b', '2024-10-10', '01')") | ||
spark.sql("INSERT INTO T VALUES(3, 'c', '2024-10-10', '01')") | ||
spark.sql("INSERT INTO T VALUES(4, 'd', '2024-10-10', '01')") | ||
spark.sql("INSERT INTO T VALUES(5, 'f', '2024-10-10', '01')") | ||
|
||
checkAnswer(spark.sql("select count(*) from `T$partitions`"), Row(1) :: Nil) | ||
checkAnswer( | ||
spark.sql("select partition,bucket from `T$buckets`"), | ||
Row("[2024-10-10, 01]", 0) :: Row("[2024-10-10, 01]", 1) :: Row("[2024-10-10, 01]", 2) :: Nil) | ||
} | ||
} |