use of org.apache.carbondata.core.scan.expression.conditional.EqualToExpression in project carbondata by apache.
the class CarbonInputMapperTest method testInputFormatMapperReadAllRowsAndFewColumnsWithFilter.
@Test
public void testInputFormatMapperReadAllRowsAndFewColumnsWithFilter() throws Exception {
try {
String outPath = "target/output3";
CarbonProjection carbonProjection = new CarbonProjection();
carbonProjection.addColumn("ID");
carbonProjection.addColumn("country");
carbonProjection.addColumn("salary");
Expression expression = new EqualToExpression(new ColumnExpression("country", DataType.STRING), new LiteralExpression("france", DataType.STRING));
runJob(outPath, carbonProjection, expression);
Assert.assertEquals("Count lines are not matching", 101, countTheLines(outPath));
Assert.assertEquals("Column count are not matching", 3, countTheColumns(outPath));
} catch (Exception e) {
Assert.assertTrue("failed", false);
}
}
use of org.apache.carbondata.core.scan.expression.conditional.EqualToExpression in project carbondata by apache.
the class NoDictionaryTypeVisitor 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<String> evaluateResultListFinal = null;
try {
// handling for is null case scenarios
if (metadata.getExpression() instanceof EqualToExpression) {
EqualToExpression expression = (EqualToExpression) metadata.getExpression();
if (expression.isNull) {
evaluateResultListFinal = new ArrayList<>(1);
evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
}
} else {
evaluateResultListFinal = metadata.getExpression().evaluate(null).getListAsString();
}
// displaying the report as per hive compatibility.
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.conditional.EqualToExpression in project carbondata by apache.
the class CarbonTableInputFormatTest method testInputFormatMapperReadAllRowsAndFewColumnsWithFilter.
@Test
public void testInputFormatMapperReadAllRowsAndFewColumnsWithFilter() throws Exception {
try {
String outPath = "target/output3";
CarbonProjection carbonProjection = new CarbonProjection();
carbonProjection.addColumn("ID");
carbonProjection.addColumn("country");
carbonProjection.addColumn("salary");
Expression expression = new EqualToExpression(new ColumnExpression("country", DataTypes.STRING), new LiteralExpression("france", DataTypes.STRING));
runJob(outPath, carbonProjection, expression);
Assert.assertEquals("Count lines are not matching", 101, countTheLines(outPath));
Assert.assertEquals("Column count are not matching", 3, countTheColumns(outPath));
} catch (Exception e) {
Assert.assertTrue("failed", false);
} finally {
StoreCreator.clearDataMaps();
}
}
use of org.apache.carbondata.core.scan.expression.conditional.EqualToExpression in project carbondata by apache.
the class CarbonTableInputFormatTest method testGetFilteredSplits.
@Test
public void testGetFilteredSplits() throws Exception {
CarbonTableInputFormat carbonInputFormat = new CarbonTableInputFormat();
JobConf jobConf = new JobConf(new Configuration());
Job job = Job.getInstance(jobConf);
job.getConfiguration().set("query.id", UUID.randomUUID().toString());
String tblPath = StoreCreator.getAbsoluteTableIdentifier().getTablePath();
FileInputFormat.addInputPath(job, new Path(tblPath));
CarbonTableInputFormat.setDatabaseName(job.getConfiguration(), StoreCreator.getAbsoluteTableIdentifier().getDatabaseName());
CarbonTableInputFormat.setTableName(job.getConfiguration(), StoreCreator.getAbsoluteTableIdentifier().getTableName());
Expression expression = new EqualToExpression(new ColumnExpression("country", DataTypes.STRING), new LiteralExpression("china", DataTypes.STRING));
CarbonTableInputFormat.setFilterPredicates(job.getConfiguration(), expression);
List splits = carbonInputFormat.getSplits(job);
Assert.assertTrue(splits != null);
Assert.assertTrue(!splits.isEmpty());
}
use of org.apache.carbondata.core.scan.expression.conditional.EqualToExpression in project carbondata by apache.
the class ObjectSerializationUtilTest method testConvertObjectToString.
@Test
public void testConvertObjectToString() throws Exception {
Expression expression = new EqualToExpression(new ColumnExpression("c1", DataTypes.STRING), new LiteralExpression("a", DataTypes.STRING));
String string = ObjectSerializationUtil.convertObjectToString(expression);
Assert.assertTrue(string != null);
}
Aggregations