Java Code Examples for org.apache.hadoop.hbase.filter.CompareFilter.CompareOp

The following examples show how to use org.apache.hadoop.hbase.filter.CompareFilter.CompareOp. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected Filter fetchHbaseFilter() {
  FilterList filterList = new FilterList();
  String[] columns = new String[]{
      EventLogConstants.LOG_COLUMN_NAME_REFERER_URL,
      EventLogConstants.LOG_COLUMN_NAME_SESSION_ID,
      EventLogConstants.LOG_COLUMN_NAME_SERVER_TIME,
      EventLogConstants.LOG_COLUMN_NAME_PLATFORM,
      EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME,
  };
  //过滤数据
  filterList.addFilter(this.getColumnFilter(columns));
  filterList.addFilter(
      new SingleColumnValueExcludeFilter(Bytes.toBytes(EventLogConstants.EVENT_LOGS_FAMILY_NAME),
          Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME), CompareOp.EQUAL,
          Bytes.toBytes(
              EventEnum.PAGEVIEW.alias)));
  return filterList;
}
 
Example 2
@Override
protected Filter fetchHbaseFilter() {
  FilterList filterList = new FilterList();
  // 只需要pageview事件
  filterList.addFilter(
      new SingleColumnValueFilter(Bytes.toBytes(EventLogConstants.EVENT_LOGS_FAMILY_NAME),
          Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME), CompareOp.EQUAL,
          Bytes.toBytes(EventLogConstants.EventEnum.PAGEVIEW.alias)));
  // 定义mapper中需要获取的列名
  String[] columns = new String[]{EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME, // 获取事件名称
      EventLogConstants.LOG_COLUMN_NAME_CURRENT_URL, // 当前url
      EventLogConstants.LOG_COLUMN_NAME_SERVER_TIME, // 服务器时间
      EventLogConstants.LOG_COLUMN_NAME_PLATFORM, // 平台名称
      EventLogConstants.LOG_COLUMN_NAME_BROWSER_NAME, // 浏览器名称
      EventLogConstants.LOG_COLUMN_NAME_BROWSER_VERSION // 浏览器版本号
  };
  filterList.addFilter(this.getColumnFilter(columns));

  return filterList;
}
 
Example 3
Source Project: phoenix   Source File: WhereCompilerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testToDateFilter() throws Exception {
    String tenantId = "000000000000001";
    String dateStr = "2012-01-01 12:00:00";
    String query = "select * from atable where organization_id='" + tenantId + "' and a_date >= to_date('" + dateStr + "')";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();

    Date date = DateUtil.parseDate(dateStr);

    assertEquals(
        singleKVFilter(constantComparison(
            CompareOp.GREATER_OR_EQUAL,
            A_DATE,
            date)),
        filter);
}
 
Example 4
Source Project: phoenix   Source File: WhereCompilerTest.java    License: Apache License 2.0 6 votes vote down vote up
private void helpTestToNumberFilter(String toNumberClause, BigDecimal expectedDecimal) throws Exception {
        String tenantId = "000000000000001";
        String query = "select * from atable where organization_id='" + tenantId + "' and x_decimal >= " + toNumberClause;
        PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
        QueryPlan plan = pstmt.optimizeQuery();
        Scan scan = plan.getContext().getScan();
        Filter filter = scan.getFilter();

        assertEquals(
            singleKVFilter(constantComparison(
                CompareOp.GREATER_OR_EQUAL,
                X_DECIMAL,
                expectedDecimal)),
            filter);
}
 
Example 5
Source Project: phoenix   Source File: WhereCompilerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNotBetweenFilter() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and a_integer not between 0 and 10";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();
    assertEquals(
            singleKVFilter(not(and(
                constantComparison(
                    CompareOp.GREATER_OR_EQUAL,
                    A_INTEGER,
                    0),
                constantComparison(
                    CompareOp.LESS_OR_EQUAL,
                    A_INTEGER,
                    10)))).toString(),
            filter.toString());
}
 
Example 6
Source Project: phoenix   Source File: SortOrderExpressionTest.java    License: Apache License 2.0 6 votes vote down vote up
private void runCompareTest(CompareOp op, boolean expectedResult, Object lhsValue, PDataType lhsDataType, Object rhsValue, PDataType rhsDataType) throws Exception {
    List<Expression> args;
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();

    args = Lists.newArrayList(getLiteral(lhsValue, lhsDataType), getLiteral(rhsValue, rhsDataType));
    evaluateAndAssertResult(ComparisonExpression.create(op, args, ptr, true), expectedResult, "lhsDataType: " + lhsDataType + " rhsDataType: " + rhsDataType);
    
    args = Lists.newArrayList(getInvertedLiteral(lhsValue, lhsDataType), getLiteral(rhsValue, rhsDataType));
    evaluateAndAssertResult(ComparisonExpression.create(op, args, ptr, true), expectedResult, "lhs (inverted) dataType: " + lhsDataType + " rhsDataType: " + rhsDataType);
    
    args = Lists.newArrayList(getLiteral(lhsValue, lhsDataType), getInvertedLiteral(rhsValue, rhsDataType));
    evaluateAndAssertResult(ComparisonExpression.create(op, args, ptr, true), expectedResult, "lhsDataType: " + lhsDataType + " rhs (inverted) dataType: " + rhsDataType);
    
    args = Lists.newArrayList(getInvertedLiteral(lhsValue, lhsDataType), getInvertedLiteral(rhsValue, rhsDataType));
    evaluateAndAssertResult(ComparisonExpression.create(op, args, ptr, true), expectedResult, "lhs (inverted) dataType: " + lhsDataType + " rhs (inverted) dataType: " + rhsDataType);                
}
 
Example 7
Source Project: BigDataArchitect   Source File: ActiveMemberRunner.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Filter fetchHbaseFilter() {
    FilterList filterList = new FilterList();
    // 定义mapper中需要获取的列名
    String[] columns = new String[] { EventLogConstants.LOG_COLUMN_NAME_MEMBER_ID, // 会员id
            EventLogConstants.LOG_COLUMN_NAME_SERVER_TIME, // 服务器时间
            EventLogConstants.LOG_COLUMN_NAME_PLATFORM, // 平台名称
            EventLogConstants.LOG_COLUMN_NAME_BROWSER_NAME, // 浏览器名称
            EventLogConstants.LOG_COLUMN_NAME_BROWSER_VERSION, // 浏览器版本号
            EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME // 添加一个事件名称获取列,在使用singlecolumnvaluefilter的时候必须指定对应的列是一个返回列
    };
    filterList.addFilter(this.getColumnFilter(columns));
    // 只需要page view事件,所以进行过滤
    filterList.addFilter(new SingleColumnValueFilter(ActiveMemberMapper.family, Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME), CompareOp.EQUAL, Bytes.toBytes(EventEnum.PAGEVIEW.alias)));

    return filterList;
}
 
Example 8
Source Project: phoenix   Source File: WhereCompilerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNotBetweenFilter() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and a_integer not between 0 and 10";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();
    assertEquals(
            singleKVFilter(not(and(
                constantComparison(
                    CompareOp.GREATER_OR_EQUAL,
                    A_INTEGER,
                    0),
                constantComparison(
                    CompareOp.LESS_OR_EQUAL,
                    A_INTEGER,
                    10)))).toString(),
            filter.toString());
}
 
Example 9
Source Project: searchanalytics-bigdata   Source File: HbaseServiceImpl.java    License: MIT License 6 votes vote down vote up
@Override
public List<String> getSearchClicksRowKeysWithValidQueryString() {
	LOG.debug("Checking getSearchClicksRowKeys searchclicks table content!");
	Scan scan = new Scan();
	scan.addFamily(HbaseJsonEventSerializer.COLUMFAMILY_SEARCH_BYTES);
	SingleColumnValueFilter filter = new SingleColumnValueFilter(HbaseJsonEventSerializer.COLUMFAMILY_SEARCH_BYTES, 
			Bytes.toBytes("querystring"), CompareOp.NOT_EQUAL, Bytes.toBytes("jaiblahblah"));
	filter.setFilterIfMissing(true);
	scan.setFilter(filter);
	List<String> rows = hbaseTemplate.find("searchclicks", scan,
			new RowMapper<String>() {
				@Override
				public String mapRow(Result result, int rowNum)
						throws Exception {
					return new String(result.getRow());
				}
			});
	for (String row : rows) {
		LOG.debug("searchclicks table content, Table returned row key: {}", row);
	}
	LOG.debug("Checking getSearchClicksRowKeys searchclicks table content done!");
	return rows;
}
 
Example 10
Source Project: phoenix   Source File: ByteUtil.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static boolean compare(CompareOp op, int compareResult) {
    switch (op) {
        case LESS:
          return compareResult < 0;
        case LESS_OR_EQUAL:
          return compareResult <= 0;
        case EQUAL:
          return compareResult == 0;
        case NOT_EQUAL:
          return compareResult != 0;
        case GREATER_OR_EQUAL:
          return compareResult >= 0;
        case GREATER:
          return compareResult > 0;
        default:
          throw new RuntimeException("Unknown Compare op " + op.name());
    }
}
 
Example 11
private void helpTestToNumberFilter(String toNumberClause, BigDecimal expectedDecimal) throws Exception {
        String tenantId = "000000000000001";
        String query = "select * from atable where organization_id='" + tenantId + "' and x_decimal >= " + toNumberClause;
        PhoenixConnection pconn = DriverManager.getConnection(getUrl(), TEST_PROPERTIES).unwrap(PhoenixConnection.class);
        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
        QueryPlan plan = pstmt.optimizeQuery();
        Scan scan = plan.getContext().getScan();
        Filter filter = scan.getFilter();

        assertEquals(
            singleKVFilter(constantComparison(
                CompareOp.GREATER_OR_EQUAL,
                BaseConnectionlessQueryTest.X_DECIMAL,
                expectedDecimal)),
            filter);
}
 
Example 12
/**
 * Invert the childPart key range
 */
@Override
public KeyPart newKeyPart(final KeyPart childPart) {
    return new KeyPart() {

        @Override
        public KeyRange getKeyRange(CompareOp op, Expression rhs) {
            KeyRange range = childPart.getKeyRange(op, rhs);
            return range.invert();
        }

        @Override
        public List<Expression> getExtractNodes() {
            return childPart.getExtractNodes();
        }

        @Override
        public PColumn getColumn() {
            return childPart.getColumn();
        }
    };
}
 
Example 13
Source Project: phoenix   Source File: WhereCompilerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 14
@Test
public void testMultiColumnEqualFilter() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and a_string=b_string";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), TEST_PROPERTIES).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();
    assertEquals(
        multiKVFilter(columnComparison(
            CompareOp.EQUAL,
            BaseConnectionlessQueryTest.A_STRING,
            BaseConnectionlessQueryTest.B_STRING)),
        filter);
}
 
Example 15
Source Project: phoenix   Source File: WhereOptimizer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public KeySlots visitLeave(InListExpression node, List<KeySlots> childParts) {
    if (childParts.isEmpty()) {
        return null;
    }

    List<Expression> keyExpressions = node.getKeyExpressions();
    Set<KeyRange> ranges = Sets.newHashSetWithExpectedSize(keyExpressions.size());
    KeySlot childSlot = childParts.get(0).iterator().next();
    KeyPart childPart = childSlot.getKeyPart();
    // Handles cases like WHERE substr(foo,1,3) IN ('aaa','bbb')
    for (Expression key : keyExpressions) {
        KeyRange range = childPart.getKeyRange(CompareOp.EQUAL, key);
        if (range != KeyRange.EMPTY_RANGE) { // null means it can't possibly be in range
            ranges.add(range);
        }
    }
    return newKeyParts(childSlot, node, new ArrayList<KeyRange>(ranges), null);
}
 
Example 16
Source Project: phoenix   Source File: WhereCompilerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBetweenFilter() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and a_integer between 0 and 10";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();
    assertEquals(
            singleKVFilter(and(
                constantComparison(
                    CompareOp.GREATER_OR_EQUAL,
                    A_INTEGER,
                    0),
                constantComparison(
                    CompareOp.LESS_OR_EQUAL,
                    A_INTEGER,
                    10))),
            filter);
}
 
Example 17
Source Project: phoenix   Source File: ParseNodeFactory.java    License: Apache License 2.0 6 votes vote down vote up
public ComparisonParseNode comparison(CompareOp op, ParseNode lhs, ParseNode rhs) {
    switch (op){
    case LESS:
        return lt(lhs,rhs);
    case LESS_OR_EQUAL:
        return lte(lhs,rhs);
    case EQUAL:
        return equal(lhs,rhs);
    case NOT_EQUAL:
        return notEqual(lhs,rhs);
    case GREATER_OR_EQUAL:
        return gte(lhs,rhs);
    case GREATER:
        return gt(lhs,rhs);
    default:
        throw new IllegalArgumentException("Unexpcted CompareOp of " + op);
    }
}
 
Example 18
public ComparisonParseNode comparison(CompareOp op, ParseNode lhs, ParseNode rhs) {
    switch (op){
    case LESS:
        return lt(lhs,rhs);
    case LESS_OR_EQUAL:
        return lte(lhs,rhs);
    case EQUAL:
        return equal(lhs,rhs);
    case NOT_EQUAL:
        return notEqual(lhs,rhs);
    case GREATER_OR_EQUAL:
        return gte(lhs,rhs);
    case GREATER:
        return gt(lhs,rhs);
    default:
        throw new IllegalArgumentException("Unexpcted CompareOp of " + op);
    }
}
 
Example 19
Source Project: phoenix   Source File: SelectStatementRewriterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRewriteAnd() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and a_integer=0 and a_string='foo'";
    Filter filter = compileStatement(query);
    assertEquals(
            multiEncodedKVFilter(and(
                    constantComparison(
                        CompareOp.EQUAL,
                        A_INTEGER, 0),
                    constantComparison(
                        CompareOp.EQUAL,
                        A_STRING, "foo")
                ), TWO_BYTE_QUALIFIERS),
            filter);
}
 
Example 20
Source Project: phoenix   Source File: WhereCompilerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBetweenFilter() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and a_integer between 0 and 10";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();
    assertEquals(
            singleKVFilter(and(
                constantComparison(
                    CompareOp.GREATER_OR_EQUAL,
                    A_INTEGER,
                    0),
                constantComparison(
                    CompareOp.LESS_OR_EQUAL,
                    A_INTEGER,
                    10))),
            filter);
}
 
Example 21
@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(), TEST_PROPERTIES).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(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(BaseConnectionlessQueryTest.ENTITY_ID,new RowKeyValueAccessor(BaseConnectionlessQueryTest.ATABLE.getPKColumns(),1)),
                        LiteralExpression.newConstant(1),
                        LiteralExpression.newConstant(3))
                    ),
                keyPrefix), QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES),
        filter);
}
 
Example 22
Source Project: phoenix   Source File: WhereCompilerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRHSLiteral() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and 0 >= a_integer";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    
    Filter filter = scan.getFilter();
    assertEquals(
        singleKVFilter(constantComparison(
            CompareOp.LESS_OR_EQUAL,
            A_INTEGER,
            0)),
        filter);
}
 
Example 23
Source Project: phoenix   Source File: InvertFunction.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Invert the childPart key range
 */
@Override
public KeyPart newKeyPart(final KeyPart childPart) {
    return new KeyPart() {

        @Override
        public KeyRange getKeyRange(CompareOp op, Expression rhs) {
            KeyRange range = childPart.getKeyRange(op, rhs);
            return range.invert();
        }

        @Override
        public List<Expression> getExtractNodes() {
            return childPart.getExtractNodes();
        }

        @Override
        public PColumn getColumn() {
            return childPart.getColumn();
        }
    };
}
 
Example 24
Source Project: phoenix   Source File: ByteUtil.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static KeyRange getKeyRange(byte[] key, CompareOp op, PDataType type) {
    switch (op) {
    case EQUAL:
        return type.getKeyRange(key, true, key, true);
    case GREATER:
        return type.getKeyRange(key, false, KeyRange.UNBOUND, false);
    case GREATER_OR_EQUAL:
        return type.getKeyRange(key, true, KeyRange.UNBOUND, false);
    case LESS:
        return type.getKeyRange(KeyRange.UNBOUND, false, key, false);
    case LESS_OR_EQUAL:
        return type.getKeyRange(KeyRange.UNBOUND, false, key, true);
    default:
        throw new IllegalArgumentException("Unknown operator " + op);
    }
}
 
Example 25
Source Project: phoenix   Source File: WhereCompilerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleEqualFilter() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and a_integer=0";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();
    assertEquals(
        singleKVFilter(constantComparison(
            CompareOp.EQUAL,
            A_INTEGER,
            0)),
        filter);
}
 
Example 26
Source Project: phoenix   Source File: WhereCompilerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testToDateFilter() throws Exception {
    String tenantId = "000000000000001";
    String dateStr = "2012-01-01 12:00:00";
    String query = "select * from atable where organization_id='" + tenantId + "' and a_date >= to_date('" + dateStr + "')";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();

    Date date = DateUtil.parseDate(dateStr);

    assertEquals(
        singleKVFilter(constantComparison(
            CompareOp.GREATER_OR_EQUAL,
            A_DATE,
            date)),
        filter);
}
 
Example 27
Source Project: phoenix   Source File: WhereCompilerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiColumnEqualFilter() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and a_string=b_string";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();
    assertEquals(
        multiEncodedKVFilter(columnComparison(
            CompareOp.EQUAL,
            A_STRING,
            B_STRING), TWO_BYTE_QUALIFIERS),
        filter);
}
 
Example 28
Source Project: phoenix   Source File: HavingCompilerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAndHavingToWhere() throws SQLException {
    String query = "select count(1) from atable group by a_string having count(1) >= 1 and a_string = 'foo'";
    List<Object> binds = Collections.emptyList();
    Expressions expressions = compileStatement(query,binds);
    Expression h = constantComparison(CompareOp.GREATER_OR_EQUAL, new CountAggregateFunction(),1L);
    Expression w = constantComparison(CompareOp.EQUAL, A_STRING,"foo");
    assertEquals(w, expressions.whereClause);
    assertEquals(h, expressions.havingClause);
}
 
Example 29
@Test
public void testAggFuncInHaving() throws SQLException {
    String query = "select count(1) from atable group by a_string having count(a_string) >= 1";
    List<Object> binds = Collections.emptyList();
    Expressions expressions = compileStatement(query,binds);
    Expression h = constantComparison(CompareOp.GREATER_OR_EQUAL, new CountAggregateFunction(Arrays.asList(kvColumn(BaseConnectionlessQueryTest.A_STRING))),1L);
    assertTrue(LiteralExpression.isTrue(expressions.whereClause));
    assertEquals(h, expressions.havingClause);
}
 
Example 30
Source Project: BigDataArchitect   Source File: InboundBounceRunner.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Filter fetchHbaseFilter() {
    FilterList list = new FilterList();
    String[] columns = new String[] { EventLogConstants.LOG_COLUMN_NAME_REFERRER_URL, // 前一个页面的url
            EventLogConstants.LOG_COLUMN_NAME_SESSION_ID, // 会话id
            EventLogConstants.LOG_COLUMN_NAME_PLATFORM, // 平台名称
            EventLogConstants.LOG_COLUMN_NAME_SERVER_TIME, // 服务器时间
            EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME // 事件名称
    };
    list.addFilter(this.getColumnFilter(columns));
    list.addFilter(new SingleColumnValueFilter(InboundMapper.family, Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME), CompareOp.EQUAL, Bytes.toBytes(EventEnum.PAGEVIEW.alias)));
    return list;
}