Search in sources :

Example 1 with SubstrFunction

use of org.apache.phoenix.expression.function.SubstrFunction in project phoenix by apache.

the class WhereCompilerTest method testOrFilter.

@Test
public void testOrFilter() throws SQLException {
    String tenantId = "000000000000001";
    String keyPrefix = "foo";
    int aInt = 2;
    String query = "select * from atable where organization_id=? and (substr(entity_id,1,3)=? or a_integer=?)";
    List<Object> binds = Arrays.<Object>asList(tenantId, keyPrefix, aInt);
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    bindParams(pstmt, binds);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();
    assertEquals(singleKVFilter(or(constantComparison(CompareOp.EQUAL, new SubstrFunction(Arrays.<Expression>asList(new RowKeyColumnExpression(ENTITY_ID, new RowKeyValueAccessor(ATABLE.getPKColumns(), 1)), LiteralExpression.newConstant(1), LiteralExpression.newConstant(3))), keyPrefix), constantComparison(CompareOp.EQUAL, A_INTEGER, aInt))), filter);
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) TestUtil.multiEncodedKVFilter(org.apache.phoenix.util.TestUtil.multiEncodedKVFilter) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Filter(org.apache.hadoop.hbase.filter.Filter) TestUtil.singleKVFilter(org.apache.phoenix.util.TestUtil.singleKVFilter) RowKeyValueAccessor(org.apache.phoenix.schema.RowKeyValueAccessor) Scan(org.apache.hadoop.hbase.client.Scan) SubstrFunction(org.apache.phoenix.expression.function.SubstrFunction) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 2 with SubstrFunction

use of org.apache.phoenix.expression.function.SubstrFunction in project phoenix by apache.

the class WhereCompilerTest method testRowKeyFilter.

@Test
public void testRowKeyFilter() throws SQLException {
    String keyPrefix = "foo";
    String query = "select * from atable where substr(entity_id,1,3)=?";
    List<Object> binds = Arrays.<Object>asList(keyPrefix);
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    bindParams(pstmt, binds);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();
    assertEquals(new RowKeyComparisonFilter(constantComparison(CompareOp.EQUAL, new SubstrFunction(Arrays.<Expression>asList(new RowKeyColumnExpression(ENTITY_ID, new RowKeyValueAccessor(ATABLE.getPKColumns(), 1)), LiteralExpression.newConstant(1), LiteralExpression.newConstant(3))), keyPrefix), QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES), filter);
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) RowKeyValueAccessor(org.apache.phoenix.schema.RowKeyValueAccessor) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) TestUtil.multiEncodedKVFilter(org.apache.phoenix.util.TestUtil.multiEncodedKVFilter) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Filter(org.apache.hadoop.hbase.filter.Filter) TestUtil.singleKVFilter(org.apache.phoenix.util.TestUtil.singleKVFilter) KeyValueColumnExpression(org.apache.phoenix.expression.KeyValueColumnExpression) Expression(org.apache.phoenix.expression.Expression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) Scan(org.apache.hadoop.hbase.client.Scan) SubstrFunction(org.apache.phoenix.expression.function.SubstrFunction) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 3 with SubstrFunction

use of org.apache.phoenix.expression.function.SubstrFunction in project phoenix by apache.

the class SortOrderExpressionTest method substr.

@Test
public void substr() throws Exception {
    List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PChar.INSTANCE), getLiteral(3), getLiteral(2));
    evaluateAndAssertResult(new SubstrFunction(args), "ah");
}
Also used : RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) ByteBasedRegexpSubstrFunction(org.apache.phoenix.expression.function.ByteBasedRegexpSubstrFunction) SubstrFunction(org.apache.phoenix.expression.function.SubstrFunction) StringBasedRegexpSubstrFunction(org.apache.phoenix.expression.function.StringBasedRegexpSubstrFunction) Test(org.junit.Test)

Example 4 with SubstrFunction

use of org.apache.phoenix.expression.function.SubstrFunction in project phoenix by apache.

the class SortOrderExpressionTest method substrLtrim.

@Test
public void substrLtrim() throws Exception {
    List<Expression> ltrimArgs = Lists.newArrayList(getInvertedLiteral("   blah", PChar.INSTANCE));
    Expression ltrim = new LTrimFunction(ltrimArgs);
    List<Expression> substrArgs = Lists.newArrayList(ltrim, getLiteral(3), getLiteral(2));
    evaluateAndAssertResult(new SubstrFunction(substrArgs), "ah");
}
Also used : LTrimFunction(org.apache.phoenix.expression.function.LTrimFunction) RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) ByteBasedRegexpSubstrFunction(org.apache.phoenix.expression.function.ByteBasedRegexpSubstrFunction) SubstrFunction(org.apache.phoenix.expression.function.SubstrFunction) StringBasedRegexpSubstrFunction(org.apache.phoenix.expression.function.StringBasedRegexpSubstrFunction) Test(org.junit.Test)

Aggregations

SubstrFunction (org.apache.phoenix.expression.function.SubstrFunction)4 Test (org.junit.Test)4 Scan (org.apache.hadoop.hbase.client.Scan)2 Filter (org.apache.hadoop.hbase.filter.Filter)2 RowKeyColumnExpression (org.apache.phoenix.expression.RowKeyColumnExpression)2 ByteBasedRegexpSubstrFunction (org.apache.phoenix.expression.function.ByteBasedRegexpSubstrFunction)2 RoundDateExpression (org.apache.phoenix.expression.function.RoundDateExpression)2 StringBasedRegexpSubstrFunction (org.apache.phoenix.expression.function.StringBasedRegexpSubstrFunction)2 RowKeyComparisonFilter (org.apache.phoenix.filter.RowKeyComparisonFilter)2 SkipScanFilter (org.apache.phoenix.filter.SkipScanFilter)2 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)2 PhoenixPreparedStatement (org.apache.phoenix.jdbc.PhoenixPreparedStatement)2 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)2 RowKeyValueAccessor (org.apache.phoenix.schema.RowKeyValueAccessor)2 TestUtil.multiEncodedKVFilter (org.apache.phoenix.util.TestUtil.multiEncodedKVFilter)2 TestUtil.singleKVFilter (org.apache.phoenix.util.TestUtil.singleKVFilter)2 Expression (org.apache.phoenix.expression.Expression)1 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)1 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)1 LTrimFunction (org.apache.phoenix.expression.function.LTrimFunction)1