use of org.apache.kudu.client.KuduPredicate in project hive by apache.
the class TestKuduPredicateHandler method testComparisonPredicates.
@Test
public void testComparisonPredicates() throws Exception {
for (ColumnSchema col : SCHEMA.getColumns()) {
// Skip null and default columns because they don't have a value to use.
if (col.getName().equals("null") || col.getName().equals("default")) {
continue;
}
PrimitiveTypeInfo typeInfo = toHiveType(col.getType(), col.getTypeAttributes());
ExprNodeDesc colExpr = new ExprNodeColumnDesc(typeInfo, col.getName(), null, false);
ExprNodeDesc constExpr = new ExprNodeConstantDesc(typeInfo, ROW.getObject(col.getName()));
List<ExprNodeDesc> children = Lists.newArrayList();
children.add(colExpr);
children.add(constExpr);
for (GenericUDF udf : COMPARISON_UDFS) {
ExprNodeGenericFuncDesc predicateExpr = new ExprNodeGenericFuncDesc(typeInfo, udf, children);
// Verify KuduPredicateHandler.decompose
HiveStoragePredicateHandler.DecomposedPredicate decompose = KuduPredicateHandler.decompose(predicateExpr, SCHEMA);
// Binary predicates are not supported. (HIVE-11370)
if (col.getName().equals("binary")) {
assertNull(decompose);
} else {
assertNotNull(String.format("Unsupported comparison UDF and type (%s, %s)", udf, typeInfo), decompose);
assertNotNull(String.format("Unsupported comparison UDF and type (%s, %s)", udf, typeInfo), decompose.pushedPredicate);
assertNull(String.format("Unsupported comparison UDF and type (%s, %s)", udf, typeInfo), decompose.residualPredicate);
List<KuduPredicate> predicates = expressionToPredicates(predicateExpr);
assertEquals(1, predicates.size());
scanWithPredicates(predicates);
}
}
}
}
use of org.apache.kudu.client.KuduPredicate in project hive by apache.
the class TestKuduPredicateHandler method testAndPredicates.
@Test
public void testAndPredicates() throws Exception {
for (ColumnSchema col : SCHEMA.getColumns()) {
// Skip null and default columns because they don't have a value to use.
if (col.getName().equals("null") || col.getName().equals("default")) {
continue;
}
PrimitiveTypeInfo typeInfo = toHiveType(col.getType(), col.getTypeAttributes());
ExprNodeDesc colExpr = new ExprNodeColumnDesc(typeInfo, col.getName(), null, false);
ExprNodeDesc constExpr = new ExprNodeConstantDesc(typeInfo, ROW.getObject(col.getName()));
List<ExprNodeDesc> children = Lists.newArrayList();
children.add(colExpr);
children.add(constExpr);
ExprNodeGenericFuncDesc gePredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPEqualOrGreaterThan(), children);
ExprNodeGenericFuncDesc lePredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPEqualOrLessThan(), children);
List<ExprNodeDesc> andChildren = Lists.newArrayList();
andChildren.add(gePredicateExpr);
andChildren.add(lePredicateExpr);
ExprNodeGenericFuncDesc andPredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPAnd(), andChildren);
// Verify KuduPredicateHandler.decompose
HiveStoragePredicateHandler.DecomposedPredicate decompose = KuduPredicateHandler.decompose(andPredicateExpr, SCHEMA);
// Binary predicates are not supported. (HIVE-11370)
if (col.getName().equals("binary")) {
assertNull(decompose);
} else {
assertNotNull(decompose);
assertNotNull(decompose.pushedPredicate);
assertNull(decompose.residualPredicate);
List<KuduPredicate> predicates = expressionToPredicates(decompose.pushedPredicate);
assertEquals(2, predicates.size());
scanWithPredicates(predicates);
// Also test NOT AND.
List<ExprNodeDesc> notChildren = Lists.newArrayList();
notChildren.add(andPredicateExpr);
ExprNodeGenericFuncDesc notPredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPNot(), notChildren);
// Verify KuduPredicateHandler.decompose
HiveStoragePredicateHandler.DecomposedPredicate decomposeNot = KuduPredicateHandler.decompose(notPredicateExpr, SCHEMA);
// See note in KuduPredicateHandler.newAnalyzer.
assertNull(decomposeNot);
List<KuduPredicate> notPredicates = expressionToPredicates(notPredicateExpr);
assertEquals(0, notPredicates.size());
}
}
}
use of org.apache.kudu.client.KuduPredicate in project hive by apache.
the class TestKuduPredicateHandler method testMixedPredicates.
@Test
public void testMixedPredicates() throws Exception {
for (ColumnSchema col : SCHEMA.getColumns()) {
// Skip binary columns because binary predicates are not supported. (HIVE-11370)
if (col.getName().equals("null") || col.getName().equals("default") || col.getName().equals("binary")) {
continue;
}
PrimitiveTypeInfo typeInfo = toHiveType(col.getType(), col.getTypeAttributes());
ExprNodeDesc colExpr = new ExprNodeColumnDesc(typeInfo, col.getName(), null, false);
ExprNodeDesc constExpr = new ExprNodeConstantDesc(typeInfo, ROW.getObject(col.getName()));
List<ExprNodeDesc> children = Lists.newArrayList();
children.add(colExpr);
children.add(constExpr);
ExprNodeGenericFuncDesc supportedPredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPEqualOrGreaterThan(), children);
ExprNodeGenericFuncDesc unsupportedPredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPUnsupported(), children);
List<ExprNodeDesc> andChildren = Lists.newArrayList();
andChildren.add(supportedPredicateExpr);
andChildren.add(unsupportedPredicateExpr);
ExprNodeGenericFuncDesc andPredicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPAnd(), andChildren);
// Verify KuduPredicateHandler.decompose
HiveStoragePredicateHandler.DecomposedPredicate decompose = KuduPredicateHandler.decompose(andPredicateExpr, SCHEMA);
assertNotNull(decompose);
assertNotNull(decompose.pushedPredicate);
assertNotNull(decompose.residualPredicate);
List<KuduPredicate> predicates = expressionToPredicates(decompose.pushedPredicate);
assertEquals(1, predicates.size());
scanWithPredicates(predicates);
}
}
use of org.apache.kudu.client.KuduPredicate in project hive by apache.
the class TestKuduPredicateHandler method testNotComparisonPredicates.
@Test
public void testNotComparisonPredicates() throws Exception {
for (ColumnSchema col : SCHEMA.getColumns()) {
// Skip binary columns because binary predicates are not supported. (HIVE-11370)
if (col.getName().equals("null") || col.getName().equals("default") || col.getName().equals("binary")) {
continue;
}
PrimitiveTypeInfo typeInfo = toHiveType(col.getType(), col.getTypeAttributes());
ExprNodeDesc colExpr = new ExprNodeColumnDesc(typeInfo, col.getName(), null, false);
ExprNodeDesc constExpr = new ExprNodeConstantDesc(typeInfo, ROW.getObject(col.getName()));
List<ExprNodeDesc> children = Lists.newArrayList();
children.add(colExpr);
children.add(constExpr);
for (GenericUDF udf : COMPARISON_UDFS) {
ExprNodeGenericFuncDesc childExpr = new ExprNodeGenericFuncDesc(typeInfo, udf, children);
List<ExprNodeDesc> notChildren = Lists.newArrayList();
notChildren.add(childExpr);
ExprNodeGenericFuncDesc predicateExpr = new ExprNodeGenericFuncDesc(typeInfo, new GenericUDFOPNot(), notChildren);
// Verify KuduPredicateHandler.decompose
HiveStoragePredicateHandler.DecomposedPredicate decompose = KuduPredicateHandler.decompose(predicateExpr, SCHEMA);
// See note in KuduPredicateHandler.newAnalyzer.
assertNull(decompose);
List<KuduPredicate> predicates = expressionToPredicates(predicateExpr);
if (udf instanceof GenericUDFOPEqual) {
// Kudu doesn't support !=.
assertTrue(predicates.isEmpty());
} else {
assertEquals(1, predicates.size());
scanWithPredicates(predicates);
}
}
}
}
use of org.apache.kudu.client.KuduPredicate in project gora by apache.
the class KuduStore method deleteByQuery.
@Override
public long deleteByQuery(Query<K, T> query) throws GoraException {
try {
long count = 0;
Column pkc = kuduMapping.getPrimaryKey().get(0);
ColumnSchema column = table.getSchema().getColumn(pkc.getName());
List<String> dbFields = new ArrayList<>();
dbFields.add(pkc.getName());
List<KuduPredicate> rangePredicates = KuduClientUtils.createRangePredicate(column, query.getStartKey(), query.getEndKey());
rangePredicates.add(KuduPredicate.newIsNotNullPredicate(column));
KuduScanner build = createScanner(rangePredicates, dbFields, query.getLimit());
while (build.hasMoreRows()) {
RowResultIterator nextRows = build.nextRows();
for (RowResult it : nextRows) {
count++;
K key = (K) KuduClientUtils.getObjectRow(it, pkc);
if (query.getFields() != null && query.getFields().length < kuduMapping.getFields().size()) {
Update updateOp = table.newUpdate();
PartialRow row = updateOp.getRow();
String[] avFields = getFieldsToQuery(query.getFields());
KuduClientUtils.addObjectRow(row, pkc, key);
for (String af : avFields) {
row.setNull(kuduMapping.getFields().get(af).getName());
}
session.apply(updateOp);
} else {
delete(key);
}
}
}
build.close();
return count;
} catch (Exception e) {
throw new GoraException(e);
}
}
Aggregations