use of datawave.query.jexl.functions.arguments.JexlArgumentDescriptor in project datawave by NationalSecurityAgency.
the class EventDataQueryExpressionVisitor method visit.
@Override
public Object visit(ASTFunctionNode node, Object data) {
JexlArgumentDescriptor desc = JexlFunctionArgumentDescriptorFactory.F.getArgumentDescriptor(node);
desc.addFilters(attributeFactory, filterMap);
return null;
}
use of datawave.query.jexl.functions.arguments.JexlArgumentDescriptor in project datawave by NationalSecurityAgency.
the class ValidPatternVisitor method visit.
/**
* Visit an ASTFunctionNode to catch cases like #INCLUDE or #EXCLUDE that accept a regex as an argument
*
* @param node
* - an ASTFunctionNode
* @param data
* - the data
* @return
*/
@Override
public Object visit(ASTFunctionNode node, Object data) {
// Should pull back an EvaluationPhaseFilterFunctionsDescriptor
JexlArgumentDescriptor descriptor = JexlFunctionArgumentDescriptorFactory.F.getArgumentDescriptor(node);
if (descriptor == null) {
throw new IllegalStateException("Could not get descriptor for ASTFunctionNode");
}
if (descriptor.regexArguments()) {
// Extract the args for this function
FunctionJexlNodeVisitor functionVisitor = new FunctionJexlNodeVisitor();
functionVisitor.visit(node, null);
List<JexlNode> args = functionVisitor.args();
for (JexlNode arg : args) {
// Only take the literals
if (arg instanceof ASTStringLiteral) {
parseAndPutPattern(arg);
}
}
}
// Do not descend to children, the ValidPatternVisitor views a function node as a leaf node.
return data;
}
use of datawave.query.jexl.functions.arguments.JexlArgumentDescriptor in project datawave by NationalSecurityAgency.
the class SplitGeoWaveFunctionVisitor method visit.
@Override
public Object visit(ASTFunctionNode node, Object data) {
JexlArgumentDescriptor descriptor = JexlFunctionArgumentDescriptorFactory.F.getArgumentDescriptor(node);
if (descriptor instanceof GeoWaveFunctionsDescriptor.GeoWaveJexlArgumentDescriptor) {
Set<String> fields = descriptor.fields(metadataHelper, Collections.emptySet());
if (fields.size() > 1) {
List<JexlNode> functionNodes = new ArrayList<>();
FunctionJexlNodeVisitor functionVisitor = new FunctionJexlNodeVisitor();
node.jjtAccept(functionVisitor, null);
for (String field : fields) {
List<JexlNode> newArgs = new ArrayList<>();
for (int i = 0; i < functionVisitor.args().size(); i++) {
if (i == 0) {
newArgs.add(JexlNodeFactory.buildIdentifier(field));
} else {
newArgs.add(RebuildingVisitor.copy(functionVisitor.args().get(i)));
}
}
functionNodes.add(JexlNodes.makeRef(FunctionJexlNodeVisitor.makeFunctionFrom(functionVisitor.namespace(), functionVisitor.name(), newArgs.toArray(new JexlNode[0]))));
}
return JexlNodeFactory.createUnwrappedOrNode(functionNodes);
}
} else if (descriptor instanceof GeoFunctionsDescriptor.GeoJexlArgumentDescriptor) {
Set<String> fields = descriptor.fields(metadataHelper, Collections.emptySet());
if (fields.size() > 1) {
List<JexlNode> functionNodes = new ArrayList<>();
FunctionJexlNodeVisitor functionVisitor = new FunctionJexlNodeVisitor();
node.jjtAccept(functionVisitor, null);
// geo functions with > 3 args contain separate fields for lat/lon, and should not be considered
if (functionVisitor.args().size() == 3) {
for (String field : fields) {
List<JexlNode> newArgs = new ArrayList<>();
for (int i = 0; i < functionVisitor.args().size(); i++) {
if (i == 0) {
newArgs.add(JexlNodeFactory.buildIdentifier(field));
} else {
newArgs.add(RebuildingVisitor.copy(functionVisitor.args().get(i)));
}
}
functionNodes.add(JexlNodes.makeRef(FunctionJexlNodeVisitor.makeFunctionFrom(functionVisitor.namespace(), functionVisitor.name(), newArgs.toArray(new JexlNode[0]))));
}
return JexlNodeFactory.createUnwrappedOrNode(functionNodes);
}
}
}
return super.visit(node, data);
}
use of datawave.query.jexl.functions.arguments.JexlArgumentDescriptor in project datawave by NationalSecurityAgency.
the class GeoFunctionsDescriptorTest method antiMeridianTest1.
@Test
public void antiMeridianTest1() throws Exception {
String query = "geo:within_bounding_box(GEO_FIELD, '40_170', '50_-170')";
JexlNode node = JexlASTHelper.parseJexlQuery(query);
JexlArgumentDescriptor argDesc = new GeoFunctionsDescriptor().getArgumentDescriptor((ASTFunctionNode) node.jjtGetChild(0).jjtGetChild(0));
JexlNode queryNode = argDesc.getIndexQuery(null, null, null, null);
Assert.assertEquals("(((_Bounded_ = true) && (GEO_FIELD >= '40.0_170.0' && GEO_FIELD <= '50.0_180')) && ((_Bounded_ = true) && (GEO_FIELD >= '40.0_-180' && GEO_FIELD <= '50.0_-170.0')))", JexlStringBuildingVisitor.buildQuery(queryNode));
}
use of datawave.query.jexl.functions.arguments.JexlArgumentDescriptor in project datawave by NationalSecurityAgency.
the class GeoFunctionsDescriptorTest method testMultiFieldGeoFunction.
@Test
public void testMultiFieldGeoFunction() throws Exception {
String query = "geo:within_circle(FIELD_1 || FIELD_2, '0_0', '10')";
JexlNode node = JexlASTHelper.parseJexlQuery(query);
JexlArgumentDescriptor argDesc = new GeoFunctionsDescriptor().getArgumentDescriptor((ASTFunctionNode) node.jjtGetChild(0).jjtGetChild(0));
JexlNode queryNode = argDesc.getIndexQuery(null, null, null, null);
Assert.assertEquals("(((_Bounded_ = true) && (FIELD_1 >= '-10.0|-10.0' && FIELD_1 <= '10.0|10.0')) || ((_Bounded_ = true) && (FIELD_2 >= '-10.0|-10.0' && FIELD_2 <= '10.0|10.0')))", JexlStringBuildingVisitor.buildQuery(queryNode));
}
Aggregations