-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Support conjugates for scalar functions, add more scalar functions #8582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Jackie-Jiang
merged 15 commits into
apache:master
from
saurabhd336:conjugationQueryOperators
May 4, 2022
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
22844e5
Add conjugation function type
6d2c2e2
Lint
9f20103
Fix tests
ede82c5
Lint
e2b907e
Refactor
ee851e7
Add more functions
941d976
Lint
07c36bc
Fix tests
e374ef9
Get rid of switch case in online path
c875ffe
Review comments + more scalar functions
64ea5f6
Lint fix
f35a36c
Review comments
4f77c2e
Add more tests
5fb8d9a
Fix tests
58739e4
Review comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ComparisonFunctions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /** | ||
| * 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.common.function.scalar; | ||
|
|
||
| import org.apache.pinot.spi.annotations.ScalarFunction; | ||
|
|
||
| public class ComparisonFunctions { | ||
|
|
||
| private static final double DOUBLE_COMPARISON_TOLERANCE = 1e-7d; | ||
|
|
||
| private ComparisonFunctions() { | ||
| } | ||
|
|
||
| @ScalarFunction | ||
| public static boolean greaterThan(double a, double b) { | ||
| return a > b; | ||
| } | ||
|
|
||
| @ScalarFunction | ||
| public static boolean greaterThanOrEqual(double a, double b) { | ||
| return a >= b; | ||
| } | ||
|
|
||
| @ScalarFunction | ||
| public static boolean lessThan(double a, double b) { | ||
| return a < b; | ||
| } | ||
|
|
||
| @ScalarFunction | ||
| public static boolean lessThanOrEqual(double a, double b) { | ||
| return a <= b; | ||
| } | ||
|
|
||
| @ScalarFunction | ||
| public static boolean notEquals(double a, double b) { | ||
| return Math.abs(a - b) >= DOUBLE_COMPARISON_TOLERANCE; | ||
| } | ||
|
|
||
| @ScalarFunction | ||
| public static boolean equals(double a, double b) { | ||
| // To avoid approximation errors | ||
| return Math.abs(a - b) < DOUBLE_COMPARISON_TOLERANCE; | ||
| } | ||
|
|
||
| @ScalarFunction | ||
| public static boolean between(double val, double a, double b) { | ||
| return val > a && val < b; | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ObjectFunctions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /** | ||
| * 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.common.function.scalar; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import org.apache.pinot.spi.annotations.ScalarFunction; | ||
|
|
||
| public class ObjectFunctions { | ||
| private ObjectFunctions() { | ||
| } | ||
|
|
||
| @ScalarFunction(nullableParameters = true) | ||
| public static boolean isNull(@Nullable Object obj) { | ||
| return obj == null; | ||
| } | ||
|
|
||
| @ScalarFunction(nullableParameters = true) | ||
| public static boolean isNotNull(@Nullable Object obj) { | ||
| return !isNull(obj); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,7 @@ private static GenericRow getRecord() { | |
| record.putValue("svStringWithLengthLimit", "123"); | ||
| record.putValue("mvString1", new Object[]{"123", 123, 123L, 123f, 123.0}); | ||
| record.putValue("mvString2", new Object[]{123, 123L, 123f, 123.0, "123"}); | ||
| record.putValue("svNullString", null); | ||
| return record; | ||
| } | ||
|
|
||
|
|
@@ -178,6 +179,150 @@ record = transformer.transform(record); | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testScalarOps() { | ||
| TableConfig tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName("testTable").build(); | ||
|
|
||
| // expression true, filtered | ||
| GenericRow genericRow = getRecord(); | ||
| tableConfig.setIngestionConfig( | ||
| new IngestionConfig(null, null, | ||
| new FilterConfig("svInt = 123"), null, null)); | ||
|
||
| RecordTransformer transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
|
|
||
| // expression true, filtered | ||
| genericRow = getRecord(); | ||
| tableConfig.setIngestionConfig( | ||
| new IngestionConfig(null, null, | ||
| new FilterConfig("svDouble > 120"), null, null)); | ||
| transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
|
|
||
| // expression true, filtered | ||
| genericRow = getRecord(); | ||
| tableConfig.setIngestionConfig( | ||
| new IngestionConfig(null, null, | ||
| new FilterConfig("svDouble >= 123"), null, null)); | ||
| transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
|
|
||
| // expression true, filtered | ||
| genericRow = getRecord(); | ||
| tableConfig.setIngestionConfig( | ||
| new IngestionConfig(null, null, | ||
| new FilterConfig("svDouble < 200"), null, null)); | ||
| transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
|
|
||
| // expression true, filtered | ||
| genericRow = getRecord(); | ||
| tableConfig.setIngestionConfig( | ||
| new IngestionConfig(null, null, | ||
| new FilterConfig("svDouble <= 123"), null, null)); | ||
| transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
|
|
||
| // expression true, filtered | ||
| genericRow = getRecord(); | ||
| tableConfig.setIngestionConfig( | ||
| new IngestionConfig(null, null, | ||
| new FilterConfig("svLong != 125"), null, null)); | ||
| transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
|
|
||
| // expression true, filtered | ||
| genericRow = getRecord(); | ||
| tableConfig.setIngestionConfig( | ||
| new IngestionConfig(null, null, | ||
| new FilterConfig("svLong = 123"), null, null)); | ||
| transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
|
|
||
| // expression true, filtered | ||
| genericRow = getRecord(); | ||
| tableConfig.setIngestionConfig( | ||
| new IngestionConfig(null, null, new FilterConfig("between(svLong, 100, 125)"), null, null)); | ||
| transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
| } | ||
|
|
||
| private GenericRow getNullColumnsRecord() { | ||
| GenericRow record = new GenericRow(); | ||
| record.putValue("svNullString", null); | ||
| record.putValue("svInt", (byte) 123); | ||
|
|
||
| record.putValue("mvLong", Collections.singletonList(123f)); | ||
| record.putValue("mvNullFloat", null); | ||
| return record; | ||
| } | ||
|
|
||
| @Test | ||
| public void testObjectOps() { | ||
| TableConfig tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName("testTable").build(); | ||
|
|
||
| // expression true, filtered | ||
| GenericRow genericRow = getNullColumnsRecord(); | ||
| tableConfig.setIngestionConfig( | ||
| new IngestionConfig(null, null, new FilterConfig("svNullString is null"), null, null)); | ||
| RecordTransformer transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
|
|
||
| // expression true, filtered | ||
| genericRow = getNullColumnsRecord(); | ||
| tableConfig.setIngestionConfig(new IngestionConfig(null, null, new FilterConfig("svInt is not null"), null, null)); | ||
| transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
|
|
||
| // expression true, filtered | ||
| genericRow = getNullColumnsRecord(); | ||
| tableConfig.setIngestionConfig(new IngestionConfig(null, null, new FilterConfig("mvLong is not null"), null, null)); | ||
| transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
|
|
||
| // expression true, filtered | ||
| genericRow = getNullColumnsRecord(); | ||
| tableConfig.setIngestionConfig( | ||
| new IngestionConfig(null, null, new FilterConfig("mvNullFloat is null"), null, null)); | ||
| transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLogicalScalarOps() { | ||
| TableConfig tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName("testTable").build(); | ||
|
|
||
| // expression true, filtered | ||
| GenericRow genericRow = getRecord(); | ||
| tableConfig.setIngestionConfig( | ||
| new IngestionConfig(null, null, | ||
| new FilterConfig("svInt = 123 AND svDouble <= 200"), null, null)); | ||
| RecordTransformer transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
|
|
||
| // expression true, filtered | ||
| genericRow = getRecord(); | ||
| tableConfig.setIngestionConfig( | ||
| new IngestionConfig(null, null, | ||
| new FilterConfig("svInt = 125 OR svLong <= 200"), null, null)); | ||
| transformer = new FilterTransformer(tableConfig); | ||
| transformer.transform(genericRow); | ||
| Assert.assertTrue(genericRow.getFieldToValueMap().containsKey(GenericRow.SKIP_RECORD_KEY)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNullValueTransformer() { | ||
| RecordTransformer transformer = new NullValueTransformer(TABLE_CONFIG, SCHEMA); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to make sure these work case-insensitive way (all other scalar functions do)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will work in a case insensitive way due to https://github.com/apache/pinot/blob/master/pinot-common/src/main/java/org/apache/pinot/common/request/context/FunctionContext.java#L42