类org.apache.hadoop.hbase.filter.Filter源码实例Demo

下面列出了怎么用org.apache.hadoop.hbase.filter.Filter的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hbase   文件: PerformanceEvaluation.java
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;
}
 
源代码2 项目: phoenix   文件: WhereOptimizerTest.java
@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());
}
 
源代码3 项目: phoenix   文件: WhereOptimizerTest.java
@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());
}
 
源代码4 项目: phoenix   文件: WhereOptimizerTest.java
@Test
public void testNullAtStartOfRVC() throws SQLException {
    String tenantId = null;
    String parentId = "000000000000002";
    Date createdDate = new Date(System.currentTimeMillis());
    
    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(new byte[15], ByteUtil.previousKey(PChar.INSTANCE.toBytes(parentId)), PDate.INSTANCE.toBytes(createdDate));
    assertArrayEquals(expectedStartRow, scan.getStartRow());
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
}
 
源代码5 项目: phoenix   文件: WhereCompilerTest.java
@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());
}
 
源代码6 项目: phoenix   文件: WhereOptimizerTest.java
@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());
}
 
源代码7 项目: phoenix   文件: WhereClauseCompileTest.java
@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());
}
 
源代码8 项目: Eagle   文件: GenericAggregateReader.java
/**
 *
 * @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;
}
 
源代码9 项目: BigDataArchitect   文件: LocationRunner.java
@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;
}
 
源代码10 项目: phoenix   文件: WhereOptimizerTest.java
/**
 * 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());
}
 
源代码11 项目: phoenix   文件: WhereCompilerTest.java
@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);
}
 
源代码12 项目: phoenix   文件: WhereOptimizerTest.java
@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);
}
 
源代码13 项目: phoenix   文件: WhereOptimizerTest.java
@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());
}
 
源代码14 项目: phoenix   文件: WhereOptimizerTest.java
@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());
}
 
源代码15 项目: phoenix   文件: WhereClauseCompileTest.java
@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);
}
 
源代码16 项目: phoenix   文件: WhereCompilerTest.java
@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());
}
 
源代码17 项目: hbase   文件: RegionCoprocessorHost.java
/**
 * 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());
      }
    });
}
 
源代码18 项目: phoenix   文件: WhereCompilerTest.java
@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);
}
 
/**
 * 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));
}
 
源代码20 项目: Eagle   文件: AbstractHBaseLogReader.java
/**
 * <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);
		}
	}
}
 
源代码21 项目: phoenix   文件: WhereOptimizerTest.java
@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());
}
 
源代码22 项目: phoenix   文件: WhereCompilerTest.java
@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);
}
 
源代码23 项目: phoenix   文件: WhereOptimizerTest.java
@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());
}
 
源代码24 项目: phoenix   文件: WhereOptimizerTest.java
/**
 * 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());
}
 
源代码25 项目: phoenix   文件: WhereOptimizerTest.java
@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());
}
 
源代码26 项目: phoenix   文件: WhereOptimizerTest.java
@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());
}
 
源代码27 项目: phoenix   文件: WhereOptimizerTest.java
@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());
}
 
源代码28 项目: java-docs-samples   文件: Filters.java
public static void filterLimitCellsPerRowOffset(
    String projectId, String instanceId, String tableId) {
  // A filter that skips the first 2 cells per row
  Filter filter = new ColumnPaginationFilter(Integer.MAX_VALUE, 2);
  Scan scan = new Scan().setFilter(filter);
  readWithFilter(projectId, instanceId, tableId, scan);
}
 
源代码29 项目: eagle   文件: TestHBaseFilterBuilder.java
private Filter buildFilter(String query) throws EagleQueryParseException {
    ORExpression expression = new EagleQueryParser(query).parse();
    HBaseFilterBuilder builder = new HBaseFilterBuilder(ed, expression);
    Filter filterList = builder.buildFilters();
    LOG.info("\n" + expression + " \n=> " + filterList);
    return filterList;
}
 
源代码30 项目: hbase   文件: MetaBrowser.java
private Scan buildScan() {
  final Scan metaScan = new Scan()
    .addFamily(HConstants.CATALOG_FAMILY)
    .readVersions(1)
    .setLimit((scanLimit != null ? scanLimit : SCAN_LIMIT_DEFAULT) + 1);
  if (scanStart != null) {
    metaScan.withStartRow(scanStart, false);
  }
  final Filter filter = buildScanFilter();
  if (filter != null) {
    metaScan.setFilter(filter);
  }
  return metaScan;
}
 
 类所在包
 同包方法