voonhous commented on code in PR #19162:
URL: https://github.com/apache/hudi/pull/19162#discussion_r3886100119


##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/common/TestHoodieSqlCommonUtils.scala:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.spark.sql.hudi.common
+
+import org.apache.hudi.common.table.read.IncrementalQueryAnalyzer
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.spark.sql.catalyst.TableIdentifier
+import org.apache.spark.sql.catalyst.analysis.caseInsensitiveResolution
+import org.apache.spark.sql.catalyst.catalog.{CatalogStorageFormat, 
CatalogTable, CatalogTableType}
+import org.apache.spark.sql.catalyst.expressions.AttributeReference
+import org.apache.spark.sql.hudi.HoodieSqlCommonUtils
+import org.apache.spark.sql.hudi.command.exception.HoodieAnalysisException
+import org.apache.spark.sql.types.{IntegerType, StringType, StructField, 
StructType}
+import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertTrue}
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.funsuite.AnyFunSuite
+
+import java.net.URI
+import java.util.TimeZone
+
+/**
+ * Unit coverage for the pure helper methods in [[HoodieSqlCommonUtils]] that 
are otherwise
+ * only reached through heavier read/write code paths.
+ */
+class TestHoodieSqlCommonUtils extends AnyFunSuite with BeforeAndAfterAll {
+
+  // Instant formatting is timezone sensitive; pin the JVM default to UTC for 
the suite and
+  // restore it afterwards so the change does not leak into other suites in 
the same JVM.
+  private var originalTimeZone: TimeZone = _
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    originalTimeZone = TimeZone.getDefault
+    TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
+  }
+
+  override protected def afterAll(): Unit = {
+    TimeZone.setDefault(originalTimeZone)
+    super.afterAll()
+  }
+
+  private def partitionedTable(partitionCols: Seq[String]): CatalogTable = {
+    val fields = StructField("id", IntegerType) +: 
partitionCols.map(StructField(_, StringType))
+    CatalogTable(
+      identifier = TableIdentifier("t", Some("default")),
+      tableType = CatalogTableType.MANAGED,
+      storage = CatalogStorageFormat.empty,
+      schema = StructType(fields),
+      provider = Some("hudi"),
+      partitionColumnNames = partitionCols)
+  }
+
+  private val nonPartitionedTable: CatalogTable = CatalogTable(
+    identifier = TableIdentifier("t0", Some("default")),
+    tableType = CatalogTableType.MANAGED,
+    storage = CatalogStorageFormat.empty,
+    schema = StructType(Seq(StructField("id", IntegerType))),
+    provider = Some("hudi"))
+
+  test("formatQueryInstant normalizes supported time formats") {

Review Comment:
   Both tests, the `TimeZone` pin and `BeforeAndAfterAll` are dropped in 
39aaae78dff6.



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/common/TestHoodieSqlCommonUtils.scala:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.spark.sql.hudi.common
+
+import org.apache.hudi.common.table.read.IncrementalQueryAnalyzer
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.spark.sql.catalyst.TableIdentifier
+import org.apache.spark.sql.catalyst.analysis.caseInsensitiveResolution
+import org.apache.spark.sql.catalyst.catalog.{CatalogStorageFormat, 
CatalogTable, CatalogTableType}
+import org.apache.spark.sql.catalyst.expressions.AttributeReference
+import org.apache.spark.sql.hudi.HoodieSqlCommonUtils
+import org.apache.spark.sql.hudi.command.exception.HoodieAnalysisException
+import org.apache.spark.sql.types.{IntegerType, StringType, StructField, 
StructType}
+import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertTrue}
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.funsuite.AnyFunSuite
+
+import java.net.URI
+import java.util.TimeZone
+
+/**
+ * Unit coverage for the pure helper methods in [[HoodieSqlCommonUtils]] that 
are otherwise
+ * only reached through heavier read/write code paths.
+ */
+class TestHoodieSqlCommonUtils extends AnyFunSuite with BeforeAndAfterAll {
+
+  // Instant formatting is timezone sensitive; pin the JVM default to UTC for 
the suite and
+  // restore it afterwards so the change does not leak into other suites in 
the same JVM.
+  private var originalTimeZone: TimeZone = _
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    originalTimeZone = TimeZone.getDefault
+    TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
+  }
+
+  override protected def afterAll(): Unit = {
+    TimeZone.setDefault(originalTimeZone)
+    super.afterAll()
+  }
+
+  private def partitionedTable(partitionCols: Seq[String]): CatalogTable = {
+    val fields = StructField("id", IntegerType) +: 
partitionCols.map(StructField(_, StringType))
+    CatalogTable(
+      identifier = TableIdentifier("t", Some("default")),
+      tableType = CatalogTableType.MANAGED,
+      storage = CatalogStorageFormat.empty,
+      schema = StructType(fields),
+      provider = Some("hudi"),
+      partitionColumnNames = partitionCols)
+  }
+
+  private val nonPartitionedTable: CatalogTable = CatalogTable(
+    identifier = TableIdentifier("t0", Some("default")),
+    tableType = CatalogTableType.MANAGED,
+    storage = CatalogStorageFormat.empty,
+    schema = StructType(Seq(StructField("id", IntegerType))),
+    provider = Some("hudi"))
+
+  test("formatQueryInstant normalizes supported time formats") {
+    
assertTrue(HoodieSqlCommonUtils.formatQueryInstant("2021-04-01").startsWith("20210401"))
+    assertTrue(HoodieSqlCommonUtils.formatQueryInstant("2021-04-01 
12:30:45").startsWith("20210401123045"))
+    
assertTrue(HoodieSqlCommonUtils.formatQueryInstant("2021-04-01T12:30:45").startsWith("20210401123045"))
+    // 10-digit epoch seconds (2021-01-01T00:00:00Z) and 13-digit epoch millis.
+    
assertTrue(HoodieSqlCommonUtils.formatQueryInstant("1609459200").startsWith("20210101"))
+    
assertTrue(HoodieSqlCommonUtils.formatQueryInstant("1609459200000").startsWith("20210101"))
+    intercept[IllegalArgumentException] {
+      HoodieSqlCommonUtils.formatQueryInstant("abc")
+    }
+  }
+
+  test("formatIncrementalInstant passes sentinels through and normalizes real 
instants") {
+    assertEquals(IncrementalQueryAnalyzer.START_COMMIT_EARLIEST,
+      
HoodieSqlCommonUtils.formatIncrementalInstant(IncrementalQueryAnalyzer.START_COMMIT_EARLIEST))
+    assertEquals("000", HoodieSqlCommonUtils.formatIncrementalInstant("000"))
+    // A short, zero-prefixed numeric value is treated as a legacy instant and 
passed through.
+    assertEquals("0000001", 
HoodieSqlCommonUtils.formatIncrementalInstant("0000001"))
+    
assertTrue(HoodieSqlCommonUtils.formatIncrementalInstant("2021-04-01").startsWith("20210401"))
+  }
+
+  test("partition style detectors classify partition paths") {
+    val t = partitionedTable(Seq("dt"))
+
+    
assertTrue(HoodieSqlCommonUtils.isHiveStyledPartitioning(Seq("dt=2021-04-01"), 
t))
+    
assertFalse(HoodieSqlCommonUtils.isHiveStyledPartitioning(Seq("2021-04-01"), t))
+    assertTrue(HoodieSqlCommonUtils.isHiveStyledPartitioning(Seq("anything"), 
nonPartitionedTable))
+
+    assertTrue(HoodieSqlCommonUtils.isUrlEncodeEnabled(Seq("dt=2021-04-01"), 
t))

Review Comment:
   Added the two-column `isHiveStyledPartitioning`/`isUrlEncodeEnabled` cases 
and dropped the three `isSlashSeparatedDatePartitioning` assertions in 
39aaae78dff6.



-- 
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]

Reply via email to