Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public enum TransformFunctionType {
IN("in"),
NOT_IN("not_in"),

IS_TRUE("is_true"),
IS_NOT_TRUE("is_not_true"),
IS_FALSE("is_false"),
IS_NOT_FALSE("is_not_false"),
IS_NULL("is_null"),
IS_NOT_NULL("is_not_null"),
COALESCE("coalesce"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class FunctionDefinitionRegistryTest {
// functions we are not supporting post transform anyway
"valuein", "mapvalue", "inidset", "lookup", "groovy", "scalar", "geotoh3", "not_in", "timeconvert",
// functions not needed for register b/c they are in std sql table or they will not be composed directly.
"in", "and", "or", "range", "extract"
"in", "and", "or", "range", "extract", "is_true", "is_not_true", "is_false", "is_not_false"
);

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* 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.operator.transform.function;

import com.google.common.base.Preconditions;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.pinot.core.operator.ColumnContext;
import org.apache.pinot.core.operator.blocks.ValueBlock;
import org.apache.pinot.core.operator.transform.TransformResultMetadata;
import org.roaringbitmap.RoaringBitmap;


public abstract class BaseBooleanAssertionTransformFunction extends BaseTransformFunction {
private TransformFunction _transformFunction;

@Override
public void init(List<TransformFunction> arguments, Map<String, ColumnContext> columnContextMap) {
Preconditions.checkArgument(arguments.size() == 1, "Exact 1 argument is required for " + getName());
_transformFunction = arguments.get(0);
}

@Override
public TransformResultMetadata getResultMetadata() {
return BOOLEAN_SV_NO_DICTIONARY_METADATA;
}

@Override
public int[] transformToIntValuesSV(ValueBlock valueBlock) {
int length = valueBlock.getNumDocs();
initIntValuesSV(length);
Arrays.fill(_intValuesSV, 0);
int[] intValuesSV = _transformFunction.transformToIntValuesSV(valueBlock);
RoaringBitmap nullBitmap = null;
if (_nullHandlingEnabled) {
nullBitmap = _transformFunction.getNullBitmap(valueBlock);
}
if (nullBitmap != null) {
for (int docId = 0; docId < length; docId++) {
if (nullBitmap.contains(docId)) {
if (returnsTrueWhenValueIsNull()) {
_intValuesSV[docId] = 1;
}
} else if (valueEvaluatesToTrue(intValuesSV[docId])) {
_intValuesSV[docId] = 1;
}
}
} else {
for (int docId = 0; docId < length; docId++) {
if (valueEvaluatesToTrue(intValuesSV[docId])) {
_intValuesSV[docId] = 1;
}
}
}
return _intValuesSV;
}

protected abstract boolean returnsTrueWhenValueIsNull();

protected abstract boolean valueEvaluatesToTrue(int value);

@Override
public RoaringBitmap getNullBitmap(ValueBlock valueBlock) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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.operator.transform.function;

import java.util.List;
import java.util.Map;
import org.apache.pinot.common.function.TransformFunctionType;
import org.apache.pinot.core.operator.ColumnContext;


public class IsFalseTransformFunction extends BaseBooleanAssertionTransformFunction {

@Override
public String getName() {
return TransformFunctionType.IS_FALSE.getName();
}

@Override
public void init(List<TransformFunction> arguments, Map<String, ColumnContext> columnContextMap) {
super.init(arguments, columnContextMap);
}

@Override
protected boolean returnsTrueWhenValueIsNull() {
return false;
}

@Override
protected boolean valueEvaluatesToTrue(int value) {
return value == 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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.operator.transform.function;

import java.util.List;
import java.util.Map;
import org.apache.pinot.common.function.TransformFunctionType;
import org.apache.pinot.core.operator.ColumnContext;


public class IsNotFalseTransformFunction extends BaseBooleanAssertionTransformFunction {

@Override
public String getName() {
return TransformFunctionType.IS_NOT_TRUE.getName();
}

@Override
public void init(List<TransformFunction> arguments, Map<String, ColumnContext> columnContextMap) {
super.init(arguments, columnContextMap);
}

@Override
protected boolean returnsTrueWhenValueIsNull() {
return true;
}

@Override
protected boolean valueEvaluatesToTrue(int value) {
return value != 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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.operator.transform.function;

import java.util.List;
import java.util.Map;
import org.apache.pinot.common.function.TransformFunctionType;
import org.apache.pinot.core.operator.ColumnContext;


public class IsNotTrueTransformFunction extends BaseBooleanAssertionTransformFunction {

@Override
public String getName() {
return TransformFunctionType.IS_NOT_TRUE.getName();
}

@Override
public void init(List<TransformFunction> arguments, Map<String, ColumnContext> columnContextMap) {
super.init(arguments, columnContextMap);
}

@Override
protected boolean returnsTrueWhenValueIsNull() {
return true;
}

@Override
protected boolean valueEvaluatesToTrue(int value) {
return value == 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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.operator.transform.function;

import java.util.List;
import java.util.Map;
import org.apache.pinot.common.function.TransformFunctionType;
import org.apache.pinot.core.operator.ColumnContext;


public class IsTrueTransformFunction extends BaseBooleanAssertionTransformFunction {

@Override
public String getName() {
return TransformFunctionType.IS_TRUE.getName();
}

@Override
public void init(List<TransformFunction> arguments, Map<String, ColumnContext> columnContextMap) {
super.init(arguments, columnContextMap);
}

@Override
protected boolean returnsTrueWhenValueIsNull() {
return false;
}

@Override
protected boolean valueEvaluatesToTrue(int value) {
return value != 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ private static Map<String, Class<? extends TransformFunction>> createRegistry()
typeToImplementation.put(TransformFunctionType.GREATEST, GreatestTransformFunction.class);

// null handling
typeToImplementation.put(TransformFunctionType.IS_TRUE, IsTrueTransformFunction.class);
typeToImplementation.put(TransformFunctionType.IS_NOT_TRUE, IsNotTrueTransformFunction.class);
typeToImplementation.put(TransformFunctionType.IS_FALSE, IsFalseTransformFunction.class);
typeToImplementation.put(TransformFunctionType.IS_NOT_FALSE, IsNotFalseTransformFunction.class);
typeToImplementation.put(TransformFunctionType.IS_NULL, IsNullTransformFunction.class);
typeToImplementation.put(TransformFunctionType.IS_NOT_NULL, IsNotNullTransformFunction.class);
typeToImplementation.put(TransformFunctionType.COALESCE, CoalesceTransformFunction.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,40 @@ private void insertRowWithTwoColumns(Object column1Value, Object column2Value) {
_rows.add(row);
}

@DataProvider(name = "BooleanAssertionFunctions")
public static Object[][] getBooleanAssertionFunctionsParameters() {
return new Object[][]{
{"istrue", true, true},
{"istrue", false, false},
{"istrue", null, false},
{"isnottrue", true, false},
{"isnottrue", false, true},
{"isnottrue", null, true},
{"isfalse", true, false},
{"isfalse", false, true},
{"isfalse", null, false},
{"isnotfalse", true, true},
{"isnotfalse", false, false},
{"isnotfalse", null, true}
};
}

@Test(dataProvider = "BooleanAssertionFunctions")
public void testBooleanAssertionFunctions(String function, Boolean data, Boolean queryResult)
throws Exception {
initializeRows();
insertRow(data);
TableConfig tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName(RAW_TABLE_NAME).build();
Schema schema = new Schema.SchemaBuilder().addSingleValueDimension(COLUMN1, FieldSpec.DataType.BOOLEAN).build();
setUpSegments(tableConfig, schema);
String query = String.format("SELECT %s(%s) FROM testTable LIMIT 1", function, COLUMN1);

BrokerResponseNative brokerResponse = getBrokerResponse(query, QUERY_OPTIONS);

ResultTable resultTable = brokerResponse.getResultTable();
assertEquals(resultTable.getRows().get(0)[0], queryResult);
}

@Test
public void testGroupByOrderByNullsLastUsingOrdinal()
throws Exception {
Expand Down