You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2021/05/27 15:24:49 UTC

[GitHub] [hudi] wangxianghu opened a new pull request #3004: [HUDI-1940] Add SqlQueryBasedTransformer unit test

wangxianghu opened a new pull request #3004:
URL: https://github.com/apache/hudi/pull/3004


   ## *Tips*
   - *Thank you very much for contributing to Apache Hudi.*
   - *Please review https://hudi.apache.org/contributing.html before opening a pull request.*
   
   ## What is the purpose of the pull request
   
   *(For example: This pull request adds quick-start document.)*
   
   ## Brief change log
   
   *(for example:)*
     - *Modify AnnotationLocation checkstyle rule in checkstyle.xml*
   
   ## Verify this pull request
   
   *(Please pick either of the following options)*
   
   This pull request is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This pull request is already covered by existing tests, such as *(please describe tests)*.
   
   (or)
   
   This change added tests and can be verified as follows:
   
   *(example:)*
   
     - *Added integration tests for end-to-end.*
     - *Added HoodieClientWriteTest to verify the change.*
     - *Manually verified the change by running a job locally.*
   
   ## Committer checklist
   
    - [ ] Has a corresponding JIRA in PR title & commit
    
    - [ ] Commit message is descriptive of the change
    
    - [ ] CI is green
   
    - [ ] Necessary doc changes done or have another open PR
          
    - [ ] For large changes, please consider breaking it into sub-tasks under an umbrella JIRA.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] leesf merged pull request #3004: [HUDI-1940] Add SqlQueryBasedTransformer unit test

Posted by GitBox <gi...@apache.org>.
leesf merged pull request #3004:
URL: https://github.com/apache/hudi/pull/3004


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] wangxianghu commented on a change in pull request #3004: [HUDI-1940] Add SqlQueryBasedTransformer unit test

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #3004:
URL: https://github.com/apache/hudi/pull/3004#discussion_r641543572



##########
File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/transform/TestSqlQueryBasedTransformer.java
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.hudi.utilities.transform;
+
+import org.apache.hudi.common.config.TypedProperties;
+
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.SparkSession;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class TestSqlQueryBasedTransformer {
+
+  @Test
+  public void testSqlQuery() {
+
+    SparkSession spark = SparkSession
+        .builder()
+        .master("local[2]")
+        .appName(TestSqlQueryBasedTransformer.class.getName())
+        .getOrCreate();
+
+    JavaSparkContext jsc = JavaSparkContext.fromSparkContext(spark.sparkContext());
+
+    // prepare test data
+    String testData = "{\n"
+        + "  \"ts\": 1622126968000,\n"
+        + "  \"uuid\": \"c978e157-72ee-4819-8f04-8e46e1bb357a\",\n"
+        + "  \"rider\": \"rider-213\",\n"
+        + "  \"driver\": \"driver-213\",\n"
+        + "  \"begin_lat\": 0.4726905879569653,\n"
+        + "  \"begin_lon\": 0.46157858450465483,\n"
+        + "  \"end_lat\": 0.754803407008858,\n"
+        + "  \"end_lon\": 0.9671159942018241,\n"
+        + "  \"fare\": 34.158284716382845,\n"
+        + "  \"partitionpath\": \"americas/brazil/sao_paulo\"\n"
+        + "}";
+
+    JavaRDD<String> testRdd = jsc.parallelize(Collections.singletonList(testData), 2);
+    Dataset<Row> ds = spark.read().json(testRdd);
+
+    // create a new column dt, whose value is transformed from ts, format is yyyyMMdd
+    String transSql = "select\n"
+        + "\tuuid,\n"
+        + "\tbegin_lat,\n"
+        + "\tbegin_lon,\n"
+        + "\tdriver,\n"
+        + "\tend_lat,\n"
+        + "\tend_lon,\n"
+        + "\tfare,\n"
+        + "\tpartitionpath,\n"
+        + "\trider,\n"
+        + "\tts,\n"
+        + "\tFROM_UNIXTIME(ts / 1000, 'yyyyMMdd') as dt\n"
+        + "from\n"
+        + "\t<SRC>";
+    TypedProperties props = new TypedProperties();
+    props.put("hoodie.deltastreamer.transformer.sql", transSql);
+
+    // transform
+    SqlQueryBasedTransformer transformer = new SqlQueryBasedTransformer();
+    Dataset<Row> result = transformer.apply(jsc, spark, ds, props);
+
+    // check result
+    assertEquals(result.columns().length, 11);

Review comment:
       > pls use assertEquals(expected, result.columns), so please change to `assertEquals(11, result.columns().length)`
   
   @leesf thanks, done




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] leesf commented on a change in pull request #3004: [HUDI-1940] Add SqlQueryBasedTransformer unit test

Posted by GitBox <gi...@apache.org>.
leesf commented on a change in pull request #3004:
URL: https://github.com/apache/hudi/pull/3004#discussion_r641474949



##########
File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/transform/TestSqlQueryBasedTransformer.java
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.hudi.utilities.transform;
+
+import org.apache.hudi.common.config.TypedProperties;
+
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.SparkSession;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class TestSqlQueryBasedTransformer {
+
+  @Test
+  public void testSqlQuery() {
+
+    SparkSession spark = SparkSession
+        .builder()
+        .master("local[2]")
+        .appName(TestSqlQueryBasedTransformer.class.getName())
+        .getOrCreate();
+
+    JavaSparkContext jsc = JavaSparkContext.fromSparkContext(spark.sparkContext());
+
+    // prepare test data
+    String testData = "{\n"
+        + "  \"ts\": 1622126968000,\n"
+        + "  \"uuid\": \"c978e157-72ee-4819-8f04-8e46e1bb357a\",\n"
+        + "  \"rider\": \"rider-213\",\n"
+        + "  \"driver\": \"driver-213\",\n"
+        + "  \"begin_lat\": 0.4726905879569653,\n"
+        + "  \"begin_lon\": 0.46157858450465483,\n"
+        + "  \"end_lat\": 0.754803407008858,\n"
+        + "  \"end_lon\": 0.9671159942018241,\n"
+        + "  \"fare\": 34.158284716382845,\n"
+        + "  \"partitionpath\": \"americas/brazil/sao_paulo\"\n"
+        + "}";
+
+    JavaRDD<String> testRdd = jsc.parallelize(Collections.singletonList(testData), 2);
+    Dataset<Row> ds = spark.read().json(testRdd);
+
+    // create a new column dt, whose value is transformed from ts, format is yyyyMMdd
+    String transSql = "select\n"
+        + "\tuuid,\n"
+        + "\tbegin_lat,\n"
+        + "\tbegin_lon,\n"
+        + "\tdriver,\n"
+        + "\tend_lat,\n"
+        + "\tend_lon,\n"
+        + "\tfare,\n"
+        + "\tpartitionpath,\n"
+        + "\trider,\n"
+        + "\tts,\n"
+        + "\tFROM_UNIXTIME(ts / 1000, 'yyyyMMdd') as dt\n"
+        + "from\n"
+        + "\t<SRC>";
+    TypedProperties props = new TypedProperties();
+    props.put("hoodie.deltastreamer.transformer.sql", transSql);
+
+    // transform
+    SqlQueryBasedTransformer transformer = new SqlQueryBasedTransformer();
+    Dataset<Row> result = transformer.apply(jsc, spark, ds, props);
+
+    // check result
+    assertEquals(result.columns().length, 11);

Review comment:
       pls use assertEquals(expected, result.columns), so please change to `assertEquals(11, result.columns().length)`




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org