use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class RowLevelRangeFilterResolverImpl method getDirectSurrogateValues.
private List<Integer> getDirectSurrogateValues(ColumnExpression columnExpression) throws FilterUnsupportedException {
List<ExpressionResult> listOfExpressionResults = new ArrayList<ExpressionResult>(20);
DirectDictionaryGenerator directDictionaryGenerator = DirectDictionaryKeyGeneratorFactory.getDirectDictionaryGenerator(columnExpression.getDimension().getDataType());
if (this.getFilterExpression() instanceof BinaryConditionalExpression) {
listOfExpressionResults = ((BinaryConditionalExpression) this.getFilterExpression()).getLiterals();
}
List<Integer> filterValuesList = new ArrayList<Integer>(20);
try {
// system can display inconsistent result.
for (ExpressionResult result : listOfExpressionResults) {
filterValuesList.add(directDictionaryGenerator.generateDirectSurrogateKey(result.getString(), CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT));
}
} catch (FilterIllegalMemberException e) {
throw new FilterUnsupportedException(e);
}
return filterValuesList;
}
use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class RangeDirectDictionaryVisitor method populateFilterResolvedInfo.
/**
* This Visitor method is used to populate the visitableObj with direct dictionary filter details
* where the filters values will be resolve using dictionary cache.
*
* @param visitableObj
* @param metadata
* @throws FilterUnsupportedException,if exception occurs while evaluating
* filter models.
* @throws FilterUnsupportedException
*/
public void populateFilterResolvedInfo(DimColumnResolvedFilterInfo visitableObj, FilterResolverMetadata metadata) throws FilterUnsupportedException {
DimColumnFilterInfo resolvedFilterObject = null;
List<ExpressionResult> listOfExpressionResults = new ArrayList<ExpressionResult>(20);
List<String> evaluateResultListFinal = new ArrayList<String>();
try {
listOfExpressionResults = ((RangeExpression) metadata.getExpression()).getLiterals();
for (ExpressionResult result : listOfExpressionResults) {
if (result.getString() == null) {
evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
continue;
}
evaluateResultListFinal.add(result.getString());
}
} catch (FilterIllegalMemberException e) {
throw new FilterUnsupportedException(e);
}
resolvedFilterObject = getDirectDictionaryValKeyMemberForFilter(metadata.getColumnExpression(), evaluateResultListFinal, metadata.isIncludeFilter(), metadata.getColumnExpression().getDimension().getDataType());
if (!metadata.isIncludeFilter() && null != resolvedFilterObject && !resolvedFilterObject.getFilterList().contains(CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY)) {
// Adding default surrogate key of null member inorder to not display the same while
// displaying the report as per hive compatibility.
resolvedFilterObject.getFilterList().add(CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY);
Collections.sort(resolvedFilterObject.getFilterList());
}
visitableObj.setFilterValues(resolvedFilterObject);
}
use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class RangeNoDictionaryTypeVisitor method populateFilterResolvedInfo.
/**
* Visitor Method will update the filter related details in visitableObj, For no dictionary
* type columns the filter members will resolved directly, no need to look up in dictionary
* since it will not be part of dictionary, directly the actual data can be converted as
* byte[] and can be set. this type of encoding is effective when the particular column
* is having very high cardinality.
*
* @param visitableObj
* @param metadata
* @throws FilterUnsupportedException,if exception occurs while evaluating
* filter models.
*/
public void populateFilterResolvedInfo(DimColumnResolvedFilterInfo visitableObj, FilterResolverMetadata metadata) throws FilterUnsupportedException {
DimColumnFilterInfo resolvedFilterObject = null;
List<ExpressionResult> listOfExpressionResults = new ArrayList<ExpressionResult>(20);
List<String> evaluateResultListFinal = new ArrayList<String>();
try {
// Add The Range Filter Values.
if (metadata.getExpression() instanceof RangeExpression) {
listOfExpressionResults = ((RangeExpression) metadata.getExpression()).getLiterals();
}
for (ExpressionResult result : listOfExpressionResults) {
if (result.getString() == null) {
evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
continue;
}
evaluateResultListFinal.add(result.getString());
}
// evaluateResultListFinal.add(metadata.getExpression().evaluate().getListAsString());
if (!metadata.isIncludeFilter() && !evaluateResultListFinal.contains(CarbonCommonConstants.MEMBER_DEFAULT_VAL)) {
evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
}
} catch (FilterIllegalMemberException e) {
throw new FilterUnsupportedException(e);
}
resolvedFilterObject = FilterUtil.getNoDictionaryValKeyMemberForFilter(evaluateResultListFinal, metadata.isIncludeFilter(), metadata.getColumnExpression().getDataType());
visitableObj.setFilterValues(resolvedFilterObject);
}
use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class LessThanEqualToExpressionUnitTest method testEvaluateForLessThanEqualToExpressionWithShortDataType.
@Test
public void testEvaluateForLessThanEqualToExpressionWithShortDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
right.setColIndex(0);
ColumnExpression left = new ColumnExpression("id", DataType.SHORT);
left.setColIndex(1);
lessThanEqualToExpression = new LessThanEqualToExpression(left, right);
RowImpl value = new RowImpl();
Short[] row = { 1550 };
Short[] row1 = { 3365 };
Object[] objectRow = { row, row1 };
value.setValues(objectRow);
new MockUp<ExpressionResult>() {
Boolean returnMockFlag = true;
@Mock
public Short getShort() {
if (returnMockFlag) {
returnMockFlag = false;
return 1550;
} else {
return 3365;
}
}
};
ExpressionResult result = lessThanEqualToExpression.evaluate(value);
assertTrue(result.getBoolean());
}
use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class LessThanEqualToExpressionUnitTest method testEvaluateForLessThanEqualToExpressionWithDecimalDataType.
@Test
public void testEvaluateForLessThanEqualToExpressionWithDecimalDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
ColumnExpression right = new ColumnExpression("right_contact", DataType.DECIMAL);
right.setColIndex(0);
ColumnExpression left = new ColumnExpression("left_contact", DataType.DECIMAL);
left.setColIndex(1);
lessThanEqualToExpression = new LessThanEqualToExpression(left, right);
RowImpl value = new RowImpl();
Decimal[] row = new Decimal[] { Decimal.apply(46851.2) };
Decimal[] row1 = new Decimal[] { Decimal.apply(45821.02) };
Object[] objectRow = { row1, row };
value.setValues(objectRow);
new MockUp<ExpressionResult>() {
Boolean returnMockFlag = true;
@Mock
public BigDecimal getDecimal() {
if (returnMockFlag) {
returnMockFlag = false;
return new BigDecimal(45821.02);
} else {
return new BigDecimal(46851.2);
}
}
};
ExpressionResult result = lessThanEqualToExpression.evaluate(value);
assertTrue(result.getBoolean());
}
Aggregations