Search in sources :

Example 36 with JexlNode

use of org.apache.commons.jexl3.parser.JexlNode in project datawave by NationalSecurityAgency.

the class JexlASTHelperTest method transitiveEqualsParseWithEscapedRegexTest.

// This test is here to ensure that we can freely convert between a jexl tree and
// a query string, without impact to the string literal for the regex node.
// This also shows that an unescaped backslash (the one before '.blah') will be preserved between conversions.
// WEB QUERY: CITY == 'ci\\\\\\ty\.blah'
// StringLiteral.image: "ci\\\ty\.blah"
@Test
public void transitiveEqualsParseWithEscapedRegexTest() throws Exception {
    String query = "CITY == 'ci\\\\\\\\\\\\ty\\.blah'";
    JexlNode node = JexlASTHelper.parseJexlQuery(query);
    String interpretedQuery = JexlStringBuildingVisitor.buildQuery(node);
    JexlNode newNode = JexlASTHelper.parseJexlQuery(interpretedQuery);
    String reinterpretedQuery = JexlStringBuildingVisitor.buildQuery(newNode);
    // note: while this is different from the original query, it produces the same string literal
    Assert.assertEquals("CITY == 'ci\\\\\\\\\\\\ty\\\\.blah'", interpretedQuery);
    Assert.assertEquals(reinterpretedQuery, interpretedQuery);
    Assert.assertEquals("ci\\\\\\ty\\.blah", node.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0).image);
    Assert.assertEquals(node.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0).image, newNode.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0).image);
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 37 with JexlNode

use of org.apache.commons.jexl3.parser.JexlNode in project datawave by NationalSecurityAgency.

the class GeoFunctionsDescriptorTest method testGeoToGeoWaveFunction.

@Test
public void testGeoToGeoWaveFunction() throws Exception {
    String query = "geo:within_bounding_box(GEO_FIELD, \"-12.74,16.30\", \"-3.31,26.16\")";
    JexlNode node = JexlASTHelper.parseJexlQuery(query);
    GeoFunctionsDescriptor.GeoJexlArgumentDescriptor argDesc = (GeoFunctionsDescriptor.GeoJexlArgumentDescriptor) new GeoFunctionsDescriptor().getArgumentDescriptor((ASTFunctionNode) node.jjtGetChild(0).jjtGetChild(0));
    JexlNode queryNode = argDesc.toGeoWaveFunction(Sets.newHashSet("GEO_FIELD"));
    Assert.assertEquals("geowave:intersects(GEO_FIELD, 'POLYGON ((16.3 -12.74, 26.16 -12.74, 26.16 -3.31, 16.3 -3.31, 16.3 -12.74))')", JexlStringBuildingVisitor.buildQuery(queryNode));
}
Also used : ASTFunctionNode(org.apache.commons.jexl2.parser.ASTFunctionNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 38 with JexlNode

use of org.apache.commons.jexl3.parser.JexlNode 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));
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) JexlArgumentDescriptor(datawave.query.jexl.functions.arguments.JexlArgumentDescriptor) Test(org.junit.Test)

Example 39 with JexlNode

use of org.apache.commons.jexl3.parser.JexlNode 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));
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) JexlArgumentDescriptor(datawave.query.jexl.functions.arguments.JexlArgumentDescriptor) Test(org.junit.Test)

Example 40 with JexlNode

use of org.apache.commons.jexl3.parser.JexlNode in project datawave by NationalSecurityAgency.

the class JexlASTHelperTest method parse1InteriorBackslashEquals.

@Test
public void parse1InteriorBackslashEquals() throws Exception {
    String query = "CITY == 'ci\\\\ty'";
    JexlNode node = JexlASTHelper.parseJexlQuery(query);
    String interpretedQuery = JexlStringBuildingVisitor.buildQuery(node);
    Assert.assertEquals(query, interpretedQuery);
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Aggregations

JexlNode (org.apache.commons.jexl2.parser.JexlNode)327 Test (org.junit.Test)124 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)63 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)56 ArrayList (java.util.ArrayList)50 JexlNode (org.apache.commons.jexl3.parser.JexlNode)38 ExceededTermThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode)34 ASTAndNode (org.apache.commons.jexl2.parser.ASTAndNode)33 ASTOrNode (org.apache.commons.jexl2.parser.ASTOrNode)28 ExceededOrThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode)25 ASTEQNode (org.apache.commons.jexl2.parser.ASTEQNode)25 JexlException (org.apache.commons.jexl3.JexlException)24 HashSet (java.util.HashSet)22 ASTReference (org.apache.commons.jexl2.parser.ASTReference)19 ASTIdentifier (org.apache.commons.jexl2.parser.ASTIdentifier)18 ASTReferenceExpression (org.apache.commons.jexl2.parser.ASTReferenceExpression)16 IndexHoleMarkerJexlNode (datawave.query.jexl.nodes.IndexHoleMarkerJexlNode)15 ASTFunctionNode (org.apache.commons.jexl2.parser.ASTFunctionNode)15 ASTERNode (org.apache.commons.jexl2.parser.ASTERNode)14 JexlArgumentDescriptor (datawave.query.jexl.functions.arguments.JexlArgumentDescriptor)12