Jackie-Jiang commented on code in PR #8792:
URL: https://github.com/apache/pinot/pull/8792#discussion_r883872686


##########
pinot-spi/src/main/java/org/apache/pinot/spi/data/DateTimeFormatPatternSpec.java:
##########
@@ -81,6 +82,23 @@ public DateTimeFormatter getDateTimeFormatter() {
     return _dateTimeFormatter;
   }
 
+  /**
+   * Validates the sdf pattern
+   */
+  public static void validateFormat(@Nonnull String sdfPatternWithTz) {

Review Comment:
   Let's extract a method to return the `DateTimeFormatter` from 
`sdfPatternWithTz`, which can be shared in both the constructor and the 
validation



##########
pinot-spi/src/test/java/org/apache/pinot/spi/data/DateTimeFormatSpecTest.java:
##########
@@ -0,0 +1,41 @@
+/**
+ * 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.pinot.spi.data;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.*;
+
+
+public class DateTimeFormatSpecTest {
+
+  @Test
+  public void testValidateFormat() {
+    DateTimeFormatSpec.validateFormat("1:DAYS:EPOCH");
+    DateTimeFormatSpec.validateFormat("1:DAYS:TIMESTAMP");
+    DateTimeFormatSpec.validateFormat("1:DAYS:SIMPLE_DATE_FORMAT:yyyyMMdd");
+    Assert.assertThrows(() -> DateTimeFormatSpec.validateFormat("1:DAY"));

Review Comment:
   (minor) Since we already static import the `assertThrows()`, no need to have 
`Assert.`
   ```suggestion
       assertThrows(() -> DateTimeFormatSpec.validateFormat("1:DAY"));
   ```



##########
pinot-spi/src/main/java/org/apache/pinot/spi/data/DateTimeFormatPatternSpec.java:
##########
@@ -81,6 +82,23 @@ public DateTimeFormatter getDateTimeFormatter() {
     return _dateTimeFormatter;
   }
 
+  /**
+   * Validates the sdf pattern
+   */
+  public static void validateFormat(@Nonnull String sdfPatternWithTz) {

Review Comment:
   (convention) Let's not use `Nonnull` annotation because it is very easy to 
mix it with `Nullable`. By default we treat all fields as non-null, and only 
annotate the ones that might be null



##########
pinot-spi/src/test/java/org/apache/pinot/spi/data/DateTimeFormatSpecTest.java:
##########
@@ -0,0 +1,41 @@
+/**
+ * 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.pinot.spi.data;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.*;

Review Comment:
   (code style) If you auto-reformat, it should change this to
   ```suggestion
   import static org.testng.Assert.assertThrows;
   ```



##########
pinot-spi/src/test/java/org/apache/pinot/spi/data/DateTimeFormatPatternSpecTest.java:
##########
@@ -0,0 +1,42 @@
+/**
+ * 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.pinot.spi.data;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class DateTimeFormatPatternSpecTest {
+
+  @Test
+  public void testValidateFormat() {
+    DateTimeFormatPatternSpec.validateFormat("yyyy-MM-dd");
+    DateTimeFormatPatternSpec.validateFormat("yyyyMMdd tz(CST)");
+    DateTimeFormatPatternSpec.validateFormat("yyyyMMdd HH tz(GMT+0700)");
+    DateTimeFormatPatternSpec.validateFormat("yyyyMMddHH tz(America/Chicago)");
+
+    // Unknown tz is treated as UTC
+    DateTimeFormatPatternSpec.validateFormat("yyyyMMdd tz(CSEMT)");
+    DateTimeFormatPatternSpec.validateFormat("yyyyMMdd tz(GMT+5000)");
+    DateTimeFormatPatternSpec.validateFormat("yyyyMMddHH tz(HAHA/Chicago)");
+
+    // invalid chars will throw
+    Assert.assertThrows(() -> 
DateTimeFormatPatternSpec.validateFormat("yyyc-MM-dd"));

Review Comment:
   (minor) For tests, we may static import `Assert.assertThrows`



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to