You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by je...@apache.org on 2013/02/22 19:31:27 UTC
svn commit: r1449159 - in
/chemistry/opencmis/trunk/chemistry-opencmis-server:
chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/
chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis...
Author: jens
Date: Fri Feb 22 18:31:27 2013
New Revision: 1449159
URL: http://svn.apache.org/r1449159
Log:
ServerSupport:
allow for checking multiple CONTAINS() clauses
support SEARCH_SCORE as predefined identifier in ORDER_BY
InMemory:
allow only one CONTAINS clause
support SEARCH_SCORE as predefined identifier in ORDER_BY
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryParseTest.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseWalker.g
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java?rev=1449159&r1=1449158&r2=1449159&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java Fri Feb 22 18:31:27 2013
@@ -113,6 +113,7 @@ public class InMemoryQueryProcessor {
CmisQueryWalker walker = queryUtil.getWalker();
queryObj = queryUtil.getQueryObject();
whereTree = walker.getWherePredicateTree();
+ doAdditionalChecks(walker);
}
public ObjectList buildResultList(TypeManager tm, String user, Boolean includeAllowableActions,
@@ -194,7 +195,10 @@ public class InMemoryQueryProcessor {
CmisSelector sel = s.getSelector();
int result;
- if (sel instanceof ColumnReference) {
+ if (queryObj.isPredfinedQueryName(sel.getName())) {
+ // must be SEARCH_SCORE which is currently ignored
+ result = 0;
+ } else if (sel instanceof ColumnReference) {
String propId = ((ColumnReference) sel).getPropertyId();
PropertyDefinition<?> pd = ((ColumnReference) sel).getPropertyDefinition();
@@ -734,10 +738,9 @@ public class InMemoryQueryProcessor {
return typeQueryName;
}
- private Object xgetPropertyValue(Tree columnNode, StoredObject so) {
- ColumnReference colRef = getColumnReference(columnNode);
- PropertyDefinition<?> pd = colRef.getPropertyDefinition();
- return PropertyUtil.getProperty(so, colRef.getPropertyId(), pd);
+ private void doAdditionalChecks(CmisQueryWalker walker) {
+ if (walker.getNumberOfContainsClauses() > 1)
+ throw new CmisInvalidArgumentException("More than one CONTAINS clause is not allowed");
}
// translate SQL wildcards %, _ to Java regex syntax
@@ -780,7 +783,7 @@ public class InMemoryQueryProcessor {
}
private static void throwIncompatibleTypesException(Object o1, Object o2) {
- throw new IllegalArgumentException("Incompatible Types to compare: " + o1 + " and " + o2);
+ throw new CmisInvalidArgumentException("Incompatible Types to compare: " + o1 + " and " + o2);
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java?rev=1449159&r1=1449158&r2=1449159&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java Fri Feb 22 18:31:27 2013
@@ -38,6 +38,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.data.ObjectList;
import org.apache.chemistry.opencmis.commons.data.PropertyData;
import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.inmemory.AbstractServiceTest;
import org.apache.chemistry.opencmis.inmemory.UnitTestTypeSystemCreator;
import org.slf4j.Logger;
@@ -859,6 +860,17 @@ public class EvalQueryTest extends Abstr
assertTrue(resultContains(BigInteger.valueOf(100), UnitTestTypeSystemCreator.SECONDARY_INTEGER_PROP, res));
}
+ @Test
+ public void testMultipleContains() {
+ String statement = "SELECT * FROM " + COMPLEX_TYPE + " WHERE CONTAINS('abc') AND CONTAINS('123')";
+ try {
+ doQuery(statement);
+ fail("Multiple CONTAINS clauses should throw CmisInvalidArgumentException");
+ } catch (CmisInvalidArgumentException e) {
+ assertTrue(e.getMessage().contains("More than one CONTAINS"));
+ }
+ }
+
private ObjectList doQuery(String queryString) {
log.debug("\nExecuting query: " + queryString);
ObjectList res = fDiscSvc.query(fRepositoryId, queryString, false, false,
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryParseTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryParseTest.java?rev=1449159&r1=1449158&r2=1449159&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryParseTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryParseTest.java Fri Feb 22 18:31:27 2013
@@ -611,6 +611,14 @@ public class QueryParseTest extends Abst
printSearchTree(tree, statement);
}
+ @Test
+ public void whereTestMultipleContains2() {
+ String statement = "SELECT p1 FROM MyType WHERE CONTAINS('Beethoven') AND CONTAINS('Bach')";
+ checkTreeWhere(statement);
+ int noContains = getNumberOfSearchExpression(statement);
+ assertTrue(2 == noContains);
+ }
+
private void checkTreeWhere(String statement) {
LOG.info("\ncheckTreeWhere: " + statement);
QueryUtilStrict queryUtil = traverseStatementAndCatchExc(statement);
@@ -624,6 +632,11 @@ public class QueryParseTest extends Abst
return findTextSearchNode(whereTree);
}
+ private int getNumberOfSearchExpression(String statement) {
+ QueryUtilStrict queryUtil = traverseStatementAndCatchExc(statement);
+ return queryUtil.getWalker().getNumberOfContainsClauses();
+ }
+
private Tree findTextSearchNode(Tree node) {
int count = node.getChildCount();
if (node.getType() == CmisQlStrictLexer.CONTAINS) {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseWalker.g
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseWalker.g?rev=1449159&r1=1449158&r2=1449159&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseWalker.g (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseWalker.g Fri Feb 22 18:31:27 2013
@@ -36,6 +36,7 @@ options {
private QueryObject queryObj;
private Tree wherePredicateTree;
private boolean doFullTextParse = true;
+ private int noContains = 0;
public Tree getWherePredicateTree() {
return wherePredicateTree;
@@ -61,6 +62,10 @@ options {
return doFullTextParse;
}
+ public int getNumberOfContainsClauses() {
+ return noContains;
+ }
+
private static CommonTree parseTextSearchPredicate(String expr) throws RecognitionException {
String unescapedExpr = StringUtil.unescape(expr.substring(1, expr.length()-1), null);
CharStream input = new ANTLRStringStream(unescapedExpr);
@@ -244,6 +249,7 @@ search_condition
| ^(CONTAINS qualifier? text_search_expression)
{
queryObj.addWhereTypeReference($qualifier.start, $qualifier.value);
+ ++noContains;
}
| ^(IN_FOLDER qualifier? search_condition)
{
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g?rev=1449159&r1=1449158&r2=1449159&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g Fri Feb 22 18:31:27 2013
@@ -90,6 +90,10 @@ import org.slf4j.LoggerFactory;
public boolean getDoFullTextParse() {
return gCmisBaseWalker.getDoFullTextParse();
}
+
+ public int getNumberOfContainsClauses() {
+ return gCmisBaseWalker.getNumberOfContainsClauses();
+ }
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java?rev=1449159&r1=1449158&r2=1449159&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java Fri Feb 22 18:31:27 2013
@@ -71,6 +71,11 @@ public class QueryObject {
// order by part
protected final List<SortSpec> sortSpecs = new ArrayList<SortSpec>();
+
+ @SuppressWarnings("serial")
+ protected List<String> predefinedQueryNames = new ArrayList<String> () {{
+ add("SEARCH_SCORE");
+ }};
private String errorMessage;
@@ -514,6 +519,10 @@ public class QueryObject {
// it is property query name without a type, so find type
int noFound = 0;
TypeDefinition tdFound = null;
+
+ if (isPredfinedQueryName(propName))
+ return;
+
for (String typeQueryName : froms.values()) {
TypeDefinition td = typeMgr.getTypeByQueryName(typeQueryName);
if (null == td) {
@@ -539,6 +548,10 @@ public class QueryObject {
}
}
+ public boolean isPredfinedQueryName(String name) {
+ return predefinedQueryNames.contains(name);
+ }
+
// for a select x.y from x ... check that x has property y and that x is in
// from
protected void validateColumnReferenceAndResolveType(ColumnReference colRef) {