use of org.apache.phoenix.schema.types.PVarchar in project phoenix by apache.
the class LikeExpression method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
AbstractBasePattern pattern = this.pattern;
if (pattern == null) {
// TODO: don't allow? this is going to be slooowwww
if (!getPatternExpression().evaluate(tuple, ptr)) {
if (logger.isTraceEnabled()) {
logger.trace("LIKE is FALSE: pattern is null");
}
return false;
}
String value = (String) PVarchar.INSTANCE.toObject(ptr, getPatternExpression().getSortOrder());
pattern = compilePattern(value);
if (logger.isTraceEnabled()) {
logger.trace("LIKE pattern is expression: " + pattern.pattern());
}
}
Expression strExpression = getStrExpression();
SortOrder strSortOrder = strExpression.getSortOrder();
PVarchar strDataType = PVarchar.INSTANCE;
if (!strExpression.evaluate(tuple, ptr)) {
if (logger.isTraceEnabled()) {
logger.trace("LIKE is FALSE: child expression is null");
}
return false;
}
String value = null;
if (logger.isTraceEnabled()) {
value = (String) strDataType.toObject(ptr, strSortOrder);
}
strDataType.coerceBytes(ptr, strDataType, strSortOrder, SortOrder.ASC);
pattern.matches(ptr);
if (logger.isTraceEnabled()) {
boolean matched = ((Boolean) PBoolean.INSTANCE.toObject(ptr)).booleanValue();
logger.trace("LIKE(value='" + value + "'pattern='" + pattern.pattern() + "' is " + matched);
}
return true;
}
use of org.apache.phoenix.schema.types.PVarchar in project phoenix by apache.
the class QueryCompilerTest method testColumnProjectionUnionAll.
@Test
public void testColumnProjectionUnionAll() throws SQLException {
Connection conn = DriverManager.getConnection(getUrl());
try {
conn.createStatement().execute("CREATE TABLE t1(k INTEGER PRIMARY KEY," + " col1 CHAR(8), col2 VARCHAR(10), col3 decimal(10,2))");
conn.createStatement().execute("CREATE TABLE t2(k TINYINT PRIMARY KEY," + " col1 CHAR(20), col2 CHAR(30), col3 double)");
QueryPlan plan = getQueryPlan("SELECT * from t1 union all select * from t2", Collections.emptyList());
RowProjector rowProj = plan.getProjector();
assertTrue(rowProj.getColumnProjector(0).getExpression().getDataType() instanceof PInteger);
assertTrue(rowProj.getColumnProjector(1).getExpression().getDataType() instanceof PChar);
assertTrue(rowProj.getColumnProjector(1).getExpression().getMaxLength() == 20);
assertTrue(rowProj.getColumnProjector(2).getExpression().getDataType() instanceof PVarchar);
assertTrue(rowProj.getColumnProjector(2).getExpression().getMaxLength() == 30);
assertTrue(rowProj.getColumnProjector(3).getExpression().getDataType() instanceof PDecimal);
assertTrue(rowProj.getColumnProjector(3).getExpression().getScale() == 2);
} finally {
conn.close();
}
}
Aggregations