YannByron commented on code in PR #2377: URL: https://github.com/apache/fluss/pull/2377#discussion_r2711210525
########## fluss-spark/fluss-spark-ut/src/test/scala/org/apache/fluss/spark/SparkReadTest.scala: ########## @@ -0,0 +1,342 @@ +/* + * 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.fluss.spark + +import org.apache.spark.sql.Row + +class SparkReadTest extends FlussSparkTestBase { + + test("Spark Read: log table") { + withTable("t") { + sql(s""" + |CREATE TABLE $DEFAULT_DATABASE.t (orderId BIGINT, itemId BIGINT, amount INT, address STRING) + |""".stripMargin) + + sql(s""" + |INSERT INTO $DEFAULT_DATABASE.t + |VALUES + |(600L, 21L, 601, "addr1"), (700L, 22L, 602, "addr2"), + |(800L, 23L, 603, "addr3"), (900L, 24L, 604, "addr4"), + |(1000L, 25L, 605, "addr5") + |""".stripMargin) + + checkAnswer( + sql(s"SELECT * FROM $DEFAULT_DATABASE.t ORDER BY orderId"), + Row(600L, 21L, 601, "addr1") :: + Row(700L, 22L, 602, "addr2") :: + Row(800L, 23L, 603, "addr3") :: + Row(900L, 24L, 604, "addr4") :: + Row(1000L, 25L, 605, "addr5") :: Nil + ) + + // projection + checkAnswer( + sql(s"SELECT address, itemId FROM $DEFAULT_DATABASE.t ORDER BY orderId"), + Row("addr1", 21L) :: + Row("addr2", 22L) :: + Row("addr3", 23L) :: + Row("addr4", 24L) :: + Row("addr5", 25L) :: Nil + ) + + // filter + checkAnswer( + sql(s"SELECT * FROM $DEFAULT_DATABASE.t WHERE amount % 2 = 0 ORDER BY orderId"), + Row(700L, 22L, 602, "addr2") :: + Row(900L, 24L, 604, "addr4") :: Nil + ) + + sql(s""" + |INSERT INTO $DEFAULT_DATABASE.t VALUES + |(700L, 220L, 602, "addr2"), + |(900L, 240L, 604, "addr4"), + |(1100L, 260L, 606, "addr6") + |""".stripMargin) + // projection + filter + checkAnswer( + sql(s""" + |SELECT orderId, itemId FROM $DEFAULT_DATABASE.t + |WHERE orderId >= 900 ORDER BY orderId, itemId""".stripMargin), + Row(900L, 24L) :: + Row(900L, 240L) :: + Row(1000L, 25L) :: + Row(1100L, 260L) :: Nil + ) + } + } + + test("Spark Read: primary key table") { + withTable("t") { + sql(s""" + |CREATE TABLE $DEFAULT_DATABASE.t (orderId BIGINT, itemId BIGINT, amount INT, address STRING) + |TBLPROPERTIES("primary.key" = "orderId") + |""".stripMargin) + + sql(s""" + |INSERT INTO $DEFAULT_DATABASE.t VALUES + |(600L, 21L, 601, "addr1"), (700L, 22L, 602, "addr2"), + |(800L, 23L, 603, "addr3"), (900L, 24L, 604, "addr4"), + |(1000L, 25L, 605, "addr5") + |""".stripMargin) + + checkAnswer( + sql(s"SELECT * FROM $DEFAULT_DATABASE.t ORDER BY orderId"), + Row(600L, 21L, 601, "addr1") :: + Row(700L, 22L, 602, "addr2") :: + Row(800L, 23L, 603, "addr3") :: + Row(900L, 24L, 604, "addr4") :: + Row(1000L, 25L, 605, "addr5") :: Nil + ) + + sql(s""" + |INSERT INTO $DEFAULT_DATABASE.t VALUES + |(700L, 220L, 602, "addr2"), + |(900L, 240L, 604, "addr4"), + |(1100L, 260L, 606, "addr6") + |""".stripMargin) + + checkAnswer( + sql(s""" + |SELECT orderId, itemId, address FROM $DEFAULT_DATABASE.t + |WHERE amount <= 603 ORDER BY orderId""".stripMargin), + Row(600L, 21L, "addr1") :: + Row(700L, 220L, "addr2") :: + Row(800L, 23L, "addr3") :: + Nil + ) + } + } + + test("Spark Read: partitioned log table") { + withTable("t") { + sql( + s""" + |CREATE TABLE $DEFAULT_DATABASE.t (orderId BIGINT, itemId BIGINT, amount INT, address STRING, dt STRING) + |PARTITIONED BY (dt) + |""".stripMargin + ) + + sql(s""" + |INSERT INTO $DEFAULT_DATABASE.t VALUES + |(600L, 21L, 601, "addr1", "2026-01-01"), (700L, 22L, 602, "addr2", "2026-01-01"), + |(800L, 23L, 603, "addr3", "2026-01-02"), (900L, 24L, 604, "addr4", "2026-01-02"), + |(1000L, 25L, 605, "addr5", "2026-01-03") + |""".stripMargin) + + checkAnswer( + sql(s"SELECT * FROM $DEFAULT_DATABASE.t ORDER BY orderId"), + Row(600L, 21L, 601, "addr1", "2026-01-01") :: + Row(700L, 22L, 602, "addr2", "2026-01-01") :: + Row(800L, 23L, 603, "addr3", "2026-01-02") :: + Row(900L, 24L, 604, "addr4", "2026-01-02") :: + Row(1000L, 25L, 605, "addr5", "2026-01-03") :: Nil + ) + + // Read with partition filter + checkAnswer( + sql(s"SELECT * FROM $DEFAULT_DATABASE.t WHERE dt = '2026-01-01' ORDER BY orderId"), + Row(600L, 21L, 601, "addr1", "2026-01-01") :: + Row(700L, 22L, 602, "addr2", "2026-01-01") :: Nil + ) + + // Read with multiple partitions filter + checkAnswer( + sql(s""" + |SELECT orderId, address, dt FROM $DEFAULT_DATABASE.t + |WHERE dt IN ('2026-01-01', '2026-01-02') + |ORDER BY orderId""".stripMargin), + Row(600L, "addr1", "2026-01-01") :: + Row(700L, "addr2", "2026-01-01") :: + Row(800L, "addr3", "2026-01-02") :: + Row(900L, "addr4", "2026-01-02") :: Nil + ) + } + } + + test("Spark Read: partitioned primary key table") { + withTable("t") { + sql(s""" + |CREATE TABLE $DEFAULT_DATABASE.t (orderId BIGINT, itemId BIGINT, amount INT, address STRING, dt STRING) + |PARTITIONED BY (dt) + |TBLPROPERTIES("primary.key" = "orderId,dt") + |""".stripMargin) + + sql(s""" + |INSERT INTO $DEFAULT_DATABASE.t VALUES + |(600L, 21L, 601, "addr1", "2026-01-01"), (700L, 22L, 602, "addr2", "2026-01-01"), + |(800L, 23L, 603, "addr3", "2026-01-02"), (900L, 24L, 604, "addr4", "2026-01-02"), + |(1000L, 25L, 605, "addr5", "2026-01-03") + |""".stripMargin) + sql(s""" + |INSERT INTO $DEFAULT_DATABASE.t VALUES + |(700L, 220L, 602, "addr2_updated", "2026-01-01"), + |(900L, 240L, 604, "addr4_updated", "2026-01-02"), + |(1100L, 260L, 606, "addr6", "2026-01-03") + |""".stripMargin) + + checkAnswer( + sql(s"SELECT * FROM $DEFAULT_DATABASE.t ORDER BY orderId"), + Row(600L, 21L, 601, "addr1", "2026-01-01") :: + Row(700L, 220L, 602, "addr2_updated", "2026-01-01") :: + Row(800L, 23L, 603, "addr3", "2026-01-02") :: + Row(900L, 240L, 604, "addr4_updated", "2026-01-02") :: + Row(1000L, 25L, 605, "addr5", "2026-01-03") :: + Row(1100L, 260L, 606, "addr6", "2026-01-03") :: Review Comment: https://github.com/apache/fluss/issues/2427 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
