Search in sources :

Example 1 with PVarchar

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;
}
Also used : AbstractBasePattern(org.apache.phoenix.expression.util.regex.AbstractBasePattern) SortOrder(org.apache.phoenix.schema.SortOrder) PVarchar(org.apache.phoenix.schema.types.PVarchar) PBoolean(org.apache.phoenix.schema.types.PBoolean)

Example 2 with PVarchar

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();
    }
}
Also used : PChar(org.apache.phoenix.schema.types.PChar) PInteger(org.apache.phoenix.schema.types.PInteger) PDecimal(org.apache.phoenix.schema.types.PDecimal) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) PVarchar(org.apache.phoenix.schema.types.PVarchar) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Aggregations

PVarchar (org.apache.phoenix.schema.types.PVarchar)2 Connection (java.sql.Connection)1 AbstractBasePattern (org.apache.phoenix.expression.util.regex.AbstractBasePattern)1 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)1 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)1 SortOrder (org.apache.phoenix.schema.SortOrder)1 PBoolean (org.apache.phoenix.schema.types.PBoolean)1 PChar (org.apache.phoenix.schema.types.PChar)1 PDecimal (org.apache.phoenix.schema.types.PDecimal)1 PInteger (org.apache.phoenix.schema.types.PInteger)1 Test (org.junit.Test)1