org.apache.hadoop.hbase.filter.CompareFilter.CompareOp Java Examples
The following examples show how to use
org.apache.hadoop.hbase.filter.CompareFilter.CompareOp.
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 |
@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 #2
Source File: WhereCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
@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 #3
Source File: WhereCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
@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 File: SortOrderExpressionTest.java From phoenix with Apache License 2.0 | 6 votes |
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 #5
Source File: ActiveMemberRunner.java From BigDataArchitect with Apache License 2.0 | 6 votes |
@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 #6
Source File: WhereCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
@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 #7
Source File: PageViewRunner.java From BigDataPlatform with GNU General Public License v3.0 | 6 votes |
@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 #8
Source File: WhereCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
@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 #9
Source File: WhereCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
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 #10
Source File: WhereCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
@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 #11
Source File: WhereCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
@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 #12
Source File: ByteUtil.java From phoenix with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #13
Source File: InvertFunction.java From phoenix with Apache License 2.0 | 6 votes |
/** * 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 #14
Source File: WhereCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
@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 #15
Source File: HbaseServiceImpl.java From searchanalytics-bigdata with MIT License | 6 votes |
@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 #16
Source File: WhereClauseCompileTest.java From phoenix with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 #17
Source File: WhereCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
@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 #18
Source File: ByteUtil.java From phoenix with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #19
Source File: SelectStatementRewriterTest.java From phoenix with Apache License 2.0 | 6 votes |
@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 File: ParseNodeFactory.java From phoenix with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #21
Source File: WhereClauseCompileTest.java From phoenix with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #22
Source File: InvertFunction.java From phoenix with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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 #23
Source File: WhereCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
@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 #24
Source File: ParseNodeFactory.java From phoenix with Apache License 2.0 | 6 votes |
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 #25
Source File: WhereClauseCompileTest.java From phoenix with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 #26
Source File: WhereOptimizer.java From phoenix with Apache License 2.0 | 6 votes |
@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 #27
Source File: InboundBounceRunner.java From BigDataPlatform with GNU General Public License v3.0 | 6 votes |
@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 #28
Source File: RoundFloorCeilExpressionsTest.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testFloorDecimalExpressionKeyRangeSimple() throws Exception { KeyPart baseKeyPart = getDecimalKeyPart(); ScalarFunction floorDecimalExpression = (ScalarFunction)FloorDecimalExpression.create(DUMMY_DECIMAL, 3); byte[] upperBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.239")); byte[] lowerBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.238")); KeyRange expectedKeyRange = KeyRange.getKeyRange(lowerBound, true, upperBound, false); KeyPart keyPart = floorDecimalExpression.newKeyPart(baseKeyPart); assertEquals(expectedKeyRange, keyPart.getKeyRange(CompareOp.EQUAL, LiteralExpression.newConstant(new BigDecimal("1.238"), PDecimal.INSTANCE))); }
Example #29
Source File: WhereOptimizer.java From phoenix with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Iterator<Expression> visitEnter(ComparisonExpression node) { Expression rhs = node.getChildren().get(1); if (!rhs.isStateless() || node.getFilterOp() == CompareOp.NOT_EQUAL) { return Iterators.emptyIterator(); } return Iterators.singletonIterator(node.getChildren().get(0)); }
Example #30
Source File: WhereCompilerTest.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testOrFilter() throws SQLException { String tenantId = "000000000000001"; String keyPrefix = "foo"; int aInt = 2; String query = "select * from atable where organization_id=? and (substr(entity_id,1,3)=? or a_integer=?)"; List<Object> binds = Arrays.<Object>asList(tenantId, keyPrefix, aInt); 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( singleKVFilter( // single b/c one column is a row key column or( constantComparison( CompareOp.EQUAL, new SubstrFunction(Arrays.<Expression> asList( new RowKeyColumnExpression( ENTITY_ID, new RowKeyValueAccessor(ATABLE.getPKColumns(), 1)), LiteralExpression.newConstant(1), LiteralExpression.newConstant(3))), keyPrefix), constantComparison( CompareOp.EQUAL, A_INTEGER, aInt))), filter); }