Java Code Examples for org.apache.hadoop.hbase.filter.CompareFilter.CompareOp#EQUAL
The following examples show how to use
org.apache.hadoop.hbase.filter.CompareFilter.CompareOp#EQUAL .
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: ParseNodeRewriter.java From phoenix with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public ParseNode visitLeave(final ComparisonParseNode node, List<ParseNode> nodes) throws SQLException { ParseNode normNode = leaveCompoundNode(node, nodes, new CompoundNodeFactory() { @Override public ParseNode createNode(List<ParseNode> children) { return NODE_FACTORY.comparison(node.getFilterOp(), children.get(0), children.get(1)); } }); CompareOp op = node.getFilterOp(); if (op == CompareOp.EQUAL || op == CompareOp.NOT_EQUAL) { // Rewrite row value constructor in = or != expression, as this is the same as if it was // used in an equality expression for each individual part. ParseNode lhs = normNode.getChildren().get(0); ParseNode rhs = normNode.getChildren().get(1); if (lhs instanceof RowValueConstructorParseNode || rhs instanceof RowValueConstructorParseNode) { List<ParseNode> andNodes = Lists.newArrayListWithExpectedSize(Math.max(lhs.getChildren().size(), rhs.getChildren().size())); rewriteRowValueConstuctorEqualityComparison(lhs,rhs,andNodes); normNode = NODE_FACTORY.and(andNodes); if (op == CompareOp.NOT_EQUAL) { normNode = NODE_FACTORY.not(normNode); } } } return normNode; }
Example 2
Source File: WhereOptimizer.java From phoenix with Apache License 2.0 | 6 votes |
@Override public SortOrder getSortOrder() { //See PHOENIX-4969: Clean up and unify code paths for RVCs with // respect to Optimizations for SortOrder //Handle the different paths for InList vs Normal Comparison //The code paths in InList assume the sortOrder is ASC for // their optimizations //The code paths for Comparisons on RVC rewrite equality, // for the non-equality cases return actual sort order //This work around should work // but a more general approach can be taken. if(rvcElementOp == CompareOp.EQUAL || rvcElementOp == CompareOp.NOT_EQUAL){ return SortOrder.ASC; } return childPart.getColumn().getSortOrder(); }
Example 3
Source File: HBaseTest.java From xxhadoop with Apache License 2.0 | 6 votes |
@Test public void testScan() throws IOException { Connection connection = admin.getConnection(); Table table = connection.getTable(TableName.valueOf("tbl_girls")); Scan scan = new Scan(Bytes.toBytes("0001"), Bytes.toBytes("0004")); // RowKeyFilter Filter filter = new PrefixFilter(Bytes.toBytes("000")); scan.setFilter(filter); Filter filter2 = new RowFilter(CompareOp.EQUAL, new SubstringComparator("000")); scan.setFilter(filter2); //BinaryComparator binaryComparator = new BinaryComparator(Bytes.toBytes(29)); Filter filter3 = new SingleColumnValueFilter(Bytes.toBytes("base_info"), Bytes.toBytes("age"), CompareOp.GREATER, Bytes.toBytes(29)); scan.setFilter(filter3); ResultScanner resultScanner = table.getScanner(scan); for (Result result : resultScanner) { LOGGER.info(result.toString()); int value = Bytes.toInt(result.getValue(Bytes.toBytes("base_info"), Bytes.toBytes("age"))); LOGGER.info(String.valueOf(value)); } }
Example 4
Source File: HBaseFilterBuilder.java From eagle with Apache License 2.0 | 6 votes |
/** * Convert ComparisonOperator to native HBase CompareOp Support: =, =~,CONTAINS,<,<=,>,>=,!=,!=~ * * @param comp * @return */ protected static CompareOp convertToHBaseCompareOp(ComparisonOperator comp) { if (comp == ComparisonOperator.EQUAL || comp == ComparisonOperator.LIKE || comp == ComparisonOperator.CONTAINS || comp == ComparisonOperator.IN || comp == ComparisonOperator.IS) { return CompareOp.EQUAL; } else if (comp == ComparisonOperator.LESS) { return CompareOp.LESS; } else if (comp == ComparisonOperator.LESS_OR_EQUAL) { return CompareOp.LESS_OR_EQUAL; } else if (comp == ComparisonOperator.GREATER) { return CompareOp.GREATER; } else if (comp == ComparisonOperator.GREATER_OR_EQUAL) { return CompareOp.GREATER_OR_EQUAL; } else if (comp == ComparisonOperator.NOT_EQUAL || comp == ComparisonOperator.NOT_LIKE || comp == ComparisonOperator.NOT_CONTAINS || comp == ComparisonOperator.IS_NOT || comp == ComparisonOperator.NOT_IN) { return CompareOp.NOT_EQUAL; } else { LOG.error("{} operation is not supported now\n", comp); throw new IllegalArgumentException("Illegal operation: " + comp + ", avaliable options: " + Arrays.toString(ComparisonOperator.values())); } }
Example 5
Source File: HBaseFilterBuilder.java From Eagle with Apache License 2.0 | 5 votes |
/** * _charset is used to decode the byte array, in hbase server, RegexStringComparator uses the same * charset to decode the byte array stored in qualifier * for tag filter regex, it's always ISO-8859-1 as it only comes from String's hashcode (Integer) * Note: regex comparasion is to compare String */ protected Filter buildTagFilter(Map<String, List<String>> tagFilters){ RegexStringComparator regexStringComparator = new RegexStringComparator(buildTagFilterRegex(tagFilters)); regexStringComparator.setCharset(_charset); RowFilter filter = new RowFilter(CompareOp.EQUAL, regexStringComparator); return filter; }
Example 6
Source File: HbaseServiceImpl.java From searchanalytics-bigdata with MIT License | 5 votes |
@Override public int numberOfTimesAFacetFilterClickedInLastAnHour(final String columnName, final String columnValue) { Scan scan = new Scan(); scan.addColumn(HbaseJsonEventSerializer.COLUMFAMILY_FILTERS_BYTES, Bytes.toBytes(columnName)); Filter filter = new SingleColumnValueFilter(HbaseJsonEventSerializer.COLUMFAMILY_FILTERS_BYTES, Bytes.toBytes(columnName), CompareOp.EQUAL, Bytes.toBytes(columnValue)); scan.setFilter(filter); DateTime dateTime = new DateTime(); try { scan.setTimeRange(dateTime.minusHours(1).getMillis(), dateTime.getMillis()); } catch (IOException e) { throw new RuntimeException(e); } int count = hbaseTemplate.find("searchclicks", scan, new RowMapper<String>() { @Override public String mapRow(Result result, int rowNum) throws Exception { byte[] value = result.getValue( HbaseJsonEventSerializer.COLUMFAMILY_FILTERS_BYTES, Bytes.toBytes(columnName)); if (value != null) { String facetValue = new String(value); LOG.debug("Facet field: {} and Facet Value: {}", new Object[] { columnName, facetValue }); } return null; } }).size(); LOG.debug("Checking numberOfTimesAFacetFilterClickedInLastAnHour done with count:{}", count); return count; }
Example 7
Source File: PhoenixRuntimeIT.java From phoenix with Apache License 2.0 | 5 votes |
private static Filter getUserTableAndViewsFilter() { SingleColumnValueFilter tableFilter = new SingleColumnValueFilter(TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.TABLE_TYPE_BYTES, CompareOp.EQUAL, Bytes.toBytes(PTableType.TABLE.getSerializedValue())); tableFilter.setFilterIfMissing(true); SingleColumnValueFilter viewFilter = new SingleColumnValueFilter(TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.TABLE_TYPE_BYTES, CompareOp.EQUAL, Bytes.toBytes(PTableType.VIEW.getSerializedValue())); viewFilter.setFilterIfMissing(true); FilterList filter = new FilterList(FilterList.Operator.MUST_PASS_ONE, Arrays.asList(new Filter[] {tableFilter, viewFilter})); return filter; }
Example 8
Source File: Filters.java From java-docs-samples with Apache License 2.0 | 5 votes |
public static void filterLimitColFamilyRegex( String projectId, String instanceId, String tableId) { // A filter that matches cells whose column family satisfies the given regex Filter filter = new FamilyFilter(CompareOp.EQUAL, new RegexStringComparator("stats_.*$")); Scan scan = new Scan().setFilter(filter); readWithFilter(projectId, instanceId, tableId, scan); }
Example 9
Source File: Filters.java From java-docs-samples with Apache License 2.0 | 5 votes |
public static void filterLimitColQualifierRegex( String projectId, String instanceId, String tableId) { // A filter that matches cells whose column qualifier satisfies the given regex Filter filter = new QualifierFilter(CompareOp.EQUAL, new RegexStringComparator("connected_.*$")); Scan scan = new Scan().setFilter(filter); readWithFilter(projectId, instanceId, tableId, scan); }
Example 10
Source File: AclService.java From Kylin with Apache License 2.0 | 5 votes |
@Override public List<ObjectIdentity> findChildren(ObjectIdentity parentIdentity) { List<ObjectIdentity> oids = new ArrayList<ObjectIdentity>(); HTableInterface htable = null; try { htable = HBaseConnection.get(hbaseUrl).getTable(aclTableName); Scan scan = new Scan(); SingleColumnValueFilter parentFilter = new SingleColumnValueFilter(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_PARENT_COLUMN), CompareOp.EQUAL, domainObjSerializer.serialize(new DomainObjectInfo(parentIdentity))); parentFilter.setFilterIfMissing(true); scan.setFilter(parentFilter); ResultScanner scanner = htable.getScanner(scan); for (Result result = scanner.next(); result != null; result = scanner.next()) { String id = Bytes.toString(result.getRow()); String type = Bytes.toString(result.getValue(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_TYPE_COLUMN))); oids.add(new ObjectIdentityImpl(type, id)); } } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(htable); } return oids; }
Example 11
Source File: Filters.java From java-docs-samples with Apache License 2.0 | 5 votes |
public static void filterComposingInterleave( String projectId, String instanceId, String tableId) { // A filter that matches cells with the value true OR with the column qualifier os_build Filter qualifierFilter = new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("os_build"))); Filter valueFilter = new ValueFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("true"))); FilterList filter = new FilterList(Operator.MUST_PASS_ONE); filter.addFilter(qualifierFilter); filter.addFilter(valueFilter); Scan scan = new Scan().setFilter(filter).setMaxVersions(); readWithFilter(projectId, instanceId, tableId, scan); }
Example 12
Source File: Reads.java From java-docs-samples with Apache License 2.0 | 5 votes |
public static void readFilter(String projectId, String instanceId, String tableId) { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. try (Connection connection = BigtableConfiguration.connect(projectId, instanceId)) { Table table = connection.getTable(TableName.valueOf(tableId)); ValueFilter valueFilter = new ValueFilter(CompareOp.EQUAL, new RegexStringComparator("PQ2A.*")); Scan scan = new Scan().setFilter(valueFilter); ResultScanner rows = table.getScanner(scan); for (Result row : rows) { printRow(row); } } catch (IOException e) { System.out.println( "Unable to initialize service client, as a network error occurred: \n" + e.toString()); } }
Example 13
Source File: EqualParseNode.java From phoenix with Apache License 2.0 | 4 votes |
@Override public CompareOp getFilterOp() { return CompareOp.EQUAL; }
Example 14
Source File: EqualParseNode.java From phoenix with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public CompareOp getFilterOp() { return CompareOp.EQUAL; }
Example 15
Source File: EqualParseNode.java From phoenix with Apache License 2.0 | 4 votes |
@Override public CompareOp getFilterOp() { return CompareOp.EQUAL; }
Example 16
Source File: ExpressionCompiler.java From phoenix with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Expression visitLeave(LikeParseNode node, List<Expression> children) throws SQLException { ParseNode lhsNode = node.getChildren().get(0); ParseNode rhsNode = node.getChildren().get(1); Expression lhs = children.get(0); Expression rhs = children.get(1); if ( rhs.getDataType() != null && lhs.getDataType() != null && !lhs.getDataType().isCoercibleTo(rhs.getDataType()) && !rhs.getDataType().isCoercibleTo(lhs.getDataType())) { throw TypeMismatchException.newException(lhs.getDataType(), rhs.getDataType(), node.toString()); } if (lhsNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)lhsNode, rhs); } if (rhsNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)rhsNode, lhs); } if (rhs instanceof LiteralExpression) { String pattern = (String)((LiteralExpression)rhs).getValue(); if (pattern == null || pattern.length() == 0) { return LiteralExpression.newConstant(null, rhs.isDeterministic()); } // TODO: for pattern of '%' optimize to strlength(lhs) > 0 // We can't use lhs IS NOT NULL b/c if lhs is NULL we need // to return NULL. int index = LikeExpression.indexOfWildcard(pattern); // Can't possibly be as long as the constant, then FALSE Integer lhsByteSize = lhs.getByteSize(); if (lhsByteSize != null && lhsByteSize < index) { return LiteralExpression.newConstant(false, rhs.isDeterministic()); } if (index == -1) { String rhsLiteral = LikeExpression.unescapeLike(pattern); if (lhsByteSize != null && lhsByteSize != rhsLiteral.length()) { return LiteralExpression.newConstant(false, rhs.isDeterministic()); } CompareOp op = node.isNegate() ? CompareOp.NOT_EQUAL : CompareOp.EQUAL; if (pattern.equals(rhsLiteral)) { return new ComparisonExpression(op, children); } else { rhs = LiteralExpression.newConstant(rhsLiteral, PDataType.CHAR, rhs.isDeterministic()); return new ComparisonExpression(op, Arrays.asList(lhs,rhs)); } } } Expression expression = new LikeExpression(children); if (node.isStateless()) { ImmutableBytesWritable ptr = context.getTempPtr(); if (!expression.evaluate(null, ptr)) { return LiteralExpression.newConstant(null, expression.isDeterministic()); } else { return LiteralExpression.newConstant(Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(ptr)) ^ node.isNegate(), expression.isDeterministic()); } } if (node.isNegate()) { expression = new NotExpression(expression); } return expression; }
Example 17
Source File: InListExpression.java From phoenix with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static Expression create (List<Expression> children, ImmutableBytesWritable ptr) throws SQLException { Expression firstChild = children.get(0); PDataType firstChildType = firstChild.getDataType(); boolean addedNull = false; List<Expression> keys = Lists.newArrayListWithExpectedSize(children.size()); List<Expression> coercedKeyExpressions = Lists.newArrayListWithExpectedSize(children.size()); keys.add(firstChild); coercedKeyExpressions.add(firstChild); for (int i = 1; i < children.size(); i++) { Expression rhs = children.get(i); if (rhs.evaluate(null, ptr)) { if (ptr.getLength() == 0) { if (!addedNull) { addedNull = true; keys.add(LiteralExpression.newConstant(null, PDataType.VARBINARY, true)); coercedKeyExpressions.add(LiteralExpression.newConstant(null, firstChildType, true)); } } else { // Don't specify the firstChild column modifier here, as we specify it in the LiteralExpression creation below try { firstChildType.coerceBytes(ptr, rhs.getDataType(), rhs.getColumnModifier(), null); keys.add(LiteralExpression.newConstant(ByteUtil.copyKeyBytesIfNecessary(ptr), PDataType.VARBINARY, firstChild.getColumnModifier(), true)); if(rhs.getDataType() == firstChildType) { coercedKeyExpressions.add(rhs); } else { coercedKeyExpressions.add(CoerceExpression.create(rhs, firstChildType)); } } catch (ConstraintViolationException e) { // Ignore and continue } } } } if (keys.size() == 1) { return LiteralExpression.newConstant(false, PDataType.BOOLEAN, true); } if (keys.size() == 2 && addedNull) { return LiteralExpression.newConstant(null, PDataType.BOOLEAN, true); } Expression expression; // TODO: if inChildren.isEmpty() then Oracle throws a type mismatch exception. This means // that none of the list elements match in type and there's no null element. We'd return // false in this case. Should we throw? if (keys.size() == 2) { expression = new ComparisonExpression(CompareOp.EQUAL, keys); } else { expression = new InListExpression(keys, coercedKeyExpressions); } return expression; }
Example 18
Source File: CreateTableCompiler.java From phoenix with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Iterator<Expression> visitEnter(ComparisonExpression node) { return node.getFilterOp() == CompareOp.EQUAL && node.getChildren().get(1).isStateless() && node.getChildren().get(1).isDeterministic() ? Iterators.singletonIterator(node.getChildren().get(0)) : super.visitEnter(node); }
Example 19
Source File: Filters.java From java-docs-samples with Apache License 2.0 | 4 votes |
public static void filterLimitRowRegex(String projectId, String instanceId, String tableId) { // A filter that matches cells from rows whose keys satisfy the given regex Filter filter = new RowFilter(CompareOp.EQUAL, new RegexStringComparator(".*#20190501$")); Scan scan = new Scan().setFilter(filter).setMaxVersions(); readWithFilter(projectId, instanceId, tableId, scan); }
Example 20
Source File: ExpressionCompiler.java From phoenix with Apache License 2.0 | 4 votes |
@Override public Expression visitLeave(LikeParseNode node, List<Expression> children) throws SQLException { ParseNode lhsNode = node.getChildren().get(0); ParseNode rhsNode = node.getChildren().get(1); Expression lhs = children.get(0); Expression rhs = children.get(1); if ( rhs.getDataType() != null && lhs.getDataType() != null && !lhs.getDataType().isCoercibleTo(rhs.getDataType()) && !rhs.getDataType().isCoercibleTo(lhs.getDataType())) { throw TypeMismatchException.newException(lhs.getDataType(), rhs.getDataType(), node.toString()); } if (lhsNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)lhsNode, rhs); } if (rhsNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)rhsNode, lhs); } if (rhs instanceof LiteralExpression) { String pattern = (String)((LiteralExpression)rhs).getValue(); if (pattern == null || pattern.length() == 0) { return LiteralExpression.newConstant(null, PBoolean.INSTANCE, rhs.getDeterminism()); } // TODO: for pattern of '%' optimize to strlength(lhs) > 0 // We can't use lhs IS NOT NULL b/c if lhs is NULL we need // to return NULL. int index = LikeExpression.indexOfWildcard(pattern); // Can't possibly be as long as the constant, then FALSE Integer lhsMaxLength = lhs.getMaxLength(); if (lhsMaxLength != null && lhsMaxLength < index) { return LiteralExpression.newConstant(false, rhs.getDeterminism()); } if (index == -1) { String rhsLiteral = LikeExpression.unescapeLike(pattern); if (node.getLikeType() == LikeType.CASE_SENSITIVE) { CompareOp op = node.isNegate() ? CompareOp.NOT_EQUAL : CompareOp.EQUAL; if (pattern.equals(rhsLiteral)) { return new ComparisonExpression(children, op); } else { rhs = LiteralExpression.newConstant(rhsLiteral, PChar.INSTANCE, rhs.getDeterminism()); return new ComparisonExpression(Arrays.asList(lhs,rhs), op); } } } else { byte[] wildcardString = new byte[pattern.length()]; byte[] wildcard = {StringUtil.MULTI_CHAR_LIKE}; StringUtil.fill(wildcardString, 0, pattern.length(), wildcard, 0, 1, false); if (pattern.equals(new String (wildcardString))) { List<Expression> compareChildren = Arrays.asList(lhs, NOT_NULL_STRING); return new ComparisonExpression(compareChildren, node.isNegate() ? CompareOp.LESS : CompareOp.GREATER_OR_EQUAL); } } } QueryServices services = context.getConnection().getQueryServices(); boolean useByteBasedRegex = services.getProps().getBoolean(QueryServices.USE_BYTE_BASED_REGEX_ATTRIB, QueryServicesOptions.DEFAULT_USE_BYTE_BASED_REGEX); Expression expression; if (useByteBasedRegex) { expression = ByteBasedLikeExpression.create(children, node.getLikeType()); } else { expression = StringBasedLikeExpression.create(children, node.getLikeType()); } if (ExpressionUtil.isConstant(expression)) { ImmutableBytesWritable ptr = context.getTempPtr(); if (!expression.evaluate(null, ptr)) { return LiteralExpression.newConstant(null, expression.getDeterminism()); } else { return LiteralExpression.newConstant(Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(ptr)) ^ node.isNegate(), expression.getDeterminism()); } } if (node.isNegate()) { expression = new NotExpression(expression); } return wrapGroupByExpression(expression); }