use of org.apache.phoenix.hive.ql.index.IndexSearchCondition in project phoenix by apache.
the class PhoenixPredicateDecomposer method decomposePredicate.
public DecomposedPredicate decomposePredicate(ExprNodeDesc predicate) {
if (LOG.isDebugEnabled()) {
LOG.debug("predicate - " + predicate.toString());
}
IndexPredicateAnalyzer analyzer = PredicateAnalyzerFactory.createPredicateAnalyzer(columnNameList, getFieldValidator());
DecomposedPredicate decomposed = new DecomposedPredicate();
List<IndexSearchCondition> conditions = new ArrayList<IndexSearchCondition>();
decomposed.residualPredicate = (ExprNodeGenericFuncDesc) analyzer.analyzePredicate(predicate, conditions);
if (!conditions.isEmpty()) {
decomposed.pushedPredicate = analyzer.translateSearchConditions(conditions);
try {
searchConditionList = conditions;
calledPPD = true;
} catch (Exception e) {
LOG.warn("Failed to decompose predicates", e);
return null;
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("decomposed predicate - residualPredicate: " + decomposed.residualPredicate + ", pushedPredicate: " + decomposed.pushedPredicate);
}
return decomposed;
}
use of org.apache.phoenix.hive.ql.index.IndexSearchCondition in project phoenix by apache.
the class PhoenixQueryBuilderTest method testBuildBetweenQueryWithDateColumns.
@Test
public void testBuildBetweenQueryWithDateColumns() throws IOException {
final String COLUMN_DATE = "Column_Date";
final String tableName = "TEST_TABLE";
final String expectedQueryPrefix = "select /*+ NO_CACHE */ \"" + COLUMN_DATE + "\" from " + tableName + " where ";
JobConf jobConf = new JobConf();
List<String> readColumnList = Lists.newArrayList(COLUMN_DATE);
List<IndexSearchCondition> searchConditions = Lists.newArrayList(mockedIndexSearchCondition("GenericUDFBetween", null, new Object[] { "1992-01-02", "1992-02-02" }, COLUMN_DATE, "date", false));
assertEquals(expectedQueryPrefix + "\"" + COLUMN_DATE + "\" between to_date('1992-01-02') and to_date('1992-02-02')", BUILDER.buildQuery(jobConf, TABLE_NAME, readColumnList, searchConditions));
searchConditions = Lists.newArrayList(mockedIndexSearchCondition("GenericUDFBetween", null, new Object[] { "1992-01-02", "1992-02-02" }, COLUMN_DATE, "date", true));
assertEquals(expectedQueryPrefix + "\"" + COLUMN_DATE + "\" not between to_date('1992-01-02') and to_date('1992-02-02')", BUILDER.buildQuery(jobConf, TABLE_NAME, readColumnList, searchConditions));
}
use of org.apache.phoenix.hive.ql.index.IndexSearchCondition in project phoenix by apache.
the class PhoenixQueryBuilderTest method testBuildQueryWithCharColumns.
@Test
public void testBuildQueryWithCharColumns() throws IOException {
final String COLUMN_CHAR = "Column_Char";
final String COLUMN_VARCHAR = "Column_VChar";
final String expectedQueryPrefix = "select /*+ NO_CACHE */ \"" + COLUMN_CHAR + "\",\"" + COLUMN_VARCHAR + "\" from TEST_TABLE where ";
JobConf jobConf = new JobConf();
List<String> readColumnList = Lists.newArrayList(COLUMN_CHAR, COLUMN_VARCHAR);
List<IndexSearchCondition> searchConditions = Lists.newArrayList(mockedIndexSearchCondition("GenericUDFOPEqual", "CHAR_VALUE", null, COLUMN_CHAR, "char(10)", false), mockedIndexSearchCondition("GenericUDFOPEqual", "CHAR_VALUE2", null, COLUMN_VARCHAR, "varchar(10)", false));
assertEquals(expectedQueryPrefix + "\"Column_Char\" = 'CHAR_VALUE' and \"Column_VChar\" = 'CHAR_VALUE2'", BUILDER.buildQuery(jobConf, TABLE_NAME, readColumnList, searchConditions));
searchConditions = Lists.newArrayList(mockedIndexSearchCondition("GenericUDFIn", null, new Object[] { "CHAR1", "CHAR2", "CHAR3" }, COLUMN_CHAR, "char(10)", false));
assertEquals(expectedQueryPrefix + "\"Column_Char\" in ('CHAR1', 'CHAR2', 'CHAR3')", BUILDER.buildQuery(jobConf, TABLE_NAME, readColumnList, searchConditions));
searchConditions = Lists.newArrayList(mockedIndexSearchCondition("GenericUDFIn", null, new Object[] { "CHAR1", "CHAR2", "CHAR3" }, COLUMN_CHAR, "char(10)", true));
assertEquals(expectedQueryPrefix + "\"Column_Char\" not in ('CHAR1', 'CHAR2', 'CHAR3')", BUILDER.buildQuery(jobConf, TABLE_NAME, readColumnList, searchConditions));
searchConditions = Lists.newArrayList(mockedIndexSearchCondition("GenericUDFBetween", null, new Object[] { "CHAR1", "CHAR2" }, COLUMN_CHAR, "char(10)", false));
assertEquals(expectedQueryPrefix + "\"Column_Char\" between 'CHAR1' and 'CHAR2'", BUILDER.buildQuery(jobConf, TABLE_NAME, readColumnList, searchConditions));
searchConditions = Lists.newArrayList(mockedIndexSearchCondition("GenericUDFBetween", null, new Object[] { "CHAR1", "CHAR2" }, COLUMN_CHAR, "char(10)", true));
assertEquals(expectedQueryPrefix + "\"Column_Char\" not between 'CHAR1' and 'CHAR2'", BUILDER.buildQuery(jobConf, TABLE_NAME, readColumnList, searchConditions));
}
use of org.apache.phoenix.hive.ql.index.IndexSearchCondition in project phoenix by apache.
the class PhoenixQueryBuilderTest method mockedIndexSearchCondition.
private IndexSearchCondition mockedIndexSearchCondition(String comparisionOp, Object constantValue, Object[] constantValues, String columnName, String typeString, boolean isNot) {
IndexSearchCondition condition = mock(IndexSearchCondition.class);
when(condition.getComparisonOp()).thenReturn(comparisionOp);
if (constantValue != null) {
ExprNodeConstantDesc constantDesc = mock(ExprNodeConstantDesc.class);
when(constantDesc.getValue()).thenReturn(constantValue);
when(condition.getConstantDesc()).thenReturn(constantDesc);
}
ExprNodeColumnDesc columnDesc = mock(ExprNodeColumnDesc.class);
when(columnDesc.getColumn()).thenReturn(columnName);
when(columnDesc.getTypeString()).thenReturn(typeString);
when(condition.getColumnDesc()).thenReturn(columnDesc);
if (ArrayUtils.isNotEmpty(constantValues)) {
ExprNodeConstantDesc[] constantDescs = new ExprNodeConstantDesc[constantValues.length];
for (int i = 0; i < constantDescs.length; i++) {
constantDescs[i] = mock(ExprNodeConstantDesc.class);
when(condition.getConstantDesc(i)).thenReturn(constantDescs[i]);
when(constantDescs[i].getValue()).thenReturn(constantValues[i]);
}
when(condition.getConstantDescs()).thenReturn(constantDescs);
}
when(condition.isNot()).thenReturn(isNot);
return condition;
}
use of org.apache.phoenix.hive.ql.index.IndexSearchCondition in project phoenix by apache.
the class PhoenixQueryBuilderTest method testBuildQueryWithNotNull.
@Test
public void testBuildQueryWithNotNull() throws IOException {
final String COLUMN_DATE = "Column_Date";
final String tableName = "TEST_TABLE";
final String expectedQueryPrefix = "select /*+ NO_CACHE */ \"" + COLUMN_DATE + "\" from " + tableName + " where ";
JobConf jobConf = new JobConf();
List<String> readColumnList = Lists.newArrayList(COLUMN_DATE);
List<IndexSearchCondition> searchConditions = Lists.newArrayList(mockedIndexSearchCondition("GenericUDFOPNotNull", null, null, COLUMN_DATE, "date", true));
assertEquals(expectedQueryPrefix + "\"" + COLUMN_DATE + "\" is not null ", BUILDER.buildQuery(jobConf, TABLE_NAME, readColumnList, searchConditions));
}
Aggregations