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);
}
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);
}
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");
}
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");
}
Aggregations