Search in sources :

Example 1 with IndexSearchCondition

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;
}
Also used : DecomposedPredicate(org.apache.hadoop.hive.ql.metadata.HiveStoragePredicateHandler.DecomposedPredicate) IndexSearchCondition(org.apache.phoenix.hive.ql.index.IndexSearchCondition) ArrayList(java.util.ArrayList) IndexPredicateAnalyzer(org.apache.phoenix.hive.ql.index.IndexPredicateAnalyzer)

Example 2 with IndexSearchCondition

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));
}
Also used : IndexSearchCondition(org.apache.phoenix.hive.ql.index.IndexSearchCondition) JobConf(org.apache.hadoop.mapred.JobConf) Test(org.junit.Test)

Example 3 with IndexSearchCondition

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));
}
Also used : IndexSearchCondition(org.apache.phoenix.hive.ql.index.IndexSearchCondition) JobConf(org.apache.hadoop.mapred.JobConf) Test(org.junit.Test)

Example 4 with IndexSearchCondition

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;
}
Also used : ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) IndexSearchCondition(org.apache.phoenix.hive.ql.index.IndexSearchCondition) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)

Example 5 with IndexSearchCondition

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));
}
Also used : IndexSearchCondition(org.apache.phoenix.hive.ql.index.IndexSearchCondition) JobConf(org.apache.hadoop.mapred.JobConf) Test(org.junit.Test)

Aggregations

IndexSearchCondition (org.apache.phoenix.hive.ql.index.IndexSearchCondition)6 JobConf (org.apache.hadoop.mapred.JobConf)3 Test (org.junit.Test)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 DecomposedPredicate (org.apache.hadoop.hive.ql.metadata.HiveStoragePredicateHandler.DecomposedPredicate)1 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)1 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)1 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)1 InputSplit (org.apache.hadoop.mapred.InputSplit)1 QueryPlan (org.apache.phoenix.compile.QueryPlan)1 PhoenixPredicateDecomposer (org.apache.phoenix.hive.ppd.PhoenixPredicateDecomposer)1 IndexPredicateAnalyzer (org.apache.phoenix.hive.ql.index.IndexPredicateAnalyzer)1 KeyRange (org.apache.phoenix.query.KeyRange)1