@Test public void testNestedLogicalOperators() throws Exception { Filter filter = helper("a1c1082s10d2008-02-01o2a1c1082s10d2008-12-01o1a0c23s4d1200o2l0l1", tupleDescription); assertNotNull(filter); assertTrue(filter instanceof FilterList); FilterList filterList = (FilterList) filter; assertEquals(FilterList.Operator.MUST_PASS_ONE, filterList.getOperator()); 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 FilterList); SingleColumnValueFilter scvFilterLeft = (SingleColumnValueFilter) left; FilterList scvFilterListRight = (FilterList) right; assertEquals(families[1], scvFilterLeft.getFamily()); assertEquals(qualifiers[1], scvFilterLeft.getQualifier()); assertEquals(CompareFilter.CompareOp.GREATER, scvFilterLeft.getOperator()); assertEquals(0, scvFilterLeft.getComparator().compareTo("2008-02-01".getBytes())); assertEquals(FilterList.Operator.MUST_PASS_ALL, scvFilterListRight.getOperator()); assertNotNull(scvFilterListRight.getFilters()); assertEquals(2, scvFilterListRight.getFilters().size()); left = scvFilterListRight.getFilters().get(0); right = scvFilterListRight.getFilters().get(1); assertTrue(left instanceof SingleColumnValueFilter); assertTrue(right instanceof SingleColumnValueFilter); scvFilterLeft = (SingleColumnValueFilter) left; SingleColumnValueFilter scvFilterRight = (SingleColumnValueFilter) right; assertEquals(families[1], scvFilterLeft.getFamily()); assertEquals(qualifiers[1], scvFilterLeft.getQualifier()); assertEquals(CompareFilter.CompareOp.LESS, scvFilterLeft.getOperator()); assertEquals(0, scvFilterLeft.getComparator().compareTo("2008-12-01".getBytes())); assertEquals(families[0], scvFilterRight.getFamily()); assertEquals(qualifiers[0], scvFilterRight.getQualifier()); assertEquals(CompareFilter.CompareOp.GREATER, scvFilterRight.getOperator()); assertEquals(0, scvFilterRight.getComparator().compareTo("1200".getBytes())); }
private ByteArrayComparable getComparator(int type, OperandNode data) { ByteArrayComparable result; switch (DataType.get(type)) { case TEXT: result = new BinaryComparator(Bytes.toBytes(data.toString())); break; case SMALLINT: case INTEGER: result = new HBaseIntegerComparator(Long.parseLong(data.toString())); break; case BIGINT: case REAL: switch (data.getDataType()) { case BIGINT: case INTEGER: case SMALLINT: result = new HBaseIntegerComparator(Long.parseLong(data.toString())); break; case REAL: result = new HBaseFloatComparator(Float.parseFloat(data.toString())); break; case NUMERIC: case FLOAT8: result = new HBaseDoubleComparator(Double.parseDouble(data.toString())); break; default: result = null; break; } break; case FLOAT8: result = new HBaseDoubleComparator(Double.parseDouble(data.toString())); break; default: throw new IllegalArgumentException(String.format("unsupported column type for filtering %d", type)); } return result; }
HBaseFilterBuilder implements TreeVisitor { private ByteArrayComparable getComparator(int type, OperandNode data) { ByteArrayComparable result; switch (DataType.get(type)) { case TEXT: result = new BinaryComparator(Bytes.toBytes(data.toString())); break; case SMALLINT: case INTEGER: result = new HBaseIntegerComparator(Long.parseLong(data.toString())); break; case BIGINT: case REAL: switch (data.getDataType()) { case BIGINT: case INTEGER: case SMALLINT: result = new HBaseIntegerComparator(Long.parseLong(data.toString())); break; case REAL: result = new HBaseFloatComparator(Float.parseFloat(data.toString())); break; case NUMERIC: case FLOAT8: result = new HBaseDoubleComparator(Double.parseDouble(data.toString())); break; default: result = null; break; } break; case FLOAT8: result = new HBaseDoubleComparator(Double.parseDouble(data.toString())); break; default: throw new IllegalArgumentException(String.format("unsupported column type for filtering %d", type)); } return result; } }
HBaseFilterBuilder implements TreeVisitor { private ByteArrayComparable getComparator(int type, OperandNode data) { ByteArrayComparable result; switch (DataType.get(type)) { case TEXT: result = new BinaryComparator(Bytes.toBytes(data.toString())); break; case SMALLINT: case INTEGER: result = new HBaseIntegerComparator(Long.parseLong(data.toString())); break; case BIGINT: case REAL: switch (data.getDataType()) { case BIGINT: case INTEGER: case SMALLINT: result = new HBaseIntegerComparator(Long.parseLong(data.toString())); break; case REAL: result = new HBaseFloatComparator(Float.parseFloat(data.toString())); break; case NUMERIC: case FLOAT8: result = new HBaseDoubleComparator(Double.parseDouble(data.toString())); break; default: result = null; break; } break; case FLOAT8: result = new HBaseDoubleComparator(Double.parseDouble(data.toString())); break; default: throw new IllegalArgumentException(String.format("unsupported column type for filtering %d", type)); } return result; } HBaseFilterBuilder(HBaseTupleDescription tupleDescription); }
HBaseFilterBuilder implements TreeVisitor { private ByteArrayComparable getComparator(int type, OperandNode data) { ByteArrayComparable result; switch (DataType.get(type)) { case TEXT: result = new BinaryComparator(Bytes.toBytes(data.toString())); break; case SMALLINT: case INTEGER: result = new HBaseIntegerComparator(Long.parseLong(data.toString())); break; case BIGINT: case REAL: switch (data.getDataType()) { case BIGINT: case INTEGER: case SMALLINT: result = new HBaseIntegerComparator(Long.parseLong(data.toString())); break; case REAL: result = new HBaseFloatComparator(Float.parseFloat(data.toString())); break; case NUMERIC: case FLOAT8: result = new HBaseDoubleComparator(Double.parseDouble(data.toString())); break; default: result = null; break; } break; case FLOAT8: result = new HBaseDoubleComparator(Double.parseDouble(data.toString())); break; default: throw new IllegalArgumentException(String.format("unsupported column type for filtering %d", type)); } return result; } HBaseFilterBuilder(HBaseTupleDescription tupleDescription); @Override Node before(Node node, final int level); @Override Node visit(Node node, final int level); @Override Node after(Node node, final int level); Filter build(); byte[] getStartKey(); byte[] getEndKey(); }
HBaseFilterBuilder implements TreeVisitor { private ByteArrayComparable getComparator(int type, OperandNode data) { ByteArrayComparable result; switch (DataType.get(type)) { case TEXT: result = new BinaryComparator(Bytes.toBytes(data.toString())); break; case SMALLINT: case INTEGER: result = new HBaseIntegerComparator(Long.parseLong(data.toString())); break; case BIGINT: case REAL: switch (data.getDataType()) { case BIGINT: case INTEGER: case SMALLINT: result = new HBaseIntegerComparator(Long.parseLong(data.toString())); break; case REAL: result = new HBaseFloatComparator(Float.parseFloat(data.toString())); break; case NUMERIC: case FLOAT8: result = new HBaseDoubleComparator(Double.parseDouble(data.toString())); break; default: result = null; break; } break; case FLOAT8: result = new HBaseDoubleComparator(Double.parseDouble(data.toString())); break; default: throw new IllegalArgumentException(String.format("unsupported column type for filtering %d", type)); } return result; } HBaseFilterBuilder(HBaseTupleDescription tupleDescription); @Override Node before(Node node, final int level); @Override Node visit(Node node, final int level); @Override Node after(Node node, final int level); Filter build(); byte[] getStartKey(); byte[] getEndKey();  }