Commit 51137053 by apoorvnaik Committed by Madhan Neethiraj

ATLAS-2363: DSL error on extraneous input

parent 4c9a3bf7
......@@ -107,4 +107,4 @@ querySrc: commaDelimitedQueries | spaceDelimitedQueries ;
query: querySrc groupByExpression?
selectClause?
orderByExpr?
limitOffset? ;
\ No newline at end of file
limitOffset? EOF;
\ No newline at end of file
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.query;
import org.apache.atlas.exception.AtlasBaseException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.fail;
@Test
public class DSLParsingTest {
// Add all invalid constructs here to make sure that the
// DSL parsing behavior doesn't change
@DataProvider(name = "badDSLProvider")
public Object[][] getBadDSLQueries() {
return new Object[][] {
{"db orderby(name) orderby(owner)"},
{"db orderby(name) select name, owner orderby(owner)"},
{"db groupby(name) orderby(owner) select name, owner orderby(owner)"},
{"db groupby(name) select name, owner orderby(owner) orderby(owner)"},
{"db select name, owner orderby(owner) orderby(owner)"},
{"db select name, owner orderby(owner) groupby(owner)"},
{"db select name, owner groupby(owner) orderby(owner)"},
{"db groupby(name) groupby(name) select name, owner orderby(owner) orderby(owner)"},
};
}
@Test(dataProvider = "badDSLProvider", expectedExceptions = AtlasBaseException.class)
public void testInvalidDSL(String query) throws AtlasBaseException {
AtlasDSL.Parser.parse(query);
fail("The invalid query parsing should've failed");
}
}
......@@ -173,14 +173,14 @@ public class GremlinQueryComposerTest {
public void whereClauseWithAsTextContains() {
String exSel = "def f(r){ t=[['t.name','t.owner']]; r.each({t.add([it.value('Table.name'),it.value('Table.owner')])}); t.unique(); }";
String exMain = "g.V().has('__typeName', 'Table').as('t').has('Table.name', eq(\"testtable_1\")).limit(25).toList()";
verify("Table as t where t.name = \"testtable_1\" select t.name, t.owner)", getExpected(exSel, exMain));
verify("Table as t where t.name = \"testtable_1\" select t.name, t.owner", getExpected(exSel, exMain));
}
@Test
public void whereClauseWithDateCompare() {
String exSel = "def f(r){ t=[['t.name','t.owner']]; r.each({t.add([it.value('Table.name'),it.value('Table.owner')])}); t.unique(); }";
String exMain = "g.V().has('__typeName', 'Table').as('t').has('Table.createTime', eq('1513046158440')).limit(25).toList()";
verify("Table as t where t.createTime = \"2017-12-12T02:35:58.440Z\" select t.name, t.owner)", getExpected(exSel, exMain));
verify("Table as t where t.createTime = \"2017-12-12T02:35:58.440Z\" select t.name, t.owner", getExpected(exSel, exMain));
}
@Test
......
......@@ -19,6 +19,7 @@
package org.apache.atlas.web.integration;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.discovery.AtlasSearchResult;
import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult;
import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasQueryType;
......@@ -109,11 +110,10 @@ public class EntityDiscoveryJerseyResourceIT extends BaseResourceIT {
assertEquals(searchResult.getEntities().size(), 1);
}
@Test
@Test(expectedExceptions = AtlasBaseException.class)
public void testSearchByDSLForUnknownType() throws Exception {
String dslQuery = "from blah";
AtlasSearchResult searchResult = atlasClientV2.dslSearch(dslQuery);
//TODO: Should throw an exception, current v2 DSL doesn't handle search on unknown type
}
@Test(enabled = false)
......
......@@ -25,6 +25,7 @@ import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.v1.model.instance.Id;
import org.apache.atlas.v1.model.instance.Referenceable;
......@@ -133,13 +134,12 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
}
}
@Test
@Test(expectedExceptions = AtlasBaseException.class)
public void testSearchByDSLForUnknownType() throws Exception {
String dslQuery = "from blah";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", dslQuery);
atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
//TODO: Should throw an exception, current v2 DSL doesn't handle search on unknown type
}
@Test (enabled = false)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment