kishoreg commented on a change in pull request #5238: Evaluate schema transform expressions during ingestion URL: https://github.com/apache/incubator-pinot/pull/5238#discussion_r407235605
########## File path: pinot-core/src/test/java/org/apache/pinot/core/data/recordtransformer/ExpressionTransformerTest.java ########## @@ -0,0 +1,129 @@ +/** + * 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.core.data.recordtransformer; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.data.readers.AbstractRecordExtractorTest; +import org.apache.pinot.spi.data.readers.GenericRow; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +/** + * Tests the evaluation of transform expressions by the ExpressionTransformer + */ +public class ExpressionTransformerTest { + + private Schema _pinotSchema; + + @BeforeClass + public void setup() + throws IOException { + URL resource = + AbstractRecordExtractorTest.class.getClassLoader().getResource("data/expression_transformer/groovy_expression_transformer.json"); + File schemaFile = new File(resource.getFile()); + _pinotSchema = Schema.fromFile(schemaFile); + } + + @Test + public void testGroovyExpressionTransformer() { + ExpressionTransformer expressionTransformer = new ExpressionTransformer(_pinotSchema); + DataTypeTransformer dataTypeTransformer = new DataTypeTransformer(_pinotSchema); + + // test functions from schema + GenericRow genericRow = new GenericRow(); + genericRow.putValue("userID", 1L); + genericRow.putValue("firstName", "John"); + genericRow.putValue("lastName", "Denver"); + genericRow.putValue("bids", Arrays.asList(10, 20)); + HashMap<String, String> map1 = new HashMap<>(); // keys in Map from avro are always in STRING + map1.put("30", "foo"); + map1.put("200", "bar"); + genericRow.putValue("map1", map1); + HashMap<String, Integer> map2 = new HashMap<>(); + map2.put("k1", 10); + map2.put("k2", 20); + genericRow.putValue("map2", map2); + genericRow.putValue("cost", 1000.0); + genericRow.putValue("timestamp", 1574000000000L); + + // expression transformer + expressionTransformer.transform(genericRow); + + // extract userId + Assert.assertEquals(genericRow.getValue("userId"), 1L); Review comment: userId --> user_id we might make columns case insensitive at some point and this test case should still be valid. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
