org.apache.hadoop.hbase.filter.Filter Java Examples

The following examples show how to use org.apache.hadoop.hbase.filter.Filter. 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
Source File: WhereCompilerTest.java    From phoenix with 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 #2
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testNullAtEndOfRVC() throws SQLException {
    String tenantId = "000000000000001";
    String parentId = "000000000000002";
    Date createdDate = null;
    
    String query = "select * from entity_history where (organization_id, parent_id, created_date) >= (?,?,?)";
    List<Object> binds = Arrays.<Object>asList(tenantId, parentId, createdDate);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNull(filter);
    byte[] expectedStartRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(parentId));
    assertArrayEquals(expectedStartRow, scan.getStartRow());
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
}
 
Example #3
Source File: AbstractHBaseLogReader.java    From Eagle with Apache License 2.0 6 votes vote down vote up
/**
 * <h2>History</h2>
 * <ul>
 * 	<li><b>Nov 19th, 2014</b>: Fix for out put all qualifiers</li>
 * </ul>
 * @param s1
 * @param filter
 */
protected void workaroundHBASE2198(Scan s1, Filter filter) {
	if (filter instanceof SingleColumnValueFilter) {
		if(this.qualifiers == null){
			s1.addFamily(((SingleColumnValueFilter) filter).getFamily());
		}else {
			s1.addColumn(((SingleColumnValueFilter) filter).getFamily(), ((SingleColumnValueFilter) filter).getQualifier());
		}
		return;
	}
	if (filter instanceof FilterList) {
		for (Filter f : ((FilterList)filter).getFilters()) {
			workaroundHBASE2198(s1, f);
		}
	}
}
 
Example #4
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseOfFunctionOnLHSInMiddleOfRVCForLTE() throws SQLException {
    String tenantId = "000000000000001";
    String parentId = "000000000000002";
    String subStringParentId = parentId.substring(0, 3);
    Date createdDate = new Date(System.currentTimeMillis());
    
    String query = "select * from entity_history where (organization_id, substr(parent_id, 1, 3), created_date) <= (?,?,?)";
    List<Object> binds = Arrays.<Object>asList(tenantId, subStringParentId, createdDate);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNotNull(filter);
    assertTrue(filter instanceof RowKeyComparisonFilter);
    byte[] expectedStopRow = ByteUtil.concat(
        PVarchar.INSTANCE.toBytes(tenantId), ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(subStringParentId)));
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStartRow());
    assertArrayEquals(expectedStopRow, scan.getStopRow());
}
 
Example #5
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testLikeNoOptKeyExpression() throws SQLException {
    String tenantId = "000000000000001";
    String keyPrefix = "002";
    String likeArg = "%001%" + keyPrefix + "%";
    String query = "select * from atable where organization_id = ? and entity_id  LIKE '" + likeArg + "'";
    List<Object> binds = Arrays.<Object>asList(tenantId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();

    Filter filter = scan.getFilter();
    assertNotNull(filter);
    assertEquals(
            rowKeyFilter(like(
                ENTITY_ID,
                likeArg)),
            filter);

    byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
    assertArrayEquals(startRow, scan.getStartRow());
    assertArrayEquals(ByteUtil.nextKey(startRow), scan.getStopRow());
}
 
Example #6
Source File: WhereCompilerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrFalseFilter() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and (a_integer=0 or 3!=3)";
    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);
    byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
    assertArrayEquals(startRow, scan.getStartRow());
    byte[] stopRow = startRow;
    assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
}
 
Example #7
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testLikeExtractKeyExpression2() throws SQLException {
    String tenantId = "000000000000001";
    String keyPrefix = "002";
    String likeArg = keyPrefix + "_";
    String query = "select * from atable where organization_id = ? and entity_id  LIKE '" + likeArg + "'";
    List<Object> binds = Arrays.<Object>asList(tenantId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();

    Filter filter = scan.getFilter();
    assertNotNull(filter);
    assertEquals(
            rowKeyFilter(like(
                ENTITY_ID,
                likeArg,
                context)),
            filter);

    byte[] startRow = ByteUtil.concat(
        PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15));
    assertArrayEquals(startRow, scan.getStartRow());
    byte[] stopRow = ByteUtil.concat(
        PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)),15));
    assertArrayEquals(stopRow, scan.getStopRow());
}
 
Example #8
Source File: WhereCompilerTest.java    From phoenix with 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 #9
Source File: PerformanceEvaluation.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected Scan constructScan(byte[] valuePrefix) throws IOException {
  FilterList list = new FilterList();
  Filter filter = new SingleColumnValueFilter(FAMILY_ZERO, COLUMN_ZERO,
    CompareOperator.EQUAL, new BinaryComparator(valuePrefix));
  list.addFilter(filter);
  if (opts.filterAll) {
    list.addFilter(new FilterAllFilter());
  }
  Scan scan = new Scan().setCaching(opts.caching).setCacheBlocks(opts.cacheBlocks)
      .setAsyncPrefetch(opts.asyncPrefetch).setReadType(opts.scanReadType)
      .setScanMetricsEnabled(true);
  if (opts.addColumns) {
    for (int column = 0; column < opts.columns; column++) {
      byte [] qualifier = column == 0? COLUMN_ZERO: Bytes.toBytes("" + column);
      scan.addColumn(FAMILY_ZERO, qualifier);
    }
  } else {
    scan.addFamily(FAMILY_ZERO);
  }
  scan.setFilter(list);
  return scan;
}
 
Example #10
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrDiffColExpression() throws SQLException {
    String tenantId1 = "000000000000001";
    String entityId1 = "002333333333331";
    String query = "select * from atable where organization_id = ? or entity_id  = ?";
    List<Object> binds = Arrays.<Object>asList(tenantId1,entityId1);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();

    assertNotNull(filter);
    assertTrue(filter instanceof RowKeyComparisonFilter);
    ScanRanges scanRanges = context.getScanRanges();
    assertEquals(ScanRanges.EVERYTHING,scanRanges);
    assertArrayEquals(HConstants.EMPTY_START_ROW, scan.getStartRow());
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
}
 
Example #11
Source File: TransactionVisibilityFilterTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
/**
 * Test filtering of KeyValues for in-progress and invalid transactions.
 * @throws Exception
 */
@Test
public void testFiltering() throws Exception {
  TxFilterFactory txFilterFactory = new TxFilterFactory() {
    @Override
    public Filter getTxFilter(Transaction tx, Map<byte[], Long> familyTTLs) {
      return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN);
    }
  };
  runFilteringTest(txFilterFactory,
                   ImmutableList.of(Filter.ReturnCode.INCLUDE_AND_NEXT_COL,
                                    Filter.ReturnCode.INCLUDE_AND_NEXT_COL,
                                    Filter.ReturnCode.SKIP,
                                    Filter.ReturnCode.SKIP,
                                    Filter.ReturnCode.INCLUDE_AND_NEXT_COL,
                                    Filter.ReturnCode.INCLUDE_AND_NEXT_COL));
}
 
Example #12
Source File: WhereClauseCompileTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 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(), 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(not(and(
                constantComparison(
                    CompareOp.GREATER_OR_EQUAL,
                    BaseConnectionlessQueryTest.A_INTEGER,
                    0),
                constantComparison(
                    CompareOp.LESS_OR_EQUAL,
                    BaseConnectionlessQueryTest.A_INTEGER,
                    10)))).toString(),
            filter.toString());
}
 
Example #13
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testFullyQualifiedRVCWithNonTenantSpecificView() throws Exception {
	String baseTableDDL = "CREATE TABLE BASE_TABLE(\n " + 
            "  tenant_id VARCHAR(5) NOT NULL,\n" + 
            "  userid INTEGER NOT NULL,\n" + 
            "  username VARCHAR NOT NULL,\n" +
            "  col VARCHAR\n " + 
            "  CONSTRAINT pk PRIMARY KEY (tenant_id, userid, username))";
	Connection conn = DriverManager.getConnection(getUrl());
    conn.createStatement().execute(baseTableDDL);
    conn.close();
    
    String viewDDL = "CREATE VIEW VIEWXYZ AS SELECT * FROM BASE_TABLE";
    conn = DriverManager.getConnection(getUrl());
    conn.createStatement().execute(viewDDL);
    
    String query = "SELECT * FROM VIEWXYZ WHERE (tenant_id, userid, username) IN ((?, ?, ?), (?, ?, ?))";
    List<Object> binds = Arrays.<Object>asList("tenantId", 1, "uname1", "tenantId", 2, "uname2");
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertEquals(SkipScanFilter.class, filter.getClass());
}
 
Example #14
Source File: RegionCoprocessorHost.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Supports Coprocessor 'bypass'.
 * @param row row to check
 * @param filter filter
 * @param put data to put if check succeeds
 * @return true or false to return to client if default processing should be bypassed, or null
 * otherwise
 */
public Boolean preCheckAndPut(final byte [] row, final Filter filter, final Put put)
  throws IOException {
  boolean bypassable = true;
  boolean defaultResult = false;
  if (coprocEnvironments.isEmpty()) {
    return null;
  }
  return execOperationWithResult(
    new ObserverOperationWithResult<RegionObserver, Boolean>(regionObserverGetter,
      defaultResult, bypassable) {
      @Override
      public Boolean call(RegionObserver observer) throws IOException {
        return observer.preCheckAndPut(this, row, filter, put, getResult());
      }
    });
}
 
Example #15
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testLikeOptKeyExpression() throws SQLException {
    String tenantId = "000000000000001";
    String keyPrefix = "002";
    String likeArg = keyPrefix + "%003%";
    String query = "select * from atable where organization_id = ? and entity_id  LIKE '" + likeArg + "'";
    List<Object> binds = Arrays.<Object>asList(tenantId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();

    Filter filter = scan.getFilter();
    assertNotNull(filter);
    assertEquals(
            rowKeyFilter(like(
                ENTITY_ID,
                likeArg)),
            filter);

    byte[] startRow = ByteUtil.concat(
        PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15));
    assertArrayEquals(startRow, scan.getStartRow());
    byte[] stopRow = ByteUtil.concat(
        PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)),15));
    assertArrayEquals(stopRow, scan.getStopRow());
}
 
Example #16
Source File: WhereClauseCompileTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testInListWithAnd1Filter() throws SQLException {
    String tenantId1 = "000000000000001";
    String tenantId2 = "000000000000002";
    String tenantId3 = "000000000000003";
    String entityId = "00000000000000X";
    String query = String.format("select * from %s where organization_id IN ('%s','%s','%s') AND entity_id='%s'",
            ATABLE_NAME, tenantId1, tenantId3, tenantId2, entityId);
    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(
        new SkipScanFilter(
            ImmutableList.of(
                Arrays.asList(
                    pointRange(tenantId1),
                    pointRange(tenantId2),
                    pointRange(tenantId3)),
                Arrays.asList(pointRange(entityId))),
            plan.getContext().getResolver().getTables().get(0).getTable().getRowKeySchema()),
        filter);
}
 
Example #17
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiRVCExpressionsCombinedWithAnd() throws SQLException {
    String lowerTenantId = "000000000000001";
    String lowerParentId = "000000000000002";
    Date lowerCreatedDate = new Date(System.currentTimeMillis());
    String upperTenantId = "000000000000008";
    String upperParentId = "000000000000009";
    
    String query = "select * from entity_history where (organization_id, parent_id, created_date) >= (?, ?, ?) AND (organization_id, parent_id) <= (?, ?)";
    List<Object> binds = Arrays.<Object>asList(lowerTenantId, lowerParentId, lowerCreatedDate, upperTenantId, upperParentId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNull(filter);
    byte[] expectedStartRow = ByteUtil.concat(
        PVarchar.INSTANCE.toBytes(lowerTenantId), PVarchar.INSTANCE.toBytes(lowerParentId), PDate.INSTANCE.toBytes(lowerCreatedDate));
    byte[] expectedStopRow = ByteUtil.nextKey(ByteUtil.concat(PVarchar.INSTANCE.toBytes(upperTenantId), PVarchar.INSTANCE.toBytes(upperParentId)));
    assertArrayEquals(expectedStartRow, scan.getStartRow());
    assertArrayEquals(expectedStopRow, scan.getStopRow());
}
 
Example #18
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testTrailingIsNull() throws Exception {
    String baseTableDDL = "CREATE TABLE t(\n " + 
            "  a VARCHAR,\n" + 
            "  b VARCHAR,\n" + 
            "  CONSTRAINT pk PRIMARY KEY (a, b))";
    Connection conn = DriverManager.getConnection(getUrl());
    conn.createStatement().execute(baseTableDDL);
    conn.close();
    
    String query = "SELECT * FROM t WHERE a = 'a' and b is null";
    StatementContext context = compileStatement(query, Collections.<Object>emptyList());
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNull(filter);
    assertArrayEquals(Bytes.toBytes("a"), scan.getStartRow());
    assertArrayEquals(ByteUtil.concat(Bytes.toBytes("a"), QueryConstants.SEPARATOR_BYTE_ARRAY, QueryConstants.SEPARATOR_BYTE_ARRAY), scan.getStopRow());
}
 
Example #19
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testTrailingIsNullWithOr() throws Exception {
    String baseTableDDL = "CREATE TABLE t(\n " + 
            "  a VARCHAR,\n" + 
            "  b VARCHAR,\n" + 
            "  CONSTRAINT pk PRIMARY KEY (a, b))";
    Connection conn = DriverManager.getConnection(getUrl());
    conn.createStatement().execute(baseTableDDL);
    conn.close();
    
    String query = "SELECT * FROM t WHERE a = 'a' and (b is null or b = 'b')";
    StatementContext context = compileStatement(query, Collections.<Object>emptyList());
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertTrue(filter instanceof SkipScanFilter);
    SkipScanFilter skipScan = (SkipScanFilter)filter;
    List<List<KeyRange>>slots = skipScan.getSlots();
    assertEquals(2,slots.size());
    assertEquals(1,slots.get(0).size());
    assertEquals(2,slots.get(1).size());
    assertEquals(KeyRange.getKeyRange(Bytes.toBytes("a")), slots.get(0).get(0));
    assertTrue(KeyRange.IS_NULL_RANGE == slots.get(1).get(0));
    assertEquals(KeyRange.getKeyRange(Bytes.toBytes("b")), slots.get(1).get(1));
    assertArrayEquals(Bytes.toBytes("a"), scan.getStartRow());
    assertArrayEquals(ByteUtil.concat(Bytes.toBytes("a"), QueryConstants.SEPARATOR_BYTE_ARRAY, Bytes.toBytes("b"), QueryConstants.SEPARATOR_BYTE_ARRAY), scan.getStopRow());
}
 
Example #20
Source File: WhereCompilerTest.java    From phoenix with 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 #21
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrSameColRangeExpression() throws SQLException {
    String query = "select * from atable where substr(organization_id,1,3) = ? or organization_id LIKE 'foo%'";
    List<Object> binds = Arrays.<Object>asList("00D");
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();

    assertNotNull(filter);
    assertTrue(filter instanceof SkipScanFilter);
    ScanRanges scanRanges = context.getScanRanges();
    assertNotNull(scanRanges);
    List<List<KeyRange>> ranges = scanRanges.getRanges();
    assertEquals(1,ranges.size());
    List<List<KeyRange>> expectedRanges = Collections.singletonList(Arrays.asList(
            PChar.INSTANCE.getKeyRange(
                    StringUtil.padChar(PChar.INSTANCE.toBytes("00D"),15), true,
                    StringUtil.padChar(ByteUtil.nextKey(PChar.INSTANCE.toBytes("00D")),15), false),
            PChar.INSTANCE.getKeyRange(
                    StringUtil.padChar(PChar.INSTANCE.toBytes("foo"),15), true,
                    StringUtil.padChar(ByteUtil.nextKey(PChar.INSTANCE.toBytes("foo")),15), false)));
    assertEquals(expectedRanges, ranges);
}
 
Example #22
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * With the leading row key col missing Phoenix won't be able to optimize
 * and provide the start row for the scan.
 * 
 * Table entity_history has the row key defined as (organization_id, parent_id, created_date, entity_history_id). 
 * This test uses (parent_id, entity_id) in RVC. Start row should be empty.
 * @throws SQLException
 */

@Test
public void testRVCExpressionWithoutLeadingColOfRowKey() throws SQLException {
    
    String parentId = "000000000000002";
    String entityHistId = "000000000000003";
    
    String query = "select * from entity_history where (parent_id, entity_history_id) >= (?,?)";
    List<Object> binds = Arrays.<Object>asList(parentId, entityHistId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNotNull(filter);
    assertTrue(filter instanceof RowKeyComparisonFilter);
    assertArrayEquals(HConstants.EMPTY_START_ROW, scan.getStartRow());
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
}
 
Example #23
Source File: WhereCompilerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testInListFilter() throws SQLException {
    String tenantId1 = "000000000000001";
    String tenantId2 = "000000000000002";
    String tenantId3 = "000000000000003";
    String query = String.format("select * from %s where organization_id IN ('%s','%s','%s')",
            ATABLE_NAME, tenantId1, tenantId3, tenantId2);
    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();
    byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId1);
    assertArrayEquals(startRow, scan.getStartRow());
    byte[] stopRow = PVarchar.INSTANCE.toBytes(tenantId3);
    assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());

    Filter filter = scan.getFilter();
    assertEquals(
        new SkipScanFilter(
            ImmutableList.of(Arrays.asList(
                pointRange(tenantId1),
                pointRange(tenantId2),
                pointRange(tenantId3))),
            plan.getContext().getResolver().getTables().get(0).getTable().getRowKeySchema()),
        filter);
}
 
Example #24
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * With the leading row key col missing Phoenix won't be able to optimize
 * and provide the start row for the scan.
 * 
 * Table entity_history has the row key defined as (organization_id, parent_id, created_date, entity_history_id). 
 * This test uses (parent_id, entity_id) in RVC. Start row should be empty.
 * @throws SQLException
 */

@Test
public void testRVCExpressionWithoutLeadingColOfRowKey() throws SQLException {
    
    String parentId = "000000000000002";
    String entityHistId = "000000000000003";
    
    String query = "select * from entity_history where (parent_id, entity_history_id) >= (?,?)";
    List<Object> binds = Arrays.<Object>asList(parentId, entityHistId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNotNull(filter);
    assertTrue(filter instanceof RowKeyComparisonFilter);
    assertArrayEquals(HConstants.EMPTY_START_ROW, scan.getStartRow());
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
}
 
Example #25
Source File: LocationRunner.java    From BigDataArchitect with Apache License 2.0 6 votes vote down vote up
@Override
protected Filter fetchHbaseFilter() {
    FilterList list = new FilterList();
    String[] columns = new String[] { EventLogConstants.LOG_COLUMN_NAME_PLATFORM, // 平台
            EventLogConstants.LOG_COLUMN_NAME_SERVER_TIME, // 服务器时间戳
            EventLogConstants.LOG_COLUMN_NAME_UUID, // 用户id
            EventLogConstants.LOG_COLUMN_NAME_SESSION_ID, // 会话id
            EventLogConstants.LOG_COLUMN_NAME_COUNTRY, // 国家
            EventLogConstants.LOG_COLUMN_NAME_PROVINCE, // 省份
            EventLogConstants.LOG_COLUMN_NAME_CITY, // 城市
            EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME, // 事件名称
    };
    list.addFilter(this.getColumnFilter(columns));
    // 过滤只需要pageview事件
    list.addFilter(new SingleColumnValueFilter(LocationMapper.family, Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME), CompareOp.EQUAL, Bytes.toBytes(EventEnum.PAGEVIEW.alias)));
    return list;
}
 
Example #26
Source File: GenericAggregateReader.java    From Eagle with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param ed                Entity Definition
 * @param partitions        Partition values
 * @param startTime         Start time
 * @param endTime           End time
 * @param filter            HBase filter for scanning
 * @param lastScanKey       Last HBase scan row key in String
 * @param outputQualifiers  HBase output qualifiers in bytes
 * @param prefix            HBase prefix, not necessary except for GenericMetric query
 * @param condition         GroupAggregateCondition Object
 *
 * @see org.apache.eagle.query.aggregate.AggregateCondition
 */
public GenericAggregateReader(EntityDefinition ed,
                               List<String> partitions,
                               Date startTime,
                               Date endTime,
                               Filter filter,
                               String lastScanKey,
                               byte[][] outputQualifiers,
                               String prefix,
                               AggregateCondition condition) {
	super(ed, partitions, startTime, endTime, filter, lastScanKey, outputQualifiers, prefix);
	this.ed = ed;
	this.startTime = startTime.getTime();
	this.endTime = endTime.getTime();
	this.aggregateCondition = condition;
}
 
Example #27
Source File: HbaseQuery.java    From tephra with MIT License 5 votes vote down vote up
/**
 * 获取过滤器。
 *
 * @return 过滤器。
 */
public synchronized Filter getFilter() {
    if (pageSize > 0) {
        addFilter(new PageFilter(pageSize));
        pageSize = 0L;
    }

    return filters;
}
 
Example #28
Source File: HBaseFilterBuilder.java    From pxf with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the HBase {@link Filter} object after visiting the expression tree.
 *
 * @return filter object
 */
public Filter build() {
    if (!filterQueue.isEmpty()) {
        throw new IllegalStateException("Filter queue is not empty after visiting all nodes");
    }
    return currentFilter;
}
 
Example #29
Source File: HBaseFilterBuilderTest.java    From pxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterWithIncompatiblePredicate() throws Exception {
    // ((_1_ LIKE row1 AND _2_ < 999) AND _1_ = seq)
    Filter filter = helper("a1c25s4drow1o7a2c23s3d999o1l0a1c25s3dseqo5l0", tupleDescription);
    assertNotNull(filter);
    assertTrue(filter instanceof FilterList);
    FilterList filterList = (FilterList) filter;
    assertEquals(FilterList.Operator.MUST_PASS_ALL, filterList.getOperator());

    // LIKE is not supported so it gets dropped
    assertNotNull(filterList.getFilters());
    assertEquals(2, filterList.getFilters().size());

    Filter left = filterList.getFilters().get(0);
    Filter right = filterList.getFilters().get(1);
    assertTrue(left instanceof SingleColumnValueFilter);
    assertTrue(right instanceof SingleColumnValueFilter);

    SingleColumnValueFilter scvFilterLeft = (SingleColumnValueFilter) left;
    SingleColumnValueFilter scvFilterRight = (SingleColumnValueFilter) right;

    assertEquals(families[2], scvFilterLeft.getFamily());
    assertEquals(qualifiers[2], scvFilterLeft.getQualifier());
    assertEquals(CompareFilter.CompareOp.LESS, scvFilterLeft.getOperator());
    assertEquals(0, scvFilterLeft.getComparator().compareTo("999".getBytes()));

    assertEquals(families[1], scvFilterRight.getFamily());
    assertEquals(qualifiers[1], scvFilterRight.getQualifier());
    assertEquals(CompareFilter.CompareOp.EQUAL, scvFilterRight.getOperator());
    assertEquals(0, scvFilterRight.getComparator().compareTo("seq".getBytes()));
}
 
Example #30
Source File: SelectStatementRewriterTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testLHSLiteralCollapseAnd() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where '" + tenantId + "'=organization_id and 0=a_integer";
    Filter filter = compileStatement(query);
    assertEquals(
            singleKVFilter(constantComparison(
                CompareOp.EQUAL,
                A_INTEGER,
                0)),
            filter);
}