Skip to content

Commit

Permalink
Add test case for multi fielded functions
Browse files Browse the repository at this point in the history
  • Loading branch information
apmoriarty committed Apr 29, 2024
1 parent 0139db6 commit a94b830
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,22 @@ public Set<String> getIngestTypesForLeaf(JexlNode node) {
* @return a set of ingest types
*/
public Set<String> getFieldsForLeaf(JexlNode node) {
Set<String> identifiers;
JexlNode deref = JexlASTHelper.dereference(node);
if (deref instanceof ASTFunctionNode) {
try {
return getFieldsForFunctionNode((ASTFunctionNode) deref);
identifiers = getFieldsForFunctionNode((ASTFunctionNode) deref);
} catch (Exception e) {
// if a FunctionsDescriptor throws an exception for any reason then return an empty collection
// so the node gets treated as an unknown type
return new HashSet<>();
}
} else {
identifiers = JexlASTHelper.getIdentifierNames(deref);
}

// @formatter:off
return JexlASTHelper.getIdentifierNames(deref)
.stream()
return identifiers.stream()
.map(JexlASTHelper::deconstructIdentifier)
.collect(Collectors.toSet());
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import datawave.webservice.query.configuration.GenericQueryConfiguration;

/**
* A set of tests that emphasis the influence of datatypes on query planning and execution
* A set of tests that emphasize the influence of datatypes on query planning and execution
* <p>
* Data is from {@link ShapesIngest} test set
*/
Expand Down Expand Up @@ -812,8 +812,6 @@ public void testFilterWithExtraTypesWithPrune() throws Exception {
assertDatatypeFilter(Sets.newHashSet("hexagon"));
}

// battery tests in two forms

@Test
public void testPruneNestedTermAllPermutations() throws Exception {
// natural prune will drop the ONLY_QUAD term
Expand All @@ -825,14 +823,17 @@ public void testPruneNestedTermAllPermutations() throws Exception {
assertPlannedQuery("ONLY_HEX == 'hexa' && SHAPE == 'hexagon'");
}

/**
* A slightly larger test
*
* @throws Exception
* if something goes wrong
*/
@Test
public void testPermutations() throws Exception {
String query = "ONLY_HEX == 'hexa' && (SHAPE == 'hexagon' || ONLY_QUAD == 'square')";
String planned = "ONLY_HEX == 'hexa' && SHAPE == 'hexagon'";
testBattery(query, planned);
}
String expectedPlan = "ONLY_HEX == 'hexa' && SHAPE == 'hexagon'";

private void testBattery(String query, String expectedPlan) throws Exception {
boolean[] pruneOptions = {false, true};
boolean[] reduceOptions = {false, true};
boolean[] rebuildOptions = {false, true};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,21 @@ void testAndNotNull() {
test(query, Collections.singleton("ingestType1"), metadata);
}

@Test
void testAndMultiFieldedDateFilter() {
TypeMetadata metadata = new TypeMetadata();
metadata.put("A", "type1", LcType.class.getTypeName());
metadata.put("B", "type1", LcType.class.getTypeName());
metadata.put("C", "type1", LcType.class.getTypeName());
metadata.put("D", "type1", LcType.class.getTypeName());
metadata.put("1", "type1", LcType.class.getTypeName());
metadata.put("2", "type1", LcType.class.getTypeName());
metadata.put("3", "type1", LcType.class.getTypeName());

String query = "!(A == null) && ($1 == '1' || B == '1') && ($2 == '2' || C == '2') && filter:afterDate(($3 || D), '2024-01-01')";
test(query, Collections.singleton("type1"), metadata);
}

private void assertSingleNode(String query, Set<String> expectedIngestTypes) {
assertSingleNode(query, expectedIngestTypes, typeMetadata);
}
Expand Down

0 comments on commit a94b830

Please sign in to comment.