teiid SVN: r1219 - in trunk/engine/src: main/java/com/metamatrix/query/validator and 3 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-08-06 22:33:46 -0400 (Thu, 06 Aug 2009)
New Revision: 1219
Removed:
trunk/engine/src/main/java/com/metamatrix/query/validator/ValueValidationVisitor.java
Modified:
trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
Log:
TEIID-496 removing valuevalidationvisitor and instead adding constraints to references
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java 2009-08-06 20:11:11 UTC (rev 1218)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java 2009-08-07 02:33:46 UTC (rev 1219)
@@ -22,6 +22,7 @@
package com.metamatrix.query.sql.symbol;
+import com.metamatrix.api.exception.query.QueryValidatorException;
import com.metamatrix.core.util.Assertion;
import com.metamatrix.query.metadata.TempMetadataID;
import com.metamatrix.query.sql.LanguageVisitor;
@@ -34,13 +35,19 @@
*/
public class Reference implements Expression, ContextReference {
+ public interface Constraint {
+ public void validate(Object value) throws QueryValidatorException;
+ }
+
private boolean positional;
private int refIndex;
private Class<?> type;
private ElementSymbol expression;
-
+
+ private Constraint constraint;
+
/**
* Constructor for a positional Reference.
*/
@@ -49,6 +56,14 @@
this.positional = true;
}
+ public Constraint getConstraint() {
+ return constraint;
+ }
+
+ public void setConstraint(Constraint constraint) {
+ this.constraint = constraint;
+ }
+
/**
* Constructor for an element Reference.
*/
@@ -64,6 +79,7 @@
if (ref.expression != null) {
this.expression = (ElementSymbol)ref.expression.clone();
}
+ this.constraint = ref.constraint;
}
public boolean isResolved() {
Modified: trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-08-06 20:11:11 UTC (rev 1218)
+++ trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-08-07 02:33:46 UTC (rev 1219)
@@ -35,6 +35,7 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.ExpressionEvaluationException;
import com.metamatrix.api.exception.query.QueryMetadataException;
+import com.metamatrix.api.exception.query.QueryValidatorException;
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.query.QueryPlugin;
import com.metamatrix.query.eval.Evaluator;
@@ -58,6 +59,7 @@
import com.metamatrix.query.sql.lang.Insert;
import com.metamatrix.query.sql.lang.Into;
import com.metamatrix.query.sql.lang.IsNullCriteria;
+import com.metamatrix.query.sql.lang.Limit;
import com.metamatrix.query.sql.lang.MatchCriteria;
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.Option;
@@ -90,6 +92,7 @@
import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
+import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
@@ -104,7 +107,24 @@
public class ValidationVisitor extends AbstractValidationVisitor {
- // State during validation
+ private final class PositiveIntegerConstraint implements
+ Reference.Constraint {
+
+ private String msgKey;
+
+ public PositiveIntegerConstraint(String msgKey) {
+ this.msgKey = msgKey;
+ }
+
+ @Override
+ public void validate(Object value) throws QueryValidatorException {
+ if (((Integer)value).intValue() < 0) {
+ throw new QueryValidatorException(QueryPlugin.Util.getString(msgKey)); //$NON-NLS-1$
+ }
+ }
+ }
+
+ // State during validation
private boolean isXML = false; // only used for Query commands
// update procedure being validated
@@ -1033,6 +1053,78 @@
if (isNonComparable(obj.getLeftExpression())) {
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0027, obj),obj);
}
+
+ // Validate use of 'rowlimit' and 'rowlimitexception' pseudo-functions - they cannot be nested within another
+ // function, and their operands must be a nonnegative integers
+
+ // Collect all occurrances of rowlimit function
+ List rowLimitFunctions = new ArrayList();
+ FunctionCollectorVisitor visitor = new FunctionCollectorVisitor(rowLimitFunctions, FunctionLibrary.ROWLIMIT);
+ PreOrderNavigator.doVisit(obj, visitor);
+ visitor = new FunctionCollectorVisitor(rowLimitFunctions, FunctionLibrary.ROWLIMITEXCEPTION);
+ PreOrderNavigator.doVisit(obj, visitor);
+ final int functionCount = rowLimitFunctions.size();
+ if (functionCount > 0) {
+ Function function = null;
+ Expression expr = null;
+ if (obj.getLeftExpression() instanceof Function) {
+ Function leftExpr = (Function)obj.getLeftExpression();
+ if (leftExpr.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMIT) ||
+ leftExpr.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMITEXCEPTION)) {
+ function = leftExpr;
+ expr = obj.getRightExpression();
+ }
+ }
+ if (function == null && obj.getRightExpression() instanceof Function) {
+ Function rightExpr = (Function)obj.getRightExpression();
+ if (rightExpr.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMIT) ||
+ rightExpr.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMITEXCEPTION)) {
+ function = rightExpr;
+ expr = obj.getLeftExpression();
+ }
+ }
+ if (function == null) {
+ // must be nested, which is invalid
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.0"), obj); //$NON-NLS-1$
+ } else {
+ if (expr instanceof Constant) {
+ Constant constant = (Constant)expr;
+ if (constant.getValue() instanceof Integer) {
+ Integer integer = (Integer)constant.getValue();
+ if (integer.intValue() < 0) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.1"), obj); //$NON-NLS-1$
+ }
+ } else {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.1"), obj); //$NON-NLS-1$
+ }
+ } else if (expr instanceof Reference) {
+ ((Reference)expr).setConstraint(new PositiveIntegerConstraint("ValidationVisitor.1")); //$NON-NLS-1$
+ } else {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.1"), obj); //$NON-NLS-1$
+ }
+ }
+ }
}
+
+ public void visit(Limit obj) {
+ Expression offsetExpr = obj.getOffset();
+ if (offsetExpr instanceof Constant) {
+ Integer offset = (Integer)((Constant)offsetExpr).getValue();
+ if (offset.intValue() < 0) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.badoffset2"), obj); //$NON-NLS-1$
+ }
+ } else if (offsetExpr instanceof Reference) {
+ ((Reference)offsetExpr).setConstraint(new PositiveIntegerConstraint("ValidationVisitor.badoffset2")); //$NON-NLS-1$
+ }
+ Expression limitExpr = obj.getRowLimit();
+ if (limitExpr instanceof Constant) {
+ Integer limit = (Integer)((Constant)limitExpr).getValue();
+ if (limit.intValue() < 0) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.badlimit2"), obj); //$NON-NLS-1$
+ }
+ } else if (limitExpr instanceof Reference) {
+ ((Reference)limitExpr).setConstraint(new PositiveIntegerConstraint("ValidationVisitor.badlimit2")); //$NON-NLS-1$
+ }
+ }
}
Deleted: trunk/engine/src/main/java/com/metamatrix/query/validator/ValueValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/validator/ValueValidationVisitor.java 2009-08-06 20:11:11 UTC (rev 1218)
+++ trunk/engine/src/main/java/com/metamatrix/query/validator/ValueValidationVisitor.java 2009-08-07 02:33:46 UTC (rev 1219)
@@ -1,122 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.validator;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.metamatrix.query.QueryPlugin;
-import com.metamatrix.query.function.FunctionLibrary;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.Limit;
-import com.metamatrix.query.sql.navigator.PreOrderNavigator;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.visitor.FunctionCollectorVisitor;
-
-public class ValueValidationVisitor extends AbstractValidationVisitor {
-
- public void visit(CompareCriteria obj) {
- // Validate use of 'rowlimit' and 'rowlimitexception' pseudo-functions - they cannot be nested within another
- // function, and their operands must be a nonnegative integers
-
- // Collect all occurrances of rowlimit function
- List rowLimitFunctions = new ArrayList();
- FunctionCollectorVisitor visitor = new FunctionCollectorVisitor(rowLimitFunctions, FunctionLibrary.ROWLIMIT);
- PreOrderNavigator.doVisit(obj, visitor);
- visitor = new FunctionCollectorVisitor(rowLimitFunctions, FunctionLibrary.ROWLIMITEXCEPTION);
- PreOrderNavigator.doVisit(obj, visitor);
- final int functionCount = rowLimitFunctions.size();
- if (functionCount > 0) {
- Function function = null;
- Expression expr = null;
- if (obj.getLeftExpression() instanceof Function) {
- Function leftExpr = (Function)obj.getLeftExpression();
- if (leftExpr.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMIT) ||
- leftExpr.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMITEXCEPTION)) {
- function = leftExpr;
- expr = obj.getRightExpression();
- }
- }
- if (function == null && obj.getRightExpression() instanceof Function) {
- Function rightExpr = (Function)obj.getRightExpression();
- if (rightExpr.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMIT) ||
- rightExpr.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMITEXCEPTION)) {
- function = rightExpr;
- expr = obj.getLeftExpression();
- }
- }
- if (function == null) {
- // must be nested, which is invalid
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.0"), obj); //$NON-NLS-1$
- } else {
- if (expr instanceof Reference) {
- expr = ((Reference)expr).getExpression();
- }
- if (expr instanceof Constant) {
- Constant constant = (Constant)expr;
- if (constant.getValue() instanceof Integer) {
- Integer integer = (Integer)constant.getValue();
- if (integer.intValue() < 0) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.1"), obj); //$NON-NLS-1$
- }
- } else {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.1"), obj); //$NON-NLS-1$
- }
- } else {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.1"), obj); //$NON-NLS-1$
- }
- }
- }
- }
-
- public void visit(Limit obj) {
- Expression offsetExpr = obj.getOffset();
- if (offsetExpr instanceof Reference) {
- offsetExpr = ((Reference)offsetExpr).getExpression();
- }
- if (offsetExpr instanceof Constant) {
- Integer offset = (Integer)((Constant)offsetExpr).getValue();
- if (offset == null) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.badoffset1"), obj); //$NON-NLS-1$
- } else if (offset.intValue() < 0) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.badoffset2"), obj); //$NON-NLS-1$
- }
- }
- Expression limitExpr = obj.getRowLimit();
- if (limitExpr instanceof Reference) {
- limitExpr = ((Reference)limitExpr).getExpression();
- }
- if (limitExpr instanceof Constant) {
- Integer limit = (Integer)((Constant)limitExpr).getValue();
- if (limit == null) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.badlimit1"), obj); //$NON-NLS-1$
- } else if (limit.intValue() < 0) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.badlimit2"), obj); //$NON-NLS-1$
- }
- }
- }
-
-}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java 2009-08-06 20:11:11 UTC (rev 1218)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java 2009-08-07 02:33:46 UTC (rev 1219)
@@ -123,12 +123,6 @@
}
}
- @Override
- protected void validateQueryValues(Command command)
- throws QueryValidatorException, MetaMatrixComponentException {
- //do nothing initially - check after parameter values have been set
- }
-
/**
* @throws MetaMatrixComponentException
* @throws QueryValidatorException
@@ -174,7 +168,7 @@
List<Reference> params = prepPlan.getReferences();
List<?> values = requestMsg.getParameterValues();
- resolveAndValidateParameters(this.userCommand, params, values);
+ PreparedStatementRequest.resolveParameterValues(params, values, this.context);
}
return prepPlan.getRewritenCommand();
}
@@ -213,7 +207,7 @@
List<VariableContext> contexts = new LinkedList<VariableContext>();
List<List<Object>> multiValues = new ArrayList<List<Object>>(this.prepPlan.getReferences().size());
for (List<?> values : paramValues) {
- resolveAndValidateParameters(this.userCommand, this.prepPlan.getReferences(), values);
+ PreparedStatementRequest.resolveParameterValues(this.prepPlan.getReferences(), values, this.context);
contexts.add(this.context.getVariableContext());
if(supportPreparedBatchUpdate){
if (multiValues.isEmpty()) {
@@ -259,22 +253,14 @@
this.processPlan = planner.optimize(ctn, idGenerator, metadata, capabilitiesFinder, analysisRecord, context);
}
- private void resolveAndValidateParameters(Command command, List<Reference> params,
- List<?> values) throws QueryResolverException,
- MetaMatrixComponentException, QueryValidatorException {
- // validate parameters values - right number and right type
- PreparedStatementRequest.resolveParameterValues(params, values, this.context);
- // call back to Request.validateQueryValues to ensure that bound references are valid
- super.validateQueryValues(command);
- }
-
/**
* @param params
* @param values
* @throws QueryResolverException
+ * @throws QueryValidatorException
*/
public static void resolveParameterValues(List<Reference> params,
- List values, CommandContext context) throws QueryResolverException, MetaMatrixComponentException {
+ List values, CommandContext context) throws QueryResolverException, MetaMatrixComponentException, QueryValidatorException {
VariableContext result = new VariableContext();
//the size of the values must be the same as that of the parameters
if (params.size() != values.size()) {
@@ -303,6 +289,9 @@
}
}
+ if (param.getConstraint() != null) {
+ param.getConstraint().validate(value);
+ }
//bind variable
result.setGlobalValue(param.getContextSymbol(), value);
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2009-08-06 20:11:11 UTC (rev 1218)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2009-08-07 02:33:46 UTC (rev 1219)
@@ -105,7 +105,6 @@
import com.metamatrix.query.validator.Validator;
import com.metamatrix.query.validator.ValidatorFailure;
import com.metamatrix.query.validator.ValidatorReport;
-import com.metamatrix.query.validator.ValueValidationVisitor;
/**
* Server side representation of the RequestMessage. Knows how to process itself.
@@ -326,13 +325,6 @@
}
}
- protected void validateQueryValues(Command command)
- throws QueryValidatorException, MetaMatrixComponentException {
-
- AbstractValidationVisitor visitor = new ValueValidationVisitor();
- validateWithVisitor(visitor, metadata, command, false);
- }
-
private Command parseCommand() throws QueryParserException {
String[] commands = requestMsg.getCommands();
ParseInfo parseInfo = createParseInfo(this.requestMsg);
@@ -471,8 +463,6 @@
validateQuery(command, true);
- validateQueryValues(command);
-
command = QueryRewriter.rewrite(command, null, metadata, context);
/*
@@ -615,8 +605,6 @@
validateQuery(newCommand, isRootXQuery);
- validateQueryValues(newCommand);
-
if (isRootXQuery) {
validateEntitlement(newCommand);
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-08-06 20:11:11 UTC (rev 1218)
+++ trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-08-07 02:33:46 UTC (rev 1219)
@@ -354,12 +354,9 @@
try {
ValidatorReport report = Validator.validate(command, metadata);
- ValidatorReport report3 = Validator.validate(command, metadata, new ValueValidationVisitor(), true);
-
// Get invalid objects from report
Collection actualObjs = new ArrayList();
report.collectInvalidObjects(actualObjs);
- report3.collectInvalidObjects(actualObjs);
// Compare expected and actual objects
Set expectedStrings = new HashSet(Arrays.asList(expectedStringArray));
@@ -371,7 +368,7 @@
}
if(expectedStrings.size() == 0 && actualStrings.size() > 0) {
- fail("Expected no failures but got some: " + report.getFailureMessage() + ", " + report3.getFailureMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ fail("Expected no failures but got some: " + report.getFailureMessage()); //$NON-NLS-1$
} else if(actualStrings.size() == 0 && expectedStrings.size() > 0) {
fail("Expected some failures but got none for sql = " + command); //$NON-NLS-1$
} else {
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2009-08-06 20:11:11 UTC (rev 1218)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2009-08-07 02:33:46 UTC (rev 1219)
@@ -391,5 +391,13 @@
TestProcessor.sampleData2b(dataManager);
helpTestProcessing(preparedSql, values, expected, dataManager, FakeMetadataFactory.example1Cached(), false, false);
}
+
+ @Test(expected=QueryValidatorException.class) public void testLimitValidation() throws Exception {
+ String preparedSql = "select pm1.g1.e1 from pm1.g1 limit ?"; //$NON-NLS-1$
+
+ List values = Arrays.asList(-1);
+ FakeDataManager dataManager = new FakeDataManager();
+ helpTestProcessing(preparedSql, values, null, dataManager, FakeMetadataFactory.example1Cached(), false, false);
+ }
}
15 years, 5 months
teiid SVN: r1218 - in trunk/connectors/connector-jdbc/src: test/java/org/teiid/connector/jdbc/postgresql and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-08-06 16:11:11 -0400 (Thu, 06 Aug 2009)
New Revision: 1218
Added:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java
Log:
TEIID-758 adding support for locate to postgresql.
Added: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java 2009-08-06 20:11:11 UTC (rev 1218)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc.postgresql;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.teiid.connector.api.TypeFacility;
+import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
+import org.teiid.connector.language.IExpression;
+import org.teiid.connector.language.IFunction;
+import org.teiid.connector.language.ILanguageFactory;
+
+public class LocateFunctionModifier extends BasicFunctionModifier {
+
+ private ILanguageFactory factory;
+
+ public LocateFunctionModifier(ILanguageFactory factory) {
+ this.factory = factory;
+ }
+
+ @Override
+ public List<?> translate(IFunction function) {
+ List<Object> parts = new ArrayList<Object>();
+ List<IExpression> params = function.getParameters();
+ parts.add("position("); //$NON-NLS-1$
+ parts.add(params.get(0));
+ parts.add(" in "); //$NON-NLS-1$
+ if (params.size() == 3) {
+ parts.add(factory.createFunction("substr", params.subList(1, 3), TypeFacility.RUNTIME_TYPES.STRING)); //$NON-NLS-1$
+ } else {
+ parts.add(params.get(1));
+ }
+ parts.add(")"); //$NON-NLS-1$
+ return parts;
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/LocateFunctionModifier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java 2009-08-06 16:47:07 UTC (rev 1217)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java 2009-08-06 20:11:11 UTC (rev 1218)
@@ -89,8 +89,7 @@
supportedFunctions.add("LCASE"); //$NON-NLS-1$
supportedFunctions.add("LEFT"); //$NON-NLS-1$
supportedFunctions.add("LENGTH"); //$NON-NLS-1$
- // Doesn't support both forms exposed by MM
-// supportedFunctions.add("LOCATE"); //$NON-NLS-1$
+ supportedFunctions.add("LOCATE"); //$NON-NLS-1$
supportedFunctions.add("LOWER"); //$NON-NLS-1$
supportedFunctions.add("LPAD"); //$NON-NLS-1$
supportedFunctions.add("LTRIM"); //$NON-NLS-1$
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-08-06 16:47:07 UTC (rev 1217)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-08-06 20:11:11 UTC (rev 1218)
@@ -93,7 +93,9 @@
registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.CONVERT, new PostgreSQLConvertModifier(getLanguageFactory()));
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, new PostgreSQLConvertModifier(getLanguageFactory()));
+
+ registerFunctionModifier(SourceSystemFunctions.LOCATE, new LocateFunctionModifier(getLanguageFactory()));
}
@Override
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java 2009-08-06 16:47:07 UTC (rev 1217)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/postgresql/TestPostgreSQLTranslator.java 2009-08-06 20:11:11 UTC (rev 1218)
@@ -22,40 +22,24 @@
package org.teiid.connector.jdbc.postgresql;
-import java.util.Map;
import java.util.Properties;
+import org.junit.BeforeClass;
+import org.junit.Test;
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.jdbc.MetadataFactory;
-import org.teiid.connector.jdbc.postgresql.PostgreSQLTranslator;
-import org.teiid.connector.jdbc.translator.TranslatedCommand;
-import org.teiid.connector.language.ICommand;
-import junit.framework.TestCase;
-
import com.metamatrix.cdk.api.EnvironmentUtility;
-/**
- */
-public class TestPostgreSQLTranslator extends TestCase {
+public class TestPostgreSQLTranslator {
- private static Map MODIFIERS;
private static PostgreSQLTranslator TRANSLATOR;
-
- static {
- try {
- TRANSLATOR = new PostgreSQLTranslator();
- TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
- MODIFIERS = TRANSLATOR.getFunctionModifiers();
- } catch(ConnectorException e) {
- e.printStackTrace();
- }
- }
-
- public TestPostgreSQLTranslator(String name) {
- super(name);
- }
-
+
+ @BeforeClass public static void setupOnce() throws Exception {
+ TRANSLATOR = new PostgreSQLTranslator();
+ TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
+ }
+
public String getTestVDB() {
return MetadataFactory.PARTS_VDB;
}
@@ -64,401 +48,359 @@
return MetadataFactory.BQT_VDB;
}
- public void helpTestVisitor(String vdb, String input, Map modifiers, String expectedOutput) throws ConnectorException {
- // Convert from sql to objects
- ICommand obj = MetadataFactory.helpTranslate(vdb, input);
-
- TranslatedCommand tc = new TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), TRANSLATOR);
- tc.translateCommand(obj);
-
-
- // Check stuff
- assertEquals("Did not get correct sql", expectedOutput, tc.getSql()); //$NON-NLS-1$
+ public void helpTestVisitor(String vdb, String input, String expectedOutput) throws ConnectorException {
+ MetadataFactory.helpTestVisitor(vdb, input, expectedOutput, TRANSLATOR);
}
- public void testRewriteConversion1() throws Exception {
+ @Test public void testRewriteConversion1() throws Exception {
String input = "SELECT char(convert(PART_WEIGHT, integer) + 100) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT chr((cast(PARTS.PART_WEIGHT AS integer) + 100)) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion2() throws Exception {
+ @Test public void testRewriteConversion2() throws Exception {
String input = "SELECT convert(PART_WEIGHT, long) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT cast(PARTS.PART_WEIGHT AS bigint) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion3() throws Exception {
+ @Test public void testRewriteConversion3() throws Exception {
String input = "SELECT convert(PART_WEIGHT, short) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT cast(PARTS.PART_WEIGHT AS smallint) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion4() throws Exception {
+ @Test public void testRewriteConversion4() throws Exception {
String input = "SELECT convert(PART_WEIGHT, float) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT cast(PARTS.PART_WEIGHT AS real) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion5() throws Exception {
+ @Test public void testRewriteConversion5() throws Exception {
String input = "SELECT convert(PART_WEIGHT, double) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT cast(PARTS.PART_WEIGHT AS float8) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion6() throws Exception {
+ @Test public void testRewriteConversion6() throws Exception {
String input = "SELECT convert(PART_WEIGHT, biginteger) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT cast(PARTS.PART_WEIGHT AS numeric) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion7() throws Exception {
+ @Test public void testRewriteConversion7() throws Exception {
String input = "SELECT convert(PART_WEIGHT, bigdecimal) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT cast(PARTS.PART_WEIGHT AS decimal) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion8() throws Exception {
+ @Test public void testRewriteConversion8() throws Exception {
String input = "SELECT convert(PART_WEIGHT, boolean) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT cast(PARTS.PART_WEIGHT AS boolean) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion9() throws Exception {
+ @Test public void testRewriteConversion9() throws Exception {
String input = "SELECT convert(PART_WEIGHT, date) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT to_date(PARTS.PART_WEIGHT, 'YYYY-MM-DD') FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion10() throws Exception {
+ @Test public void testRewriteConversion10() throws Exception {
String input = "SELECT convert(PART_WEIGHT, time) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT to_timestamp(('1970-01-01 ' || PARTS.PART_WEIGHT), 'YYYY-MM-DD HH24:MI:SS') FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion11() throws Exception {
+ @Test public void testRewriteConversion11() throws Exception {
String input = "SELECT convert(PART_WEIGHT, timestamp) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF') FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion12() throws Exception {
+ @Test public void testRewriteConversion12() throws Exception {
String input = "SELECT convert(convert(PART_WEIGHT, time), string) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT to_char(to_timestamp(('1970-01-01 ' || PARTS.PART_WEIGHT), 'YYYY-MM-DD HH24:MI:SS'), 'HH24:MI:SS') FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion13() throws Exception {
+ @Test public void testRewriteConversion13() throws Exception {
String input = "SELECT convert(convert(PART_WEIGHT, timestamp), string) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT to_char(to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF'), 'YYYY-MM-DD HH24:MI:SS.US') FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion14() throws Exception {
+ @Test public void testRewriteConversion14() throws Exception {
String input = "SELECT convert(convert(PART_WEIGHT, date), string) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT to_char(to_date(PARTS.PART_WEIGHT, 'YYYY-MM-DD'), 'YYYY-MM-DD') FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion15() throws Exception {
+ @Test public void testRewriteConversion15() throws Exception {
String input = "SELECT convert(convert(PART_WEIGHT, timestamp), date) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT cast(to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF') AS date) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion16() throws Exception {
+ @Test public void testRewriteConversion16() throws Exception {
String input = "SELECT convert(convert(PART_WEIGHT, timestamp), time) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT cast(to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF') AS time) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion17() throws Exception {
+ @Test public void testRewriteConversion17() throws Exception {
String input = "SELECT convert(convert(PART_WEIGHT, time), timestamp) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT to_timestamp(to_char(to_timestamp(('1970-01-01 ' || PARTS.PART_WEIGHT), 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS') FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion18() throws Exception {
+ @Test public void testRewriteConversion18() throws Exception {
String input = "SELECT convert(convert(PART_WEIGHT, date), timestamp) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT to_timestamp(to_char(to_date(PARTS.PART_WEIGHT, 'YYYY-MM-DD'), 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS') FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteConversion19() throws Exception {
+ @Test public void testRewriteConversion19() throws Exception {
String input = "SELECT convert(convert(PART_WEIGHT, boolean), string) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT CASE WHEN cast(PARTS.PART_WEIGHT AS boolean) = TRUE THEN '1' ELSE '0' END FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteLog() throws Exception {
+ @Test public void testRewriteLog() throws Exception {
String input = "SELECT log(convert(PART_WEIGHT, double)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT ln(cast(PARTS.PART_WEIGHT AS float8)) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
input = "SELECT log10(convert(PART_WEIGHT, double)) FROM PARTS"; //$NON-NLS-1$
output = "SELECT log(cast(PARTS.PART_WEIGHT AS float8)) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteLeft() throws Exception {
+ @Test public void testRewriteLeft() throws Exception {
String input = "SELECT left(PART_WEIGHT, 2) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT SUBSTR(PARTS.PART_WEIGHT, 1, 2) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRewriteRight() throws Exception {
+ @Test public void testRewriteRight() throws Exception {
String input = "SELECT right(PART_WEIGHT, 2) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT SUBSTR(PARTS.PART_WEIGHT, (-1 * 2)) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testDayOfWeek() throws Exception {
+ @Test public void testDayOfWeek() throws Exception {
String input = "SELECT dayofweek(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT (EXTRACT(DOW FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) + 1) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testDayOfMonth() throws Exception {
+ @Test public void testDayOfMonth() throws Exception {
String input = "SELECT dayofmonth(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT EXTRACT(DAY FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testDayOfYear() throws Exception {
+ @Test public void testDayOfYear() throws Exception {
String input = "SELECT dayofyear(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT EXTRACT(DOY FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testHour() throws Exception {
+ @Test public void testHour() throws Exception {
String input = "SELECT hour(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT EXTRACT(HOUR FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testMinute() throws Exception {
+ @Test public void testMinute() throws Exception {
String input = "SELECT minute(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT EXTRACT(MINUTE FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testMonth() throws Exception {
+ @Test public void testMonth() throws Exception {
String input = "SELECT month(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT EXTRACT(MONTH FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testQuarter() throws Exception {
+ @Test public void testQuarter() throws Exception {
String input = "SELECT quarter(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT EXTRACT(QUARTER FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testSecond() throws Exception {
+ @Test public void testSecond() throws Exception {
String input = "SELECT second(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT EXTRACT(SECOND FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testWeek() throws Exception {
+ @Test public void testWeek() throws Exception {
String input = "SELECT week(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT EXTRACT(WEEK FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testYear() throws Exception {
+ @Test public void testYear() throws Exception {
String input = "SELECT year(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT EXTRACT(YEAR FROM to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testDayName() throws Exception {
+ @Test public void testDayName() throws Exception {
String input = "SELECT dayname(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT RTRIM(TO_CHAR(to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF'), 'Day')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testMonthName() throws Exception {
+ @Test public void testMonthName() throws Exception {
String input = "SELECT monthname(convert(PART_WEIGHT, timestamp)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT RTRIM(TO_CHAR(to_timestamp(PARTS.PART_WEIGHT, 'YYYY-MM-DD HH24:MI:SS.UF'), 'Month')) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testIfnull() throws Exception {
+ @Test public void testIfnull() throws Exception {
String input = "SELECT ifnull(PART_WEIGHT, 'otherString') FROM PARTS"; //$NON-NLS-1$
String output = "SELECT coalesce(PARTS.PART_WEIGHT, 'otherString') FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testSubstring1() throws Exception {
+ @Test public void testSubstring1() throws Exception {
String input = "SELECT substring(PART_WEIGHT, 1) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT substr(PARTS.PART_WEIGHT, 1) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testSubstring2() throws Exception {
+ @Test public void testSubstring2() throws Exception {
String input = "SELECT substring(PART_WEIGHT, 1, 5) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT substr(PARTS.PART_WEIGHT, 1, 5) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testBooleanAggregate() throws Exception {
+ @Test public void testBooleanAggregate() throws Exception {
String input = "SELECT MIN(convert(PART_WEIGHT, boolean)) FROM PARTS"; //$NON-NLS-1$
String output = "SELECT bool_and(cast(PARTS.PART_WEIGHT AS boolean)) FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
- MODIFIERS,
output);
}
- public void testRowLimit2() throws Exception {
+ @Test public void testRowLimit2() throws Exception {
String input = "select intkey from bqt1.smalla limit 100"; //$NON-NLS-1$
String output = "SELECT SmallA.IntKey FROM SmallA LIMIT 100"; //$NON-NLS-1$
helpTestVisitor(getTestBQTVDB(),
input,
- MODIFIERS,
output);
}
- public void testRowLimit3() throws Exception {
+ @Test public void testRowLimit3() throws Exception {
String input = "select intkey from bqt1.smalla limit 50, 100"; //$NON-NLS-1$
String output = "SELECT SmallA.IntKey FROM SmallA LIMIT 100 OFFSET 50"; //$NON-NLS-1$
helpTestVisitor(getTestBQTVDB(),
input,
- MODIFIERS,
output);
}
- public void testBitFunctions() throws Exception {
+ @Test public void testBitFunctions() throws Exception {
String input = "select bitand(intkey, intnum), bitnot(intkey), bitor(intnum, intkey), bitxor(intnum, intkey) from bqt1.smalla"; //$NON-NLS-1$
String output = "SELECT (SmallA.IntKey & SmallA.IntNum), ~(SmallA.IntKey), (SmallA.IntNum | SmallA.IntKey), (SmallA.IntNum # SmallA.IntKey) FROM SmallA"; //$NON-NLS-1$
helpTestVisitor(getTestBQTVDB(),
input,
- MODIFIERS,
output);
}
+
+ @Test public void testLocate() throws Exception {
+ String input = "select locate('a', stringkey), locate('b', stringkey, 2) from bqt1.smalla"; //$NON-NLS-1$
+ String output = "SELECT position('a' in SmallA.StringKey), position('b' in substr(SmallA.StringKey, 2)) FROM SmallA"; //$NON-NLS-1$
+
+ helpTestVisitor(getTestBQTVDB(),
+ input,
+ output);
+ }
-
}
15 years, 5 months
teiid SVN: r1217 - trunk/runtime/src/main/java/com/metamatrix/jdbc.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-08-06 12:47:07 -0400 (Thu, 06 Aug 2009)
New Revision: 1217
Modified:
trunk/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java
Log:
removing unneeded shutdowninprogress variable
Modified: trunk/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java
===================================================================
--- trunk/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java 2009-08-06 16:34:42 UTC (rev 1216)
+++ trunk/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java 2009-08-06 16:47:07 UTC (rev 1217)
@@ -84,7 +84,6 @@
* already alive.
*/
public class EmbeddedConnectionFactoryImpl implements ServerConnectionFactory {
- private volatile boolean shutdownInProgress = false;
private DQPCore dqp;
private long starttime = -1L;
private Thread shutdownThread;
@@ -315,45 +314,34 @@
Runtime.getRuntime().removeShutdownHook(this.shutdownThread);
}
- // Make sure shutdown is not already in progress; as call to shutdown will close
- // connections; and after the last connection closes, the listener also calls shutdown
- // for normal route.
- if (!this.shutdownInProgress) {
-
- // this will by pass, and only let shutdown called once.
- this.shutdownInProgress = true;
-
- try {
- this.dqp.stop();
- } catch (ApplicationLifecycleException e) {
- LogManager.logWarning(LogConstants.CTX_DQP, e, e.getMessage());
- }
-
- // remove any artifacts which are not cleaned-up
- if (this.workspaceDirectory != null) {
- File file = new File(this.workspaceDirectory);
- if (file.exists()) {
- delete(file);
- }
+ try {
+ this.dqp.stop();
+ } catch (ApplicationLifecycleException e) {
+ LogManager.logWarning(LogConstants.CTX_DQP, e, e.getMessage());
+ }
+
+ // remove any artifacts which are not cleaned-up
+ if (this.workspaceDirectory != null) {
+ File file = new File(this.workspaceDirectory);
+ if (file.exists()) {
+ delete(file);
}
-
- this.dqp = null;
-
- // shutdown the socket transport.
- if (this.socketTransport != null) {
- this.socketTransport.stop();
- this.socketTransport = null;
- }
-
- // shutdown the cache.
- ResourceFinder.getCacheFactory().destroy();
-
- this.shutdownInProgress = false;
-
- this.init = false;
-
- this.restart = restart;
- }
+ }
+
+ this.dqp = null;
+
+ // shutdown the socket transport.
+ if (this.socketTransport != null) {
+ this.socketTransport.stop();
+ this.socketTransport = null;
+ }
+
+ // shutdown the cache.
+ ResourceFinder.getCacheFactory().destroy();
+
+ this.init = false;
+
+ this.restart = restart;
}
private Admin getAdminAPI() {
15 years, 5 months
teiid SVN: r1216 - in trunk: connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2 and 10 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-08-06 12:34:42 -0400 (Thu, 06 Aug 2009)
New Revision: 1216
Added:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCUpdateExecution.java
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbySQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java
trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java
Log:
TEIID-715 TEIID-752 TEIID-753 adding some consistency to null ordering, addressing issues with mysql translator and with bulk updates
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -97,7 +97,7 @@
* Return true if this is a batched update
*/
protected void bindPreparedStatementValues(PreparedStatement stmt, TranslatedCommand tc, int rowCount) throws SQLException {
- List params = tc.getPreparedValues();
+ List<?> params = tc.getPreparedValues();
for (int row = 0; row < rowCount; row++) {
for (int i = 0; i< params.size(); i++) {
@@ -106,12 +106,12 @@
if (paramValue.isMultiValued()) {
value = ((List<?>)value).get(row);
}
- Class paramType = paramValue.getType();
+ Class<?> paramType = paramValue.getType();
sqlTranslator.bindValue(stmt, value, paramType, i+1);
- if (rowCount > 1) {
- stmt.addBatch();
- }
- }
+ }
+ if (rowCount > 1) {
+ stmt.addBatch();
+ }
}
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -122,9 +122,11 @@
} catch (MetaMatrixCoreException e) {
throw new ConnectorException(e);
}
+ PropertiesUtils.setBeanProperties(sqlTranslator, environment.getProperties(), null);
sqlTranslator.initialize(environment);
capabilities = sqlTranslator.getConnectorCapabilities();
+ PropertiesUtils.setBeanProperties(capabilities, environment.getProperties(), null);
createDataSources(dataSourceClassName, connectionProps);
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCUpdateExecution.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -89,10 +89,10 @@
boolean succeeded = false;
boolean commitType = getAutoCommit(null);
- ICommand[] commands = (ICommand[])batchedCommand.getUpdateCommands().toArray(new ICommand[batchedCommand.getUpdateCommands().size()]);
+ ICommand[] commands = batchedCommand.getUpdateCommands().toArray(new ICommand[batchedCommand.getUpdateCommands().size()]);
int[] results = new int[commands.length];
- TranslatedCommand command = null;
+ TranslatedCommand tCommand = null;
try {
// temporarily turn the auto commit off, and set it back to what it was
@@ -106,18 +106,18 @@
TranslatedCommand previousCommand = null;
for (int i = 0; i < commands.length; i++) {
- command = translateCommand(commands[i]);
- if (command.isPrepared()) {
+ tCommand = translateCommand(commands[i]);
+ if (tCommand.isPrepared()) {
PreparedStatement pstmt = null;
- if (previousCommand != null && previousCommand.isPrepared() && previousCommand.getSql().equals(command.getSql())) {
+ if (previousCommand != null && previousCommand.isPrepared() && previousCommand.getSql().equals(tCommand.getSql())) {
pstmt = (PreparedStatement)statement;
} else {
if (!executedCmds.isEmpty()) {
executeBatch(i, results, executedCmds);
}
- pstmt = getPreparedStatement(command.getSql());
+ pstmt = getPreparedStatement(tCommand.getSql());
}
- bindPreparedStatementValues(pstmt, command, 1);
+ bindPreparedStatementValues(pstmt, tCommand, 1);
pstmt.addBatch();
} else {
if (previousCommand != null && previousCommand.isPrepared()) {
@@ -127,17 +127,17 @@
if (statement == null) {
getStatement();
}
- statement.addBatch(command.getSql());
+ statement.addBatch(tCommand.getSql());
}
- executedCmds.add(command);
- previousCommand = command;
+ executedCmds.add(tCommand);
+ previousCommand = tCommand;
}
if (!executedCmds.isEmpty()) {
executeBatch(commands.length, results, executedCmds);
}
succeeded = true;
} catch (SQLException e) {
- throw new JDBCExecutionException(e, command);
+ throw new JDBCExecutionException(e, tCommand);
} finally {
if (commitType) {
restoreAutoCommit(!succeeded, null);
@@ -182,7 +182,7 @@
for (int i = 0; i< translatedComm.getPreparedValues().size(); i++) {
ILiteral paramValue = (ILiteral)translatedComm.getPreparedValues().get(i);
if (paramValue.isMultiValued()) {
- rowCount = ((List<?>)paramValue).size();
+ rowCount = ((List<?>)paramValue.getValue()).size();
break;
}
}
@@ -220,11 +220,14 @@
* @return
* @throws ConnectorException
*/
- private boolean getAutoCommit(TranslatedCommand command) throws ConnectorException {
+ private boolean getAutoCommit(TranslatedCommand tCommand) throws ConnectorException {
+ if (this.context.isTransactional()) {
+ return false;
+ }
try {
return connection.getAutoCommit();
} catch (SQLException err) {
- throw new JDBCExecutionException(err, command);
+ throw new JDBCExecutionException(err, tCommand);
}
}
@@ -236,18 +239,18 @@
* @throws ConnectorException
*/
private void restoreAutoCommit(boolean exceptionOccurred,
- TranslatedCommand command) throws ConnectorException {
+ TranslatedCommand tCommand) throws ConnectorException {
try {
if (exceptionOccurred) {
connection.rollback();
}
} catch (SQLException err) {
- throw new JDBCExecutionException(err, command);
+ throw new JDBCExecutionException(err, tCommand);
} finally {
try {
connection.setAutoCommit(true);
} catch (SQLException err) {
- throw new JDBCExecutionException(err, command);
+ throw new JDBCExecutionException(err, tCommand);
}
}
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/db2/DB2SQLTranslator.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -176,5 +176,8 @@
return expr;
}
-
+ @Override
+ public NullOrder getDefaultNullOrder() {
+ return NullOrder.HIGH;
+ }
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyCapabilities.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbyCapabilities.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -135,7 +135,7 @@
return supportedFunctions;
}
- public void setVersion(String version) {
+ public void setDatabaseVersion(String version) {
this.version = version;
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbySQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbySQLTranslator.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/derby/DerbySQLTranslator.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -37,8 +37,8 @@
*/
public class DerbySQLTranslator extends DB2SQLTranslator {
- public static final String DATABASE_VERSION = "DatabaseVersion"; //$NON-NLS-1$
-
+ private String version = DerbyCapabilities.TEN_1;
+
@Override
public void initialize(ConnectorEnvironment env) throws ConnectorException {
super.initialize(env);
@@ -68,13 +68,12 @@
}
@Override
- public ConnectorCapabilities getConnectorCapabilities()
- throws ConnectorException {
- ConnectorCapabilities capabilities = super.getConnectorCapabilities();
- if (capabilities instanceof DerbyCapabilities) {
- ((DerbyCapabilities)capabilities).setVersion(getEnvironment().getProperties().getProperty(DATABASE_VERSION, DerbyCapabilities.TEN_1));
- }
- return capabilities;
+ public boolean supportsExplicitNullOrdering() {
+ return version.compareTo(DerbyCapabilities.TEN_4) >= 0;
+ }
+
+ public void setDatabaseVersion(String version) {
+ this.version = version;
}
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -64,7 +64,7 @@
@Override
public String translateLiteralTimestamp(Timestamp timestampValue) {
- return "TIMESTAMP('" + formatDateValue(timestampValue) + "')"; //$NON-NLS-1$//$NON-NLS-2$
+ return "{ts '" + formatDateValue(timestampValue) + "'}"; //$NON-NLS-1$//$NON-NLS-2$
}
@Override
@@ -74,7 +74,7 @@
@Override
public int getTimestampNanoPrecision() {
- return 6;
+ return 0;
}
@Override
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -323,6 +323,11 @@
}
@Override
+ public NullOrder getDefaultNullOrder() {
+ return NullOrder.HIGH;
+ }
+
+ @Override
public Class<? extends ConnectorCapabilities> getDefaultCapabilities() {
return OracleCapabilities.class;
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLCapabilities.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -33,8 +33,15 @@
* @since 4.3
*/
public class PostgreSQLCapabilities extends JDBCCapabilities {
-
-
+
+ public static final String EIGHT_0 = "8.0"; //$NON-NLS-1$
+ public static final String EIGHT_1 = "8.1"; //$NON-NLS-1$
+ public static final String EIGHT_2 = "8.2"; //$NON-NLS-1$
+ public static final String EIGHT_3 = "8.3"; //$NON-NLS-1$
+ public static final String EIGHT_4 = "8.4"; //$NON-NLS-1$
+
+ private String version = EIGHT_0;
+
public List<String> getSupportedFunctions() {
List<String> supportedFunctions = new ArrayList<String>();
supportedFunctions.addAll(super.getSupportedFunctions());
@@ -117,9 +124,11 @@
// supportedFunctions.add("PARSETIME"); //$NON-NLS-1$
// supportedFunctions.add("PARSETIMESTAMP"); //$NON-NLS-1$
supportedFunctions.add("QUARTER"); //$NON-NLS-1$
- supportedFunctions.add("SECOND"); //$NON-NLS-1$
-// supportedFunctions.add("TIMESTAMPADD"); //$NON-NLS-1$
-// supportedFunctions.add("TIMESTAMPDIFF"); //$NON-NLS-1$
+ supportedFunctions.add("SECOND"); //$NON-NLS-1$
+ if (this.version.compareTo(EIGHT_2) >= 0) {
+ supportedFunctions.add("TIMESTAMPADD"); //$NON-NLS-1$
+ supportedFunctions.add("TIMESTAMPDIFF"); //$NON-NLS-1$
+ }
supportedFunctions.add("WEEK"); //$NON-NLS-1$
supportedFunctions.add("YEAR"); //$NON-NLS-1$
@@ -268,5 +277,9 @@
@Override
public boolean supportsIntersect() {
return true;
- }
+ }
+
+ public void setDatabaseVersion(String version) {
+ this.version = version;
+ }
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -52,7 +52,9 @@
* Translator class for PostgreSQL. Updated to expect a 8.0+ jdbc client
* @since 4.3
*/
-public class PostgreSQLTranslator extends Translator {
+public class PostgreSQLTranslator extends Translator {
+
+ private String version = PostgreSQLCapabilities.EIGHT_0;
public void initialize(ConnectorEnvironment env) throws ConnectorException {
//TODO: all of the functions (except for convert) can be handled through just the escape syntax
@@ -158,6 +160,16 @@
}
@Override
+ public NullOrder getDefaultNullOrder() {
+ return NullOrder.HIGH;
+ }
+
+ @Override
+ public boolean supportsExplicitNullOrdering() {
+ return version.compareTo(PostgreSQLCapabilities.EIGHT_4) >= 0;
+ }
+
+ @Override
public Class<? extends ConnectorCapabilities> getDefaultCapabilities() {
return PostgreSQLCapabilities.class;
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -37,11 +37,13 @@
import org.teiid.connector.api.ExecutionContext;
import org.teiid.connector.api.TypeFacility;
+import org.teiid.connector.jdbc.translator.Translator.NullOrder;
import org.teiid.connector.language.ICommand;
import org.teiid.connector.language.IFunction;
import org.teiid.connector.language.ILanguageObject;
import org.teiid.connector.language.ILimit;
import org.teiid.connector.language.ILiteral;
+import org.teiid.connector.language.IOrderByItem;
import org.teiid.connector.language.IParameter;
import org.teiid.connector.language.IProcedure;
import org.teiid.connector.language.IParameter.Direction;
@@ -119,6 +121,22 @@
}
}
}
+
+ @Override
+ public void visit(IOrderByItem obj) {
+ super.visit(obj);
+ if (!this.translator.supportsExplicitNullOrdering()) {
+ return;
+ }
+ NullOrder nullOrder = this.translator.getDefaultNullOrder();
+ if (obj.getDirection() == IOrderByItem.ASC) {
+ if (nullOrder != NullOrder.LOW && nullOrder != NullOrder.FIRST) {
+ buffer.append(" NULLS FIRST"); //$NON-NLS-1$
+ }
+ } else if (nullOrder != NullOrder.HIGH && nullOrder != NullOrder.LAST) {
+ buffer.append(" NULLS LAST"); //$NON-NLS-1$
+ }
+ }
/**
* @param type
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -56,6 +56,7 @@
import org.teiid.connector.language.IParameter;
import org.teiid.connector.language.ISetQuery;
import org.teiid.connector.language.IParameter.Direction;
+import org.teiid.connector.visitor.util.SQLReservedWords;
import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.core.util.ReflectionHelper;
@@ -65,7 +66,14 @@
* Specific databases should override as necessary.
*/
public class Translator {
-
+
+ public enum NullOrder {
+ HIGH,
+ LOW,
+ FIRST,
+ LAST
+ }
+
// Because the retrieveValue() method will be hit for every value of
// every JDBC result set returned, we do lots of weird special stuff here
// to improve the performance (most importantly to remove big if/else checks
@@ -296,6 +304,8 @@
if (getTimestampNanoPrecision() > 0) {
int mask = 10^(9-getTimestampNanoPrecision());
newTs.setNanos(ts.getNanos()/mask*mask);
+ } else {
+ newTs.setNanos(0);
}
dateObject = newTs;
}
@@ -784,4 +794,16 @@
public boolean useParensForJoins() {
return false;
}
+
+ /**
+ * get the default null ordering
+ * @return
+ */
+ public NullOrder getDefaultNullOrder() {
+ return NullOrder.LOW;
+ }
+
+ public boolean supportsExplicitNullOrdering() {
+ return true;
+ }
}
Modified: trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml
===================================================================
--- trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml 2009-08-06 16:34:42 UTC (rev 1216)
@@ -86,6 +86,7 @@
<PropertyDefinition Name="ConnectionSource" DisplayName="Connection Source Class" ShortDescription="Driver, DataSource, or XADataSource class name" DefaultValue="org.postgresql.Driver" IsRequired="true" />
<PropertyDefinition Name="URL" DisplayName="JDBC URL" ShortDescription="" DefaultValue="jdbc:postgresql://<host>:5432/<databaseName>" IsRequired="true" PropertyType="String" IsMasked="false" />
<PropertyDefinition Name="ExtensionTranslationClass" DisplayName="Extension SQL Translation Class" ShortDescription="" DefaultValue="org.teiid.connector.jdbc.postgresql.PostgreSQLTranslator" PropertyType="String" IsExpert="true" IsMasked="false" />
+ <PropertyDefinition Name="DatabaseVersion" DisplayName="Database Version" ShortDescription="PostgreSQL Version i.e. 8.3" DefaultValue="8.0" PropertyType="String" />
</ComponentType>
<ComponentType Name="PostgreSQL XA JDBC Connector" ComponentTypeCode="2" Deployable="true" Deprecated="false" Monitorable="false" SuperComponentType="JDBC Connector" ParentComponentType="Connectors" LastChangedBy="ConfigurationStartup" CreatedBy="ConfigurationStartup">
<PropertyDefinition Name="ConnectionSource" DisplayName="Connection Source Class" ShortDescription="Driver, DataSource, or XADataSource class name" DefaultValue="org.postgresql.xa.PGXADataSource" IsRequired="true" />
@@ -94,6 +95,7 @@
<PropertyDefinition Name="DatabaseName" DisplayName="Database Name" ShortDescription="" IsRequired="true" PropertyType="String" IsMasked="false" />
<PropertyDefinition Name="ExtensionTranslationClass" DisplayName="Extension SQL Translation Class" ShortDescription="" DefaultValue="org.teiid.connector.jdbc.postgresql.PostgreSQLTranslator" PropertyType="String" IsExpert="true" IsMasked="false" />
<PropertyDefinition Name="IsXA" DisplayName="Is XA" ShortDescription="Is XA" DefaultValue="true" IsRequired="true" PropertyType="Boolean" />
+ <PropertyDefinition Name="DatabaseVersion" DisplayName="Database Version" ShortDescription="PostgreSQL Version i.e. 8.3" DefaultValue="8.0" PropertyType="String" />
</ComponentType>
<ComponentType Name="Apache Derby Embedded Connector" ComponentTypeCode="2" Deployable="true" Deprecated="false" Monitorable="false" SuperComponentType="JDBC Connector" ParentComponentType="Connectors" LastChangedBy="ConfigurationStartup" CreatedBy="ConfigurationStartup">
<PropertyDefinition Name="ConnectionSource" DisplayName="Connection Source Class" ShortDescription="Driver, DataSource, or XADataSource class name" DefaultValue="org.apache.derby.jdbc.EmbeddedDriver" IsRequired="true" />
Added: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCUpdateExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCUpdateExecution.java (rev 0)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCUpdateExecution.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.teiid.connector.api.ConnectorLogger;
+import org.teiid.connector.api.ExecutionContext;
+import org.teiid.connector.jdbc.translator.Translator;
+import org.teiid.connector.language.ICommand;
+import org.teiid.connector.language.IInsert;
+import org.teiid.connector.language.IInsertExpressionValueSource;
+import org.teiid.connector.language.ILiteral;
+
+import com.metamatrix.cdk.api.EnvironmentUtility;
+
+public class TestJDBCUpdateExecution {
+
+ @Test public void testBulkUpdate() throws Exception {
+ ICommand command = MetadataFactory.helpTranslate(MetadataFactory.BQT_VDB, "insert into bqt1.smalla (intkey, intnum) values (1, 2)"); //$NON-NLS-1$
+ ILiteral value = ((ILiteral)((IInsertExpressionValueSource)((IInsert)command).getValueSource()).getValues().get(0));
+ ILiteral value1 = ((ILiteral)((IInsertExpressionValueSource)((IInsert)command).getValueSource()).getValues().get(1));
+ value.setMultiValued(true);
+ value.setBindValue(true);
+ value.setValue(Arrays.asList(1, 2));
+ value1.setMultiValued(true);
+ value1.setBindValue(true);
+ value1.setValue(Arrays.asList(2, 3));
+ Connection connection = Mockito.mock(Connection.class);
+ PreparedStatement p = Mockito.mock(PreparedStatement.class);
+ Mockito.stub(p.executeBatch()).toReturn(new int [] {1, 1});
+ Mockito.stub(connection.prepareStatement("INSERT INTO SmallA (IntKey, IntNum) VALUES (?, ?)")).toReturn(p); //$NON-NLS-1$
+ Translator sqlTranslator = new Translator();
+ ExecutionContext context = EnvironmentUtility.createSecurityContext("user"); //$NON-NLS-1$
+ JDBCUpdateExecution updateExecution = new JDBCUpdateExecution(command, connection, sqlTranslator, Mockito.mock(ConnectorLogger.class), new Properties(), context);
+ updateExecution.execute();
+ Mockito.verify(p, Mockito.times(2)).addBatch();
+ }
+
+}
Property changes on: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCUpdateExecution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbyCapabilities.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -31,14 +31,14 @@
@Test public void testLimitSupport() {
DerbyCapabilities derbyCapabilities = new DerbyCapabilities();
assertFalse(derbyCapabilities.supportsRowLimit());
- derbyCapabilities.setVersion(DerbyCapabilities.TEN_5);
+ derbyCapabilities.setDatabaseVersion(DerbyCapabilities.TEN_5);
assertTrue(derbyCapabilities.supportsRowLimit());
}
@Test public void testFunctionSupport() {
DerbyCapabilities derbyCapabilities = new DerbyCapabilities();
assertEquals(27, derbyCapabilities.getSupportedFunctions().size());
- derbyCapabilities.setVersion(DerbyCapabilities.TEN_4);
+ derbyCapabilities.setDatabaseVersion(DerbyCapabilities.TEN_4);
assertEquals(43, derbyCapabilities.getSupportedFunctions().size());
}
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -192,5 +192,14 @@
MetadataFactory.helpTestVisitor(MetadataFactory.BQT_VDB,
input,
output, TRANSLATOR);
+ }
+
+ @Test public void testTimestampLiteral() throws Exception {
+ String input = "select smalla.intkey from bqt1.smalla where smalla.timestampvalue = '2009-08-06 12:23:34.999'"; //$NON-NLS-1$
+ String output = "SELECT SmallA.IntKey FROM SmallA WHERE SmallA.TimestampValue = {ts '2009-08-06 12:23:34.0'}"; //$NON-NLS-1$
+
+ MetadataFactory.helpTestVisitor(MetadataFactory.BQT_VDB,
+ input,
+ output, TRANSLATOR);
}
}
Modified: trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2009-08-06 14:43:44 UTC (rev 1215)
+++ trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2009-08-06 16:34:42 UTC (rev 1216)
@@ -301,7 +301,7 @@
helpTestVisitor(getTestVDB(),
"select part_id id FROM parts UNION ALL select part_name FROM parts UNION ALL select part_id FROM parts ORDER BY id", //$NON-NLS-1$
null,
- "(SELECT g_2.PART_ID AS c_0 FROM PARTS g_2 UNION ALL SELECT g_1.PART_NAME AS c_0 FROM PARTS g_1) UNION ALL SELECT g_0.PART_ID AS c_0 FROM PARTS g_0 ORDER BY c_0", //$NON-NLS-1$
+ "(SELECT g_2.PART_ID AS c_0 FROM PARTS g_2 UNION ALL SELECT g_1.PART_NAME AS c_0 FROM PARTS g_1) UNION ALL SELECT g_0.PART_ID AS c_0 FROM PARTS g_0 ORDER BY c_0 NULLS FIRST", //$NON-NLS-1$
true);
}
@@ -309,7 +309,7 @@
helpTestVisitor(getTestVDB(),
"select part_id FROM parts UNION ALL select part_name FROM parts ORDER BY part_id", //$NON-NLS-1$
null,
- "SELECT g_1.PART_ID AS c_0 FROM PARTS g_1 UNION ALL SELECT g_0.PART_NAME AS c_0 FROM PARTS g_0 ORDER BY c_0", //$NON-NLS-1$
+ "SELECT g_1.PART_ID AS c_0 FROM PARTS g_1 UNION ALL SELECT g_0.PART_NAME AS c_0 FROM PARTS g_0 ORDER BY c_0 NULLS FIRST", //$NON-NLS-1$
true);
}
@@ -317,7 +317,7 @@
helpTestVisitor(getTestVDB(),
"select part_id as p FROM parts UNION ALL select part_name FROM parts ORDER BY p", //$NON-NLS-1$
null,
- "SELECT PARTS.PART_ID AS p FROM PARTS UNION ALL SELECT PARTS.PART_NAME FROM PARTS ORDER BY p"); //$NON-NLS-1$
+ "SELECT PARTS.PART_ID AS p FROM PARTS UNION ALL SELECT PARTS.PART_NAME FROM PARTS ORDER BY p NULLS FIRST"); //$NON-NLS-1$
}
@Test public void testUpdateWithFunction() throws Exception {
@@ -458,7 +458,7 @@
@Test public void testLimitWithNestedInlineView() throws Exception {
String input = "select max(intkey), stringkey from (select intkey, stringkey from bqt1.smalla order by intkey limit 100) x group by stringkey"; //$NON-NLS-1$
- String output = "SELECT MAX(x.intkey), x.stringkey FROM (SELECT * FROM (SELECT SmallA.IntKey, SmallA.StringKey FROM SmallA ORDER BY intkey) WHERE ROWNUM <= 100) x GROUP BY x.stringkey"; //$NON-NLS-1$
+ String output = "SELECT MAX(x.intkey), x.stringkey FROM (SELECT * FROM (SELECT SmallA.IntKey, SmallA.StringKey FROM SmallA ORDER BY intkey NULLS FIRST) WHERE ROWNUM <= 100) x GROUP BY x.stringkey"; //$NON-NLS-1$
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
@@ -500,7 +500,7 @@
@Test public void testRowLimitWithUnionOrderBy() throws Exception {
String input = "(select intkey from bqt1.smalla limit 50, 100) union select intnum from bqt1.smalla order by intkey"; //$NON-NLS-1$
- String output = "SELECT c_0 FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (SELECT g_1.IntKey AS c_0 FROM SmallA g_1) VIEW_FOR_LIMIT WHERE ROWNUM <= 150) WHERE ROWNUM_ > 50 UNION SELECT g_0.IntNum AS c_0 FROM SmallA g_0 ORDER BY c_0"; //$NON-NLS-1$
+ String output = "SELECT c_0 FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (SELECT g_1.IntKey AS c_0 FROM SmallA g_1) VIEW_FOR_LIMIT WHERE ROWNUM <= 150) WHERE ROWNUM_ > 50 UNION SELECT g_0.IntNum AS c_0 FROM SmallA g_0 ORDER BY c_0 NULLS FIRST"; //$NON-NLS-1$
CommandBuilder commandBuilder = new CommandBuilder(FakeMetadataFactory.exampleBQTCached());
ICommand obj = commandBuilder.getCommand(input, true, true);
15 years, 5 months
teiid SVN: r1215 - trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-08-06 10:43:44 -0400 (Thu, 06 Aug 2009)
New Revision: 1215
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java
Log:
minor fix to clear groups after a raise over a set op
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java 2009-08-05 15:36:27 UTC (rev 1214)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java 2009-08-06 14:43:44 UTC (rev 1215)
@@ -161,9 +161,8 @@
}
NodeEditor.removeChildNode(parentNode, node);
}
- rootNode = performRaise(rootNode, accessNode, parentNode);
-
- return rootNode;
+ accessNode.getGroups().clear();
+ return performRaise(rootNode, accessNode, parentNode);
case NodeConstants.Types.SELECT:
{
if (!parentNode.hasBooleanProperty(NodeConstants.Info.IS_DEPENDENT_SET) && canRaiseOverSelect(accessNode, metadata, capFinder, parentNode)) {
15 years, 5 months
teiid SVN: r1214 - trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/http.
by teiid-commits@lists.jboss.org
Author: jdoyle
Date: 2009-08-05 11:36:27 -0400 (Wed, 05 Aug 2009)
New Revision: 1214
Removed:
trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/http/HTTPTestServer.java
trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/http/TestNoArgConnector.java
Log:
TEIID-749
Removing occasionally failing test.
Deleted: trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/http/HTTPTestServer.java
===================================================================
--- trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/http/HTTPTestServer.java 2009-08-04 17:49:52 UTC (rev 1213)
+++ trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/http/HTTPTestServer.java 2009-08-05 15:36:27 UTC (rev 1214)
@@ -1,52 +0,0 @@
-package com.metamatrix.connector.xml.http;
-
-import org.mortbay.jetty.Handler;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.handler.DefaultHandler;
-import org.mortbay.jetty.handler.HandlerList;
-import org.mortbay.jetty.handler.ResourceHandler;
-import org.mortbay.jetty.servlet.Context;
-
-import com.metamatrix.connector.xml.base.ProxyObjectFactory;
-
-public class HTTPTestServer {
-
- private static Server server;
-
- public HTTPTestServer() {
- server = initServer();
-
- try {
- server.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private static Server initServer() {
- Server srv = new Server(8673);
- ResourceHandler handler = new ResourceHandler();
- handler.setResourceBase(ProxyObjectFactory.getDocumentsFolder());
-
- Context context = new Context(srv, "/servlets");
- //context.addServlet("com.metamatrix.test.servlet.EchoServlet", "/Echo");
- //context.addServlet("com.metamatrix.test.servlet.MockResponseServlet", "/Mock");
- context.addServlet("com.metamatrix.test.servlet.NameValueServlet", "/requestTest/NameValue");
- //context.addServlet("com.metamatrix.test.servlet.DocNameValueServlet", "/requestTest/docNameValue");
- //context.addServlet("com.metamatrix.test.servlet.DocPostBodyServlet", "/requestTest/docPostBody");
-
- HandlerList hList = new HandlerList();
- hList.setHandlers(new Handler[]{handler, context, new DefaultHandler()});
- srv.setHandler(hList);
- return srv;
- }
-
- public void stop() {
- try {
- server.stop();
- } catch (Exception e) {
- // shutting down.
- }
- }
-
-}
\ No newline at end of file
Deleted: trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/http/TestNoArgConnector.java
===================================================================
--- trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/http/TestNoArgConnector.java 2009-08-04 17:49:52 UTC (rev 1213)
+++ trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/http/TestNoArgConnector.java 2009-08-05 15:36:27 UTC (rev 1214)
@@ -1,45 +0,0 @@
-package com.metamatrix.connector.xml.http;
-
-
-import java.util.List;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import org.teiid.connector.api.Connector;
-import org.teiid.connector.api.ConnectorException;
-
-import com.metamatrix.cdk.api.ConnectorHost;
-import com.metamatrix.connector.xml.base.ProxyObjectFactory;
-import com.metamatrix.connector.xml.base.XMLConnector;
-import com.metamatrix.connector.xml.base.XMLConnectorStateImpl;
-
-public class TestNoArgConnector extends TestCase {
-
- Connector connector;
- ConnectorHost host;
- HTTPTestServer server;
-
- @Override
- public void setUp() throws Exception {
- server = new HTTPTestServer();
-
- connector = new XMLConnector();
- Properties props = ProxyObjectFactory.getDefaultHttpProps();
- props.setProperty(HTTPConnectorState.URI, "http://0.0.0.0:8673/purchaseOrdersShort.xml");
- props.setProperty(HTTPConnectorState.PARAMETER_METHOD, HTTPConnectorState.PARAMETER_NONE);
- props.setProperty(XMLConnectorStateImpl.CACHE_ENABLED, "true");
- String vdbPath = ProxyObjectFactory.getDocumentsFolder() + "/purchase_orders.vdb";
- host = new ConnectorHost(connector, props, vdbPath);
- host.setSecurityContext("purchase_orders", "1", "root", null);
- }
-
- public void testSelect() {
- try {
- List result = host.executeCommand("SELECT * FROM po_list_noargs.ITEM");
- assertEquals(2, result.size());
- } catch (ConnectorException e) {
- fail(e.getMessage());
- }
- }
-}
15 years, 5 months
teiid SVN: r1213 - trunk/runtime/src/main/java/org/teiid/transport.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-08-04 13:49:52 -0400 (Tue, 04 Aug 2009)
New Revision: 1213
Modified:
trunk/runtime/src/main/java/org/teiid/transport/SSLConfiguration.java
Log:
TEIID-665: correcting regression of previous code. Also, making the ssl enablement independent of crypto enablement.
Modified: trunk/runtime/src/main/java/org/teiid/transport/SSLConfiguration.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/SSLConfiguration.java 2009-08-04 16:37:03 UTC (rev 1212)
+++ trunk/runtime/src/main/java/org/teiid/transport/SSLConfiguration.java 2009-08-04 17:49:52 UTC (rev 1213)
@@ -80,11 +80,10 @@
boolean client_encryption_enabled = false;
public void init(Properties props) {
- ssl_enabled = PropertiesUtils.getBooleanProperty(props, SSL_ENABLED, false);
+ ssl_enabled = PropertiesUtils.getBooleanProperty(props, SSL_ENABLED, false);
+ client_encryption_enabled = PropertiesUtils.getBooleanProperty(props, CLIENT_ENCRYPTION_ENABLED, true);
if (ssl_enabled) {
- client_encryption_enabled = PropertiesUtils.getBooleanProperty(props, CLIENT_ENCRYPTION_ENABLED, true);
-
keyStoreFileName = props.getProperty(KEYSTORE_FILENAME);
try {
keyStorePassword = CryptoUtil.stringDecrypt(props.getProperty(KEYSTORE_PASSWORD, "")); //$NON-NLS-1$
@@ -142,11 +141,11 @@
}
public boolean isServerSSLEnabled() {
- return ssl_enabled && CryptoUtil.isEncryptionEnabled();
+ return this.ssl_enabled;
}
public boolean isClientEncryptionEnabled() {
- return CryptoUtil.isEncryptionEnabled() && client_encryption_enabled;
+ return this.client_encryption_enabled;
}
}
15 years, 5 months
teiid SVN: r1212 - in trunk/engine/src: main/java/com/metamatrix/query/resolver/util and 6 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-08-04 12:37:03 -0400 (Tue, 04 Aug 2009)
New Revision: 1212
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinRegion.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/NewCalculateCostUtil.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleChooseDependent.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCleanCriteria.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCopyCriteria.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeCriteria.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestDependentJoins.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCalculateCostUtil.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestRulePushSelectCriteria.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLProcessor.java
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
Log:
TEIID-746 TEIID-747 updates to costing for composite keys and better handling of ndv, nnv, set ops, etc.
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinRegion.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinRegion.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinRegion.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -315,8 +315,7 @@
public void initializeCostingInformation(QueryMetadataInterface metadata) throws QueryMetadataException, MetaMatrixComponentException {
for (Iterator i = joinSourceNodes.values().iterator(); i.hasNext();) {
PlanNode node = (PlanNode)i.next();
- float value = NewCalculateCostUtil.computeCostForTree(node, metadata);
- node.setProperty(NodeConstants.Info.EST_CARDINALITY, new Float(value));
+ NewCalculateCostUtil.computeCostForTree(node, metadata);
}
estimateCriteriaSelectivity(metadata);
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/NewCalculateCostUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/NewCalculateCostUtil.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/NewCalculateCostUtil.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -26,6 +26,7 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -77,8 +78,6 @@
public static final float UNKNOWN_VALUE = -1;
- public static final int DEFAULT_STRONG_COST = 10;
-
// These batch size should generally not be used as they should be retrieved from the
// command context, however they might be used in test scenarios where that is undefined
static final int DEFAULT_PROCESSOR_BATCH_SIZE = 2000;
@@ -86,7 +85,7 @@
// the following variables are used to hold cost estimates (roughly in milliseconds)
private final static float compareTime = .05f; //TODO: a better estimate would be based upon the number of conjuncts
- private final static float readTime = .001f;
+ private final static float readTime = .001f; //TODO: should come from the connector
private final static float procNewRequestTime = 100; //TODO: should come from the connector
private final static float procMoreRequestTime = 15; //TODO: should come from the connector
@@ -177,48 +176,7 @@
}
case NodeConstants.Types.SET_OP:
{
- float cost = 0;
-
- SetQuery.Operation op = (SetQuery.Operation)node.getProperty(NodeConstants.Info.SET_OPERATION);
-
- if (op == SetQuery.Operation.UNION) {
- for (PlanNode childNode : node.getChildren()) {
- float childCost1 = (Float)childNode.getProperty(NodeConstants.Info.EST_CARDINALITY);
- if (childCost1 == UNKNOWN_VALUE) {
- cost = UNKNOWN_VALUE;
- break;
- }
- // All rows will be projected so add both costs together.
- cost += childCost1;
- }
- if (!node.hasBooleanProperty(NodeConstants.Info.USE_ALL)) {
- cost = getDistinctEstimate(node, metadata, cost);
- }
- } else {
- float leftCost = (Float)node.getFirstChild().getProperty(NodeConstants.Info.EST_CARDINALITY);
- leftCost = getDistinctEstimate(node.getFirstChild(), metadata, leftCost);
-
- float rightCost = (Float)node.getLastChild().getProperty(NodeConstants.Info.EST_CARDINALITY);
- rightCost = getDistinctEstimate(node.getLastChild(), metadata, rightCost);
-
- cost = leftCost;
-
- if (op == SetQuery.Operation.EXCEPT) {
- if (leftCost != UNKNOWN_VALUE && rightCost != UNKNOWN_VALUE) {
- cost = Math.max(1, leftCost - rightCost);
- }
- } else {
- if (rightCost != UNKNOWN_VALUE) {
- if (leftCost != UNKNOWN_VALUE) {
- cost = Math.min(leftCost, rightCost);
- } else {
- cost = rightCost;
- }
- }
- }
- }
-
- setCardinalityEstimate(node, new Float(cost));
+ estimateSetOpCost(node, metadata);
break;
}
case NodeConstants.Types.TUPLE_LIMIT:
@@ -249,14 +207,58 @@
}
}
+ private static void estimateSetOpCost(PlanNode node,
+ QueryMetadataInterface metadata) throws QueryMetadataException,
+ MetaMatrixComponentException {
+ float cost = 0;
+
+ SetQuery.Operation op = (SetQuery.Operation)node.getProperty(NodeConstants.Info.SET_OPERATION);
+
+ float leftCost = (Float)node.getFirstChild().getProperty(NodeConstants.Info.EST_CARDINALITY);
+ float rightCost = (Float)node.getLastChild().getProperty(NodeConstants.Info.EST_CARDINALITY);
+
+ if (!node.hasBooleanProperty(NodeConstants.Info.USE_ALL)) {
+ leftCost = getDistinctEstimate(node.getFirstChild(), metadata, leftCost);
+ rightCost = getDistinctEstimate(node.getLastChild(), metadata, rightCost);
+ }
+
+ cost = leftCost;
+
+ switch (op) {
+ case EXCEPT:
+ if (leftCost != UNKNOWN_VALUE && rightCost != UNKNOWN_VALUE) {
+ cost = Math.max(1, leftCost - .5f * rightCost);
+ }
+ break;
+ case INTERSECT:
+ if (rightCost != UNKNOWN_VALUE) {
+ if (leftCost != UNKNOWN_VALUE) {
+ cost = .5f * Math.min(leftCost, rightCost);
+ } else {
+ cost = rightCost;
+ }
+ }
+ break;
+ default: //union
+ if (leftCost != UNKNOWN_VALUE && rightCost != UNKNOWN_VALUE) {
+ if (!node.hasBooleanProperty(NodeConstants.Info.USE_ALL)) {
+ cost = Math.max(leftCost, rightCost) + .5f * Math.min(leftCost, rightCost);
+ } else {
+ cost = rightCost + leftCost;
+ }
+ }
+ break;
+ }
+
+ setCardinalityEstimate(node, new Float(cost));
+ }
+
private static float getDistinctEstimate(PlanNode node,
QueryMetadataInterface metadata, float cost)
throws QueryMetadataException, MetaMatrixComponentException {
- if (!node.hasBooleanProperty(NodeConstants.Info.USE_ALL)) {
- PlanNode projectNode = NodeEditor.findNodePreOrder(node, NodeConstants.Types.PROJECT);
- if (projectNode != null) {
- cost = getDistinctEstimate(projectNode, (List)projectNode.getProperty(NodeConstants.Info.PROJECT_COLS), metadata, cost);
- }
+ PlanNode projectNode = NodeEditor.findNodePreOrder(node, NodeConstants.Types.PROJECT);
+ if (projectNode != null) {
+ cost = getDistinctEstimate(projectNode, (List)projectNode.getProperty(NodeConstants.Info.PROJECT_COLS), metadata, cost);
}
return cost;
}
@@ -393,14 +395,12 @@
if(elements == null) {
return new Float(childCost);
}
- HashSet elems = new HashSet();
- for(Iterator iter = elements.iterator(); iter.hasNext();) {
- Expression expression = (Expression)iter.next();
- ElementCollectorVisitor.getElements(expression, elems);
+ HashSet<ElementSymbol> elems = new HashSet<ElementSymbol>();
+ ElementCollectorVisitor.getElements(elements, elems);
+ if (usesKey(elements, metadata)) {
+ return new Float(childCost);
}
- elements = new ArrayList(elems);
-
- float ndvCost = getMaxNDV(elements, node, childCost, metadata);
+ float ndvCost = getNDV(elems, node, childCost, metadata);
if(ndvCost == UNKNOWN_VALUE) {
ndvCost = childCost;
}
@@ -417,21 +417,15 @@
CompoundCriteria compCrit = (CompoundCriteria) crit;
if (compCrit.getOperator() == CompoundCriteria.OR) {
cost = 0;
- } else { //check for composite key
- HashSet elements = new HashSet();
- Iterator crits = compCrit.getCriteria().iterator();
- while(crits.hasNext()) {
- Criteria aCrit = (Criteria) crits.next();
- collectElementsOfValidCriteria(aCrit, elements);
- }
- if (usesKey(elements, metadata)) {
- return 1;
- }
+ }
+ HashSet<ElementSymbol> elements = new HashSet<ElementSymbol>();
+ collectElementsOfValidCriteria(compCrit, elements);
+ if (usesKey(elements, metadata)) {
+ return 1;
}
- Iterator iter = compCrit.getCriteria().iterator();
- while(iter.hasNext()) {
- float nextCost = recursiveEstimateCostOfCriteria(childCost, currentNode, (Criteria) iter.next(), metadata);
+ for (Criteria critPart : compCrit.getCriteria()) {
+ float nextCost = recursiveEstimateCostOfCriteria(childCost, currentNode, critPart, metadata);
if(compCrit.getOperator() == CompoundCriteria.AND) {
if (nextCost == UNKNOWN_VALUE) {
@@ -496,16 +490,29 @@
* @param elements Collection to collect ElementSymbols in
* @since 4.2
*/
- private static void collectElementsOfValidCriteria(Criteria criteria, Collection elements) {
+ private static void collectElementsOfValidCriteria(Criteria criteria, Collection<ElementSymbol> elements) {
if(criteria instanceof CompoundCriteria) {
CompoundCriteria compCrit = (CompoundCriteria) criteria;
- if(compCrit.getOperator() == CompoundCriteria.AND) {
- Iterator iter = compCrit.getCriteria().iterator();
- while(iter.hasNext()) {
- collectElementsOfValidCriteria((Criteria) iter.next(), elements);
- }
+ Iterator iter = compCrit.getCriteria().iterator();
+ boolean first = true;
+ Collection<ElementSymbol> savedElements = elements;
+ if(compCrit.getOperator() == CompoundCriteria.OR) {
+ elements = new HashSet<ElementSymbol>();
}
+ while(iter.hasNext()) {
+ if(compCrit.getOperator() == CompoundCriteria.AND || first) {
+ collectElementsOfValidCriteria((Criteria) iter.next(), elements);
+ first = false;
+ } else {
+ HashSet<ElementSymbol> other = new HashSet<ElementSymbol>();
+ collectElementsOfValidCriteria((Criteria) iter.next(), other);
+ elements.retainAll(other);
+ }
+ }
+ if (compCrit.getOperator() == CompoundCriteria.OR) {
+ savedElements.addAll(elements);
+ }
} else if(criteria instanceof CompareCriteria) {
CompareCriteria compCrit = (CompareCriteria)criteria;
if (compCrit.getOperator() == CompareCriteria.EQ){
@@ -543,15 +550,15 @@
Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(predicateCriteria, true);
- Collection groups = GroupsUsedByElementsVisitor.getGroups(predicateCriteria);
+ Collection<GroupSymbol> groups = GroupsUsedByElementsVisitor.getGroups(elements);
boolean multiGroup = groups.size() > 1;
float cost = childCost;
- float ndv = getMaxNDV(elements, currentNode, childCost, metadata);
+ float ndv = getNDV(elements, currentNode, childCost, metadata);
boolean unknownChildCost = childCost == UNKNOWN_VALUE;
boolean usesKey = usesKey(elements, metadata);
-
+
if (childCost == UNKNOWN_VALUE) {
childCost = 1;
}
@@ -599,7 +606,7 @@
if (unknownChildCost) {
return UNKNOWN_VALUE;
}
- cost = Math.min(childCost, childCost * setCriteria.getNumberOfValues() / ndv);
+ cost = childCost * setCriteria.getNumberOfValues() / ndv;
isNegatedPredicateCriteria = setCriteria.isNegated();
@@ -618,19 +625,14 @@
} else if(predicateCriteria instanceof IsNullCriteria) {
IsNullCriteria isNullCriteria = (IsNullCriteria)predicateCriteria;
- if(isNullable(elements, metadata)) {
-
- float nnv = getNNV(elements, metadata);
- if (unknownChildCost) {
- return nnv;
- } else if (nnv == UNKNOWN_VALUE) {
- cost = childCost / ndv;
- } else {
- cost = childCost * (nnv / Math.max(1, getCardinality(elements, metadata)));
- }
+ float nnv = getNNV(elements, currentNode, childCost, metadata);
+ if (nnv == UNKNOWN_VALUE) {
+ if (unknownChildCost) {
+ return UNKNOWN_VALUE;
+ }
+ cost = childCost / ndv;
} else {
- // No nulls allowed
- cost = 0;
+ cost = nnv;
}
isNegatedPredicateCriteria = isNullCriteria.isNegated();
@@ -655,11 +657,8 @@
}
/**
- * @param childCost
- * @param cost
- * @param ndv
- * @param matchExpression
- * @return
+ * TODO: does not check for escape char
+ * or if it will contain single match chars
*/
private static float estimateMatchCost(float childCost,
float ndv,
@@ -667,14 +666,8 @@
Expression matchExpression = criteria.getRightExpression();
if(matchExpression instanceof Constant && ((Constant)matchExpression).getType().equals(DataTypeManager.DefaultDataClasses.STRING)) {
String compareValue = (String) ((Constant)matchExpression).getValue();
- if(compareValue != null) {
- if(compareValue.indexOf('%') >= 0) {
- if(compareValue.length() == 1) {
- return childCost;
- }
- } else {
- return childCost / ndv;
- }
+ if(compareValue != null && compareValue.indexOf('%') < 0) {
+ return (childCost / 2) * (1 / 3f + 1 / ndv); //without knowing length constraints we'll make an average guess
}
} else if (EvaluateExpressionVisitor.willBecomeConstant(criteria.getLeftExpression())) {
return childCost / ndv;
@@ -768,7 +761,17 @@
return cost;
}
- static boolean usesKey(Collection<? extends SingleElementSymbol> allElements, QueryMetadataInterface metadata)
+ static boolean usesKey(PlanNode planNode, Collection<? extends SingleElementSymbol> allElements, QueryMetadataInterface metadata) throws QueryMetadataException, MetaMatrixComponentException {
+ return NodeEditor.findAllNodes(planNode, NodeConstants.Types.SOURCE, NodeConstants.Types.JOIN | NodeConstants.Types.SET_OP).size() == 1
+ && usesKey(allElements, metadata);
+ }
+
+ /**
+ * TODO: this uses key check is not really accurate, it doesn't take into consideration where
+ * we are in the plan.
+ * if a key column is used after a non 1-1 join or a union all, then it may be non-unique.
+ */
+ private static boolean usesKey(Collection<? extends SingleElementSymbol> allElements, QueryMetadataInterface metadata)
throws QueryMetadataException, MetaMatrixComponentException {
if(allElements == null || allElements.size() == 0) {
@@ -814,77 +817,78 @@
return false;
}
-
- /**
- * @param elements
- * @param metadata
- * @return
- * @since 4.3
+
+ /**
+ * Get the scaled max ndv for a set of elements.
+ *
+ * NOTE: this is not a good approximation over unions, joins, grouping, etc.
*/
- private static float getCardinality(Collection elements, QueryMetadataInterface metadata)
+ private static float getNDV(Collection<ElementSymbol> elements, PlanNode current, float cardinality, QueryMetadataInterface metadata)
throws QueryMetadataException, MetaMatrixComponentException {
+ float result = 1;
- if(elements.size() != 1) {
- return UNKNOWN_VALUE;
- }
- ElementSymbol elem = (ElementSymbol) elements.iterator().next();
- Object groupID = elem.getGroupSymbol().getMetadataID();
- return metadata.getCardinality(groupID);
- }
-
- private static float getMaxNDV(Collection elements, PlanNode currentNode, float estNodeCardinality, QueryMetadataInterface metadata)
- throws QueryMetadataException, MetaMatrixComponentException {
-
- if(elements.isEmpty()) {
- return UNKNOWN_VALUE;
- }
-
- float ndv = UNKNOWN_VALUE;
-
- Iterator elementIterator = elements.iterator();
- while(elementIterator.hasNext()) {
- ElementSymbol elem = (ElementSymbol) elementIterator.next();
- ndv = Math.max(ndv, estimateNDVForSymbol(elem, currentNode, estNodeCardinality, metadata));
- if(ndv == UNKNOWN_VALUE) {
- return UNKNOWN_VALUE;
+ for (ElementSymbol elementSymbol : elements) {
+ Object elemID = elementSymbol.getMetadataID();
+ float ndv = metadata.getDistinctValues(elemID);
+ if (ndv == UNKNOWN_VALUE) {
+ if (metadata.isVirtualGroup(elementSymbol.getGroupSymbol().getMetadataID()) && !metadata.isProcedure(elementSymbol.getGroupSymbol().getMetadataID())) {
+ PlanNode sourceNode = FrameUtil.findOriginatingNode(current, new HashSet<GroupSymbol>(Arrays.asList(elementSymbol.getGroupSymbol())));
+ if (sourceNode != null) {
+ SymbolMap symbolMap = (SymbolMap)sourceNode.getProperty(NodeConstants.Info.SYMBOL_MAP);
+ Expression expr = symbolMap.getMappedExpression(elementSymbol);
+ ndv = getNDV(ElementCollectorVisitor.getElements(expr, true), sourceNode.getFirstChild(), cardinality, metadata);
+ }
+ }
+ if (ndv == UNKNOWN_VALUE) {
+ return UNKNOWN_VALUE;
+ }
+ } else if (cardinality != UNKNOWN_VALUE) {
+ int groupCardinality = metadata.getCardinality(elementSymbol.getGroupSymbol().getMetadataID());
+ if (groupCardinality != UNKNOWN_VALUE) {
+ ndv *= cardinality / Math.max(1, groupCardinality);
+ }
}
- }
-
- return ndv;
+ result = Math.max(result, ndv);
+ }
+ return result;
}
- /**
- * @param elements
- * @return
- * @since 4.3
+ /**
+ * Get the scaled max nnv for a set of elements.
+ *
+ * NOTE: assumes that the expression does not allow nulls
*/
- private static boolean isNullable(Collection elements, QueryMetadataInterface metadata)
+ private static float getNNV(Collection<ElementSymbol> elements, PlanNode current, float cardinality, QueryMetadataInterface metadata)
throws QueryMetadataException, MetaMatrixComponentException {
-
- if(elements.size() != 1) {
- return true;
- }
- ElementSymbol elem = (ElementSymbol) elements.iterator().next();
- Object elemID = elem.getMetadataID();
- return metadata.elementSupports(elemID, SupportConstants.Element.NULL) ||
- metadata.elementSupports(elemID, SupportConstants.Element.NULL_UNKNOWN);
+ float result = 0;
+ for (ElementSymbol elementSymbol : elements) {
+ Object elemID = elementSymbol.getMetadataID();
+ float nnv = metadata.getNullValues(elemID);
+ if (nnv == UNKNOWN_VALUE) {
+ if (!metadata.elementSupports(elemID, SupportConstants.Element.NULL)
+ && !metadata.elementSupports(elemID, SupportConstants.Element.NULL_UNKNOWN)) {
+ nnv = 0;
+ } else if (metadata.isVirtualGroup(elementSymbol.getGroupSymbol().getMetadataID()) && !metadata.isProcedure(elementSymbol.getGroupSymbol().getMetadataID())) {
+ PlanNode sourceNode = FrameUtil.findOriginatingNode(current, new HashSet<GroupSymbol>(Arrays.asList(elementSymbol.getGroupSymbol())));
+ if (sourceNode != null) {
+ SymbolMap symbolMap = (SymbolMap)sourceNode.getProperty(NodeConstants.Info.SYMBOL_MAP);
+ Expression expr = symbolMap.getMappedExpression(elementSymbol);
+ nnv = getNNV(ElementCollectorVisitor.getElements(expr, true), sourceNode.getFirstChild(), cardinality, metadata);
+ }
+ }
+ if (nnv == UNKNOWN_VALUE) {
+ return UNKNOWN_VALUE;
+ }
+ } else if (cardinality != UNKNOWN_VALUE) {
+ int groupCardinality = metadata.getCardinality(elementSymbol.getGroupSymbol().getMetadataID());
+ if (groupCardinality != UNKNOWN_VALUE) {
+ nnv *= cardinality / Math.max(1, groupCardinality);
+ }
+ }
+ result = Math.max(result, nnv);
+ }
+ return result;
}
-
- /**
- * @param elements
- * @return
- * @since 4.3
- */
- private static float getNNV(Collection elements, QueryMetadataInterface metadata)
- throws QueryMetadataException, MetaMatrixComponentException {
-
- if(elements.size() != 1) {
- return UNKNOWN_VALUE;
- }
- ElementSymbol elem = (ElementSymbol) elements.iterator().next();
- Object elemID = elem.getMetadataID();
- return metadata.getNullValues(elemID);
- }
/**
* Computes the cost of a Merge Join
@@ -1066,9 +1070,9 @@
float result = UNKNOWN_VALUE;
for(Iterator iter = expressions.iterator(); iter.hasNext();) {
Expression expr = (Expression)iter.next();
- Collection symbols = ElementCollectorVisitor.getElements(expr, true);
+ Collection<ElementSymbol> symbols = ElementCollectorVisitor.getElements(expr, true);
- float currentSymbolNDV = getMaxNDV(symbols, node, nodeCardinality, metadata);
+ float currentSymbolNDV = getNDV(symbols, node, nodeCardinality, metadata);
if(currentSymbolNDV == UNKNOWN_VALUE) {
if (usesKey(symbols, metadata)) {
@@ -1088,129 +1092,4 @@
return Math.max(1, Math.min(nodeCardinality, result));
}
- /**
- * For virtual symbol, find a mapped physical symbol and look up it's NDV
- *
- * @param currentDepSymbol The current virtual dependent symbol
- * @param dependentNode The dependent node starting point
- * @param metadata Metadata API
- * @return NDV for currentDepSymbol
- * @since 5.0.1
- */
- private static float getMappedPhysicalNDV(ElementSymbol currentDepSymbol,
- PlanNode dependentNode,
- QueryMetadataInterface metadata) throws MetaMatrixComponentException {
-
- PlanNode currentNode = dependentNode;
-
- while(true) {
- // Walk down to a source node
- PlanNode sourceNode = FrameUtil.findOriginatingNode(currentNode, dependentNode.getGroups());
- if(sourceNode == null) {
- break;
- }
-
- if (sourceNode.getType() == NodeConstants.Types.SOURCE) {
- SymbolMap symbolMap = (SymbolMap) sourceNode.getProperty(NodeConstants.Info.SYMBOL_MAP);
-
- if (symbolMap == null) {
- return UNKNOWN_VALUE;
- }
-
- Expression currentExpr = symbolMap.getMappedExpression(currentDepSymbol);
-
- if (currentExpr == null) {
- return UNKNOWN_VALUE;
- }
-
- if(! (currentExpr instanceof ElementSymbol)) {
- // Not a 1-to-1 mapping - check for single contained element to use instead. This
- // is a bit of a hack as it will work just fine in some cases (like convert(elem, Double))
- // and will suck badly in others that change the size of the value domain. If there is
- // more than 1 element, we'll just give up for now - probably some heuristic we can use later.
- Collection elements = ElementCollectorVisitor.getElements(currentExpr, false, false);
- switch(elements.size()) {
- case 0:
- {
- // Must be a constant, so use NDV=1
- return 1;
- }
- case 1:
- {
- // Just switch to using the current expression
- currentDepSymbol = (ElementSymbol) elements.iterator().next();
- break;
- }
- default:
- {
- // More than 1 element in lower expression - give up!
- return UNKNOWN_VALUE;
- }
-
- }
- }
- }
-
- // Check for physical element and if so, break out of the loop
- try {
- if(! metadata.isVirtualGroup(currentDepSymbol.getGroupSymbol().getMetadataID())) {
- return metadata.getDistinctValues(currentDepSymbol.getMetadataID());
- }
- currentNode = currentNode.getFirstChild();
- } catch(QueryMetadataException e) {
- throw new MetaMatrixComponentException(e, e.getMessage());
- }
- }
- return UNKNOWN_VALUE;
- }
-
- /**
- * This method will return an estimate NDV of a symbol based on the cost of the input node and the ratio of
- * the input symbol's NDV value to the input symbol's Group's cardinality.
- */
- private static float estimateNDVForSymbol(ElementSymbol symbol, PlanNode currentNode, float estNodeCardinality, QueryMetadataInterface metadata)
- throws MetaMatrixComponentException, QueryMetadataException {
-
- if(symbol == null) {
- return UNKNOWN_VALUE;
- }
-
- float ndv = 0;
- float tableCardinality = 0;
- Object elemID = symbol.getMetadataID();
- Object groupID = symbol.getGroupSymbol().getMetadataID();
-
- if (metadata.isVirtualGroup(groupID)) {
- return getMappedPhysicalNDV(symbol, currentNode, metadata);
- }
-
- if(elemID != null && groupID != null) {
- ndv = metadata.getDistinctValues(elemID);
- tableCardinality = metadata.getCardinality(groupID);
- }
- // if ndv is <= 0 the value is considered unknown and we return UNKNOWN_VALUE
- if(ndv <= 0) {
- return UNKNOWN_VALUE;
- }
- float estNDV = estNodeCardinality * ndv / tableCardinality;
- if(estNDV < ndv) {
- return Math.max(1, estNDV);
- }
- return Math.max(1, ndv);
- }
-
- static boolean isNodeStrong(PlanNode accessNode, QueryMetadataInterface metadata, CommandContext context)
- throws QueryMetadataException, MetaMatrixComponentException {
-
- float result = computeCostForTree(accessNode, metadata);
-
- float strong_cost = DEFAULT_STRONG_COST;
-
- if(context != null) {
- strong_cost = Math.min(strong_cost, context.getProcessorBatchSize());
- }
-
- return result != UNKNOWN_VALUE && result <= strong_cost;
- }
-
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleChooseDependent.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleChooseDependent.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleChooseDependent.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -61,6 +61,8 @@
boolean leftCandidate;
boolean rightCandidate;
}
+
+ public static final int DEFAULT_INDEPENDENT_CARDINALITY = 10;
public PlanNode execute(PlanNode plan, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, RuleStack rules, AnalysisRecord analysisRecord, CommandContext context)
throws QueryPlannerException, QueryMetadataException, MetaMatrixComponentException {
@@ -104,25 +106,14 @@
if (depJoinCost != NewCalculateCostUtil.UNKNOWN_VALUE) {
pushCriteria |= decideForAgainstDependentJoin(depJoinCost, independentNode, dependentNode, joinNode, metadata, context);
} else {
- boolean siblingStrong = NewCalculateCostUtil.isNodeStrong(siblingNode, metadata, context);
- boolean sourceStrong = NewCalculateCostUtil.isNodeStrong(sourceNode, metadata, context);
-
- if (!bothCandidates) {
- if (siblingStrong) {
- pushCriteria |= markDependent(sourceNode, joinNode);
- }
- } else {
- if (siblingStrong && !sourceStrong) {
- pushCriteria |= markDependent(sourceNode, joinNode);
- } else if (!siblingStrong && sourceStrong) {
- pushCriteria |= markDependent(siblingNode, joinNode);
- } else if (siblingStrong && sourceStrong) {
- if (NewCalculateCostUtil.computeCostForTree(sourceNode, metadata) <= NewCalculateCostUtil.computeCostForTree(siblingNode, metadata)) {
- pushCriteria |= markDependent(siblingNode, joinNode);
- } else {
- pushCriteria |= markDependent(sourceNode, joinNode);
- }
- }
+ float sourceCost = NewCalculateCostUtil.computeCostForTree(sourceNode, metadata);
+ float siblingCost = NewCalculateCostUtil.computeCostForTree(siblingNode, metadata);
+
+ if (bothCandidates && sourceCost != NewCalculateCostUtil.UNKNOWN_VALUE && sourceCost < RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY
+ && (sourceCost < siblingCost || siblingCost == NewCalculateCostUtil.UNKNOWN_VALUE)) {
+ pushCriteria |= markDependent(siblingNode, joinNode);
+ } else if (siblingCost != NewCalculateCostUtil.UNKNOWN_VALUE && siblingCost < RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY) {
+ pushCriteria |= markDependent(sourceNode, joinNode);
}
}
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCleanCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCleanCriteria.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCleanCriteria.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -22,9 +22,6 @@
package com.metamatrix.query.optimizer.relational.rules;
-import java.util.Iterator;
-import java.util.List;
-
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.CriteriaEvaluationException;
import com.metamatrix.api.exception.query.QueryPlannerException;
@@ -53,14 +50,9 @@
public PlanNode execute(PlanNode plan, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, RuleStack rules, AnalysisRecord analysisRecord, CommandContext context)
throws QueryPlannerException, MetaMatrixComponentException {
- List criteria = NodeEditor.findAllNodes(plan, NodeConstants.Types.SELECT);
-
- Iterator critIter = criteria.iterator();
-
boolean pushRaiseNull = false;
- while (critIter.hasNext()) {
- PlanNode critNode = (PlanNode)critIter.next();
+ for (PlanNode critNode : NodeEditor.findAllNodes(plan, NodeConstants.Types.SELECT)) {
if (critNode.hasBooleanProperty(NodeConstants.Info.IS_PHANTOM)) {
NodeEditor.removeChildNode(critNode.getParent(), critNode);
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -160,7 +160,7 @@
*/
if (queryCommand instanceof SetQuery) {
((SetQuery)queryCommand).setAll(false);
- } else if (!NewCalculateCostUtil.usesKey(queryCommand.getProjectedSymbols(), metadata) && CapabilitiesUtil.supports(Capability.QUERY_SELECT_DISTINCT, RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata), metadata, capFinder)) {
+ } else if (!NewCalculateCostUtil.usesKey(accessNode, queryCommand.getProjectedSymbols(), metadata) && CapabilitiesUtil.supports(Capability.QUERY_SELECT_DISTINCT, RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata), metadata, capFinder)) {
//TODO: could check for group by and a select clause containing all group by expressions
((Query)queryCommand).getSelect().setDistinct(true);
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCopyCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCopyCriteria.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCopyCriteria.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -339,13 +339,13 @@
Set allCriteria) {
//First examine criteria in critNode for suitability
Criteria crit = (Criteria) node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
- if(node.getGroups().size() == 1 && crit != null) {
-
+ if(node.getGroups().size() == 1) {
+ List<Criteria> crits = Criteria.separateCriteriaByAnd(crit);
if(!node.hasBooleanProperty(NodeConstants.Info.IS_HAVING) && node.getSubqueryContainers().isEmpty()) {
if (!node.hasBooleanProperty(NodeConstants.Info.IS_COPIED)) {
- toCopy.add(crit);
+ toCopy.addAll(crits);
}
- allCriteria.add(crit);
+ allCriteria.addAll(crits);
}
}
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -129,7 +129,7 @@
PlanNode sortNode = createSortNode(orderSymbols, outputSymbols, directions);
if (sourceNode.getType() == NodeConstants.Types.ACCESS) {
- if (NewCalculateCostUtil.usesKey(expressions, metadata)) {
+ if (NewCalculateCostUtil.usesKey(sourceNode, expressions, metadata)) {
joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.IS_LEFT_DISTINCT : NodeConstants.Info.IS_RIGHT_DISTINCT, true);
}
if (attemptPush && RuleRaiseAccess.canRaiseOverSort(sourceNode, metadata, capFinder, sortNode)) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeCriteria.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeCriteria.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -42,6 +42,7 @@
import com.metamatrix.query.util.CommandContext;
/**
+ * TODO: this rule should attempt to intelligently order the criteria
*/
public final class RuleMergeCriteria implements OptimizerRule {
@@ -92,14 +93,14 @@
}
}
- void mergeChain(PlanNode chainRoot) {
+ static void mergeChain(PlanNode chainRoot) {
// Remove all of chain except root, collect crit from each
CompoundCriteria critParts = new CompoundCriteria();
PlanNode current = chainRoot;
boolean isDependentSet = false;
while(current.getType() == NodeConstants.Types.SELECT) {
- critParts.addCriteria((Criteria)current.getProperty(NodeConstants.Info.SELECT_CRITERIA));
+ critParts.getCriteria().add(0, (Criteria)current.getProperty(NodeConstants.Info.SELECT_CRITERIA));
isDependentSet |= current.hasBooleanProperty(NodeConstants.Info.IS_DEPENDENT_SET);
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -409,10 +409,7 @@
collectSymbolsFromOtherAggregates(allAggregates, aggregates, planNode, stagedGroupingSymbols);
//if the grouping expressions are unique then there's no point in staging the aggregate
- //TODO: the uses key check is not really accurate, it doesn't take into consideration where
- //we are in the plan.
- //if a key column is used after a non 1-1 join or a union all, then it may be non-unique.
- if (NewCalculateCostUtil.usesKey(stagedGroupingSymbols, metadata)) {
+ if (NewCalculateCostUtil.usesKey(planNode, stagedGroupingSymbols, metadata)) {
continue;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -235,6 +235,8 @@
void pushTowardOriginatingNode(PlanNode sourceNode, PlanNode critNode, QueryMetadataInterface metadata, CapabilitiesFinder capFinder)
throws QueryPlannerException, QueryMetadataException, MetaMatrixComponentException {
+ boolean groupSelects = sourceNode.getParent().getType() == NodeConstants.Types.SELECT && sourceNode.getChildCount() == 0;
+
//to keep a stable criteria ordering, move the sourceNode to the top of the criteria chain
while (sourceNode.getParent().getType() == NodeConstants.Types.SELECT) {
sourceNode = sourceNode.getParent();
@@ -247,6 +249,9 @@
PlanNode destination = examinePath(critNode, sourceNode, metadata, capFinder);
NodeEditor.removeChildNode(critNode.getParent(), critNode);
destination.addAsParent(critNode);
+ if (groupSelects && destination == sourceNode) {
+ RuleMergeCriteria.mergeChain(critNode);
+ }
}
/**
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -493,9 +493,9 @@
* The resolved elements may not contain non-selectable columns depending on the metadata first used for resolving.
*
*/
- public static List resolveElementsInGroup(GroupSymbol group, QueryMetadataInterface metadata)
+ public static List<ElementSymbol> resolveElementsInGroup(GroupSymbol group, QueryMetadataInterface metadata)
throws QueryMetadataException, MetaMatrixComponentException {
- return new ArrayList(getGroupInfo(group, metadata).getSymbolList());
+ return new ArrayList<ElementSymbol>(getGroupInfo(group, metadata).getSymbolList());
}
static GroupInfo getGroupInfo(GroupSymbol group,
Modified: trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -27,8 +27,6 @@
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -1877,7 +1875,10 @@
// if both left and right expressions are strings, and the LIKE match characters ('*', '_') are not present
// in the right expression, rewrite the criteria as EQUALs rather than LIKE
if(DataTypeManager.DefaultDataClasses.STRING.equals(criteria.getLeftExpression().getType()) && value.indexOf(escape) < 0 && value.indexOf(MatchCriteria.MATCH_CHAR) < 0 && value.indexOf(MatchCriteria.WILDCARD_CHAR) < 0) {
- return rewriteCriteria(new CompareCriteria(criteria.getLeftExpression(), criteria.isNegated()?CompareCriteria.NE:CompareCriteria.EQ, criteria.getRightExpression()), procCommand, context, metadata);
+ if (value.equals(MatchCriteria.WILDCARD_CHAR)) {
+ return TRUE_CRITERIA;
+ }
+ return rewriteCriteria(new CompareCriteria(criteria.getLeftExpression(), criteria.isNegated()?CompareCriteria.NE:CompareCriteria.EQ, criteria.getRightExpression()), procCommand, context, metadata);
}
}
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestDependentJoins.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestDependentJoins.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestDependentJoins.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -34,7 +34,7 @@
import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.optimizer.relational.rules.NewCalculateCostUtil;
+import com.metamatrix.query.optimizer.relational.rules.RuleChooseDependent;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.relational.AccessNode;
import com.metamatrix.query.processor.relational.DependentAccessNode;
@@ -496,7 +496,7 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject obj = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- obj.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1));
+ obj.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,
null, capFinder,
@@ -532,7 +532,7 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject obj = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- obj.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1));
+ obj.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1));
ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,
null, capFinder,
@@ -571,11 +571,11 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1));
FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1 ));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1 ));
FakeMetadataObject g3 = metadata.getStore().findObject("pm1.g3", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,
null, capFinder,
@@ -612,11 +612,11 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
FakeMetadataObject g3 = metadata.getStore().findObject("pm1.g3", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,
null, capFinder,
@@ -660,11 +660,11 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
FakeMetadataObject g3 = metadata.getStore().findObject("pm1.g3", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,
null, capFinder,
@@ -702,9 +702,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,
null, capFinder,
@@ -743,9 +743,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.exampleBQT();
FakeMetadataObject g1 = metadata.getStore().findObject("BQT1.SmallA", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
FakeMetadataObject g2 = metadata.getStore().findObject("BQT2.SmallA", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
ProcessorPlan plan = TestOptimizer.helpPlan(
"SELECT table1comp.IntKey, table1comp.key1, BQT1.SmallA.StringKey FROM (SELECT t1.*, (STRINGKEY || STRINGNUM) AS key1 FROM BQT2.SmallA AS t1) AS table1comp, BQT1.SmallA WHERE table1comp.key1 = BQT1.SmallA.StringKey", //$NON-NLS-1$
@@ -789,9 +789,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.exampleBQT();
FakeMetadataObject g1 = metadata.getStore().findObject("BQT1.SmallA", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
FakeMetadataObject g2 = metadata.getStore().findObject("BQT2.SmallA", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
ProcessorPlan plan = TestOptimizer.helpPlan(
"SELECT table1comp.IntKey, table1comp.key1, BQT1.SmallA.StringKey FROM (SELECT t1.*, (STRINGKEY || STRINGNUM) AS key1 FROM BQT2.SmallA AS t1) AS table1comp, BQT1.SmallA WHERE table1comp.key1 = BQT1.SmallA.StringKey AND table1comp.key1 = BQT1.SmallA.StringNum", //$NON-NLS-1$
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -53,7 +53,7 @@
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
import com.metamatrix.query.optimizer.relational.AliasGenerator;
import com.metamatrix.query.optimizer.relational.rules.CapabilitiesUtil;
-import com.metamatrix.query.optimizer.relational.rules.NewCalculateCostUtil;
+import com.metamatrix.query.optimizer.relational.rules.RuleChooseDependent;
import com.metamatrix.query.parser.QueryParser;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.relational.AccessNode;
@@ -3085,7 +3085,7 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1));
ProcessorPlan plan = helpPlan(sql, metadata,
null, capFinder,
@@ -3122,9 +3122,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 500));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500));
FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = helpPlan(sql, metadata,
null, capFinder,
@@ -3197,9 +3197,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 500));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500));
FakeMetadataObject g2 = metadata.getStore().findObject("pm2.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = helpPlan(sql, metadata,
null, capFinder,
@@ -3238,9 +3238,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 500));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500));
FakeMetadataObject g2 = metadata.getStore().findObject("pm2.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = helpPlan(sql, metadata,
null, capFinder,
@@ -3282,9 +3282,9 @@
FakeMetadataObject model = metadata.getStore().findObject("pm1", FakeMetadataObject.MODEL); //$NON-NLS-1$
FakeMetadataObject model2 = metadata.getStore().findObject("pm2", FakeMetadataObject.MODEL); //$NON-NLS-1$
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 500));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500));
FakeMetadataObject g2 = metadata.getStore().findObject("pm2.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = helpPlan(sql, metadata,
null, capFinder,
@@ -3324,9 +3324,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject model = metadata.getStore().findObject("pm1", FakeMetadataObject.MODEL); //$NON-NLS-1$
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 500));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500));
FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = helpPlan(sql, metadata,
null, capFinder,
@@ -3364,11 +3364,11 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 500));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500));
FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
FakeMetadataObject g3 = metadata.getStore().findObject("pm1.g3", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = helpPlan(sql, metadata,
null, capFinder,
@@ -3501,9 +3501,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = helpPlan(sql, metadata,
null, capFinder,
@@ -4440,9 +4440,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.exampleBQT();
FakeMetadataObject g1 = metadata.getStore().findObject("BQT1.SmallA", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
FakeMetadataObject g2 = metadata.getStore().findObject("BQT1.SmallB", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = helpPlan(
"SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA, BQT1.SmallB WHERE (BQT1.SmallA.IntKey = lookup('BQT1.SmallB', 'IntKey', 'StringKey', BQT1.SmallB.StringKey)) AND (BQT1.SmallA.IntKey = 1)", //$NON-NLS-1$
@@ -4484,9 +4484,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.exampleBQT();
FakeMetadataObject g1 = metadata.getStore().findObject("BQT1.SmallA", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
FakeMetadataObject g2 = metadata.getStore().findObject("BQT1.MediumB", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = helpPlan(
"SELECT BQT1.SmallA.IntKey, BQT1.MediumB.IntKey FROM BQT1.SmallA LEFT OUTER JOIN BQT1.MediumB ON BQT1.SmallA.IntKey = lookup('BQT1.MediumB', 'IntKey', 'StringKey', BQT1.MediumB.StringKey)", //$NON-NLS-1$
@@ -4528,9 +4528,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.exampleBQT();
FakeMetadataObject g1 = metadata.getStore().findObject("BQT1.SmallA", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
FakeMetadataObject g2 = metadata.getStore().findObject("BQT1.MediumB", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
ProcessorPlan plan = helpPlan(
"SELECT BQT1.SmallA.IntKey, BQT1.MediumB.IntKey FROM BQT1.MediumB RIGHT OUTER JOIN BQT1.SmallA ON BQT1.SmallA.IntKey = lookup('BQT1.MediumB', 'IntKey', 'StringKey',BQT1.MediumB.StringKey)", //$NON-NLS-1$
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCalculateCostUtil.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCalculateCostUtil.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCalculateCostUtil.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -22,8 +22,10 @@
package com.metamatrix.query.optimizer.relational.rules;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+import org.junit.Test;
+
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.api.exception.query.QueryParserException;
@@ -31,6 +33,7 @@
import com.metamatrix.api.exception.query.QueryValidatorException;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.optimizer.TestOptimizer;
+import com.metamatrix.query.optimizer.TestOptimizer.ComparisonMode;
import com.metamatrix.query.optimizer.relational.GenerateCanonical;
import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
import com.metamatrix.query.optimizer.relational.plantree.NodeFactory;
@@ -46,19 +49,8 @@
import com.metamatrix.query.unittest.FakeMetadataObject;
import com.metamatrix.query.util.CommandContext;
-/**
- * Test of {@link CalculateCostUtil}
- */
-public class TestCalculateCostUtil extends TestCase {
+public class TestCalculateCostUtil {
- /**
- * Constructor for TestCapabilitiesUtil.
- * @param name
- */
- public TestCalculateCostUtil(String name) {
- super(name);
- }
-
// =====================================================================
// HELPERS
// =====================================================================
@@ -100,58 +92,45 @@
// TESTS
// =====================================================================
- /** Merrill ran into a problem with this type of criteria */
- public void testEstimateCostOfCriteria() throws Exception {
+ @Test public void testEstimateCostOfCriteria() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 = '3' or pm2.g3.e2 = 2"; //$NON-NLS-1$
helpTestEstimateCost(critString, NewCalculateCostUtil.UNKNOWN_VALUE, NewCalculateCostUtil.UNKNOWN_VALUE, metadata);
}
- public void testEstimateCostOfCompareCriteria() throws Exception {
+ @Test public void testEstimateCostOfCompareCriteria() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm1.g1.e1 = '3'"; //$NON-NLS-1$
helpTestEstimateCost(critString, NewCalculateCostUtil.UNKNOWN_VALUE, 1, metadata);
- }
-
- /** defect 15045 */
- public void testEstimateCostOfCompareCriteria2() throws Exception {
+ }
+
+ @Test public void testEstimateCostOfCompareCriteria1() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
- String critString = "'3' = pm1.g1.e1"; //$NON-NLS-1$
+ String critString = "pm1.g1.e1 < '3'"; //$NON-NLS-1$
- helpTestEstimateCost(critString, NewCalculateCostUtil.UNKNOWN_VALUE, 1, metadata);
- }
-
+ helpTestEstimateCost(critString, NewCalculateCostUtil.UNKNOWN_VALUE, NewCalculateCostUtil.UNKNOWN_VALUE, metadata);
+ }
+
/**
* usesKey = false
* NOT = false
*/
- public void testEstimateCostOfMatchCriteria1() throws Exception {
+ @Test public void testEstimateCostOfMatchCriteria1() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
- String critString = "pm2.g3.e1 LIKE '#'"; //$NON-NLS-1$
+ String critString = "pm2.g3.e1 LIKE '#%'"; //$NON-NLS-1$
helpTestEstimateCost(critString, 300, 100, metadata);
}
/**
* usesKey = false
- * NOT = false
- */
- public void testEstimateCostOfMatchCriteria1a() throws Exception {
- QueryMetadataInterface metadata = FakeMetadataFactory.example4();
- String critString = "'#' LIKE pm2.g3.e1"; //$NON-NLS-1$
-
- helpTestEstimateCost(critString, 300, 100, metadata);
- }
-
- /**
- * usesKey = false
* NOT = true
*/
- public void testEstimateCostOfMatchCriteria2() throws Exception {
+ @Test public void testEstimateCostOfMatchCriteria2() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
- String critString = "pm2.g3.e1 NOT LIKE '#'"; //$NON-NLS-1$
+ String critString = "pm2.g3.e1 NOT LIKE '#_'"; //$NON-NLS-1$
helpTestEstimateCost(critString, 300, 200, metadata);
}
@@ -160,51 +139,29 @@
* usesKey = true
* NOT = false
*/
- public void testEstimateCostOfMatchCriteria3() throws Exception {
+ @Test public void testEstimateCostOfMatchCriteria3() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
- String critString = "pm1.g1.e1 LIKE '#'"; //$NON-NLS-1$
+ String critString = "pm1.g1.e1 LIKE '#_'"; //$NON-NLS-1$
- helpTestEstimateCost(critString, 300, 1, metadata);
+ helpTestEstimateCost(critString, 300, 50, metadata);
}
-
- /**
- * usesKey = true
- * NOT = false
- */
- public void testEstimateCostOfMatchCriteria3a() throws Exception {
- QueryMetadataInterface metadata = FakeMetadataFactory.example4();
- String critString = "'#' LIKE pm1.g1.e1"; //$NON-NLS-1$
-
- helpTestEstimateCost(critString, 300, 1, metadata);
- }
/**
* usesKey = true
* NOT = true
*/
- public void testEstimateCostOfMatchCriteria4() throws Exception {
+ @Test public void testEstimateCostOfMatchCriteria4() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
- String critString = "pm1.g1.e1 NOT LIKE '#'"; //$NON-NLS-1$
+ String critString = "pm1.g1.e1 NOT LIKE '#_'"; //$NON-NLS-1$
- helpTestEstimateCost(critString, 300, 299, metadata);
+ helpTestEstimateCost(critString, 300, 249, metadata);
}
-
- /**
- * usesKey = true
- * NOT = true
- */
- public void testEstimateCostOfMatchCriteria4a() throws Exception {
- QueryMetadataInterface metadata = FakeMetadataFactory.example4();
- String critString = "'#' NOT LIKE pm1.g1.e1"; //$NON-NLS-1$
-
- helpTestEstimateCost(critString, 300, 299, metadata);
- }
/**
* usesKey = false
* NOT = false
*/
- public void testEstimateCostOfIsNullCriteria1() throws Exception {
+ @Test public void testEstimateCostOfIsNullCriteria1() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 IS NULL"; //$NON-NLS-1$
@@ -215,7 +172,7 @@
* usesKey = false
* NOT = true
*/
- public void testEstimateCostOfIsNullCriteria2() throws Exception {
+ @Test public void testEstimateCostOfIsNullCriteria2() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 IS NOT NULL"; //$NON-NLS-1$
@@ -226,7 +183,7 @@
* usesKey = true
* NOT = false
*/
- public void testEstimateCostOfIsNullCriteria3() throws Exception {
+ @Test public void testEstimateCostOfIsNullCriteria3() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm1.g1.e1 IS NULL"; //$NON-NLS-1$
@@ -237,7 +194,7 @@
* usesKey = true
* NOT = true
*/
- public void testEstimateCostOfIsNullCriteria4() throws Exception {
+ @Test public void testEstimateCostOfIsNullCriteria4() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm1.g1.e1 IS NOT NULL"; //$NON-NLS-1$
@@ -249,7 +206,7 @@
* known child cost = false
* NOT = false
*/
- public void testEstimateCostOfSetCriteria1() throws Exception {
+ @Test public void testEstimateCostOfSetCriteria1() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 IN ('2', '3')"; //$NON-NLS-1$
@@ -261,7 +218,7 @@
* known child cost = false
* NOT = true
*/
- public void testEstimateCostOfSetCriteria2() throws Exception {
+ @Test public void testEstimateCostOfSetCriteria2() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 NOT IN ('2', '3')"; //$NON-NLS-1$
@@ -273,7 +230,7 @@
* known child cost = true
* NOT = false
*/
- public void testEstimateCostOfSetCriteria3() throws Exception {
+ @Test public void testEstimateCostOfSetCriteria3() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 IN ('2', '3')"; //$NON-NLS-1$
@@ -285,7 +242,7 @@
* known child cost = true
* NOT = true
*/
- public void testEstimateCostOfSetCriteria4() throws Exception {
+ @Test public void testEstimateCostOfSetCriteria4() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 NOT IN ('2', '3')"; //$NON-NLS-1$
@@ -297,7 +254,7 @@
* known child cost = false
* NOT = false
*/
- public void testEstimateCostOfSetCriteria5() throws Exception {
+ @Test public void testEstimateCostOfSetCriteria5() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm1.g1.e1 IN ('2', '3')"; //$NON-NLS-1$
@@ -309,7 +266,7 @@
* known child cost = false
* NOT = true
*/
- public void testEstimateCostOfSetCriteria6() throws Exception {
+ @Test public void testEstimateCostOfSetCriteria6() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm1.g1.e1 NOT IN ('2', '3')"; //$NON-NLS-1$
@@ -321,7 +278,7 @@
* known child cost = true
* NOT = false
*/
- public void testEstimateCostOfSetCriteria7() throws Exception {
+ @Test public void testEstimateCostOfSetCriteria7() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm1.g1.e1 IN ('2', '3')"; //$NON-NLS-1$
@@ -333,14 +290,14 @@
* known child cost = true
* NOT = true
*/
- public void testEstimateCostOfSetCriteria8() throws Exception{
+ @Test public void testEstimateCostOfSetCriteria8() throws Exception{
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm1.g1.e1 NOT IN ('2', '3')"; //$NON-NLS-1$
helpTestEstimateCost(critString, 200, 198, metadata);
}
- public void testEstimateJoinNodeCost() throws Exception {
+ @Test public void testEstimateJoinNodeCost() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
PlanNode joinNode = helpGetJoinNode(NewCalculateCostUtil.UNKNOWN_VALUE, NewCalculateCostUtil.UNKNOWN_VALUE, JoinType.JOIN_CROSS);
@@ -349,11 +306,11 @@
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key
*/
- public void testEstimateCostOfCriteriaCompoundKey() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm4.g1.e1 = '3' and pm4.g1.e2 = 2"; //$NON-NLS-1$
@@ -361,12 +318,12 @@
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key, so an OR criteria cannot be
* predicted to reduce the cost of the join
*/
- public void testEstimateCostOfCriteriaCompoundKey2() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey2() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm4.g1.e1 = '3' or pm4.g1.e2 = 2"; //$NON-NLS-1$
@@ -374,12 +331,12 @@
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key - this criteria does not
* lower the cost due to the NOT
*/
- public void testEstimateCostOfCriteriaCompoundKey3() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey3() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm4.g1.e1 = '3' and not pm4.g1.e2 = 2"; //$NON-NLS-1$
@@ -387,12 +344,12 @@
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key - this criteria does not
* lower the cost due to the 0R
*/
- public void testEstimateCostOfCriteriaCompoundKey4() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey4() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "(pm4.g1.e1 = '3' or pm4.g1.e4 = 2.0) and not pm4.g1.e2 = 2"; //$NON-NLS-1$
@@ -400,12 +357,12 @@
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key - this criteria does not
* lower the cost due to the OR
*/
- public void testEstimateCostOfCriteriaCompoundKey5() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey5() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "(pm4.g1.e1 = '3' or pm4.g1.e4 = 2.0) and pm4.g1.e2 = 2"; //$NON-NLS-1$
@@ -413,12 +370,12 @@
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key - this criteria does not
* lower the cost due to the OR
*/
- public void testEstimateCostOfCriteriaCompoundKey6() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey6() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "(pm4.g1.e1 = '3' and pm4.g1.e2 = 2) or pm4.g1.e4 = 2.0"; //$NON-NLS-1$
@@ -426,51 +383,38 @@
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key - this criteria covers that
* key so the cost should be low
*/
- public void testEstimateCostOfCriteriaCompoundKey7() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey8() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
- String critString = "(pm4.g1.e1 = '3' and pm4.g1.e2 = 2) and pm4.g1.e4 = 2.0"; //$NON-NLS-1$
+ String critString = "pm4.g1.e1 LIKE '3%' and pm4.g1.e2 = 2"; //$NON-NLS-1$
helpTestEstimateCost(critString, NewCalculateCostUtil.UNKNOWN_VALUE, 1, metadata);
- }
-
- /**
- * BOA cases 2159 and 2160, defect 14998
- *
- * e1 and e2 make up a single compound key - this criteria covers that
- * key so the cost should be low
- */
- public void testEstimateCostOfCriteriaCompoundKey8() throws Exception {
- QueryMetadataInterface metadata = FakeMetadataFactory.example4();
- String critString = "pm4.g1.e1 LIKE '3' and pm4.g1.e2 = 2"; //$NON-NLS-1$
-
- helpTestEstimateCost(critString, NewCalculateCostUtil.UNKNOWN_VALUE, 1, metadata);
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key - this criteria does not
* lower the cost due to the NOT
*/
- public void testEstimateCostOfCriteriaCompoundKey9() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey9() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
- String critString = "pm4.g1.e1 NOT LIKE '3' and pm4.g1.e2 = 2"; //$NON-NLS-1$
+ String critString = "pm4.g1.e1 NOT LIKE '3%' and pm4.g1.e2 = 2"; //$NON-NLS-1$
helpTestEstimateCost(critString, NewCalculateCostUtil.UNKNOWN_VALUE, NewCalculateCostUtil.UNKNOWN_VALUE, metadata);
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key - this criteria covers that
* key so the cost should be low
*/
- public void testEstimateCostOfCriteriaCompoundKey10() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey10() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "'3' LIKE pm4.g1.e1 and pm4.g1.e2 = 2"; //$NON-NLS-1$
@@ -478,12 +422,12 @@
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key - this criteria covers that
* key so the cost should be low
*/
- public void testEstimateCostOfCriteriaCompoundKey11() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey11() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm4.g1.e1 IS NULL and pm4.g1.e2 = 2"; //$NON-NLS-1$
@@ -491,12 +435,12 @@
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key - this criteria does not
* lower the cost due to the NOT
*/
- public void testEstimateCostOfCriteriaCompoundKey12() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey12() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm4.g1.e1 IS NOT NULL and pm4.g1.e2 = 2"; //$NON-NLS-1$
@@ -504,12 +448,12 @@
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key - this criteria covers that
* key so the cost should be low
*/
- public void testEstimateCostOfCriteriaCompoundKey13() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey13() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm4.g1.e1 IN ('3', '4') and pm4.g1.e2 = 2"; //$NON-NLS-1$
@@ -517,22 +461,29 @@
}
/**
- * BOA cases 2159 and 2160, defect 14998
+ * cases 2159 and 2160, defect 14998
*
* e1 and e2 make up a single compound key - this criteria does not
* lower the cost due to the NOT
*/
- public void testEstimateCostOfCriteriaCompoundKey14() throws Exception {
+ @Test public void testEstimateCostOfCriteriaCompoundKey14() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm4.g1.e1 NOT IN ('3', '4') and pm4.g1.e2 = 2"; //$NON-NLS-1$
helpTestEstimateCost(critString, NewCalculateCostUtil.UNKNOWN_VALUE, NewCalculateCostUtil.UNKNOWN_VALUE, metadata);
- }
+ }
+ @Test public void testEstimateCostOfCriteriaCompoundKey15() throws Exception {
+ QueryMetadataInterface metadata = FakeMetadataFactory.example4();
+ String critString = "(pm4.g1.e1 = '3' or pm4.g1.e1 = '2') and (pm4.g1.e2 = 2 or pm4.g1.e2 = 1)"; //$NON-NLS-1$
+
+ helpTestEstimateCost(critString, NewCalculateCostUtil.UNKNOWN_VALUE, 1, metadata);
+ }
+
/**
* usesKey true
*/
- public void testEstimateCostOfCriteriaMultiGroup() throws Exception {
+ @Test public void testEstimateCostOfCriteriaMultiGroup() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm4.g1.e1 = pm1.g1.e1"; //$NON-NLS-1$
@@ -542,7 +493,7 @@
/**
* usesKey false
*/
- public void testEstimateCostOfCriteriaMultiGroup1() throws Exception {
+ @Test public void testEstimateCostOfCriteriaMultiGroup1() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 = pm4.g1.e1"; //$NON-NLS-1$
@@ -552,7 +503,7 @@
/**
* usesKey true
*/
- public void testEstimateCostOfCriteriaMultiGroup2() throws Exception {
+ @Test public void testEstimateCostOfCriteriaMultiGroup2() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm4.g1.e1 = pm1.g1.e1"; //$NON-NLS-1$
@@ -562,7 +513,7 @@
/**
* usesKey false
*/
- public void testEstimateCostOfCriteriaMultiGroup3() throws Exception {
+ @Test public void testEstimateCostOfCriteriaMultiGroup3() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 = pm4.g1.e1"; //$NON-NLS-1$
@@ -573,7 +524,7 @@
* Date Criteria - Case using valid max and min date strings. In the case of date,
* the valid strings are timestamp format - since that is what our costing sets them as.
*/
- public void testEstimateCostOfCriteriaDate1() throws Exception {
+ @Test public void testEstimateCostOfCriteriaDate1() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example1();
FakeMetadataObject e2 = (FakeMetadataObject)metadata.getElementID("pm3.g1.e2"); //$NON-NLS-1$
e2.putProperty(FakeMetadataObject.Props.MIN_VALUE,"2007-04-03 12:12:12.10"); //$NON-NLS-1$
@@ -587,7 +538,7 @@
* Date Criteria - Case using invalid max and min date strings. In the case of date,
* one example of invalid strings is date format - since our costing sets them to timestamp.
*/
- public void testEstimateCostOfCriteriaDate2() throws Exception {
+ @Test public void testEstimateCostOfCriteriaDate2() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example1();
FakeMetadataObject e2 = (FakeMetadataObject)metadata.getElementID("pm3.g1.e2"); //$NON-NLS-1$
e2.putProperty(FakeMetadataObject.Props.MIN_VALUE,"2007-04-03"); //$NON-NLS-1$
@@ -600,7 +551,7 @@
/**
* Time Criteria - case using valid max and min time strings.
*/
- public void testEstimateCostOfCriteriaTime1() throws Exception {
+ @Test public void testEstimateCostOfCriteriaTime1() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example1();
FakeMetadataObject e3 = (FakeMetadataObject)metadata.getElementID("pm3.g1.e3"); //$NON-NLS-1$
e3.putProperty(FakeMetadataObject.Props.MIN_VALUE,"12:12:12"); //$NON-NLS-1$
@@ -613,7 +564,7 @@
/**
* Time Criteria - case using invalid max and min time strings
*/
- public void testEstimateCostOfCriteriaTime2() throws Exception {
+ @Test public void testEstimateCostOfCriteriaTime2() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example1();
FakeMetadataObject e3 = (FakeMetadataObject)metadata.getElementID("pm3.g1.e3"); //$NON-NLS-1$
e3.putProperty(FakeMetadataObject.Props.MIN_VALUE,"2007-04-03 12:12:12.10"); //$NON-NLS-1$
@@ -626,7 +577,7 @@
/**
* Timestamp Criteria - case using valid max and min timestamp strings
*/
- public void testEstimateCostOfCriteriaTimestamp1() throws Exception {
+ @Test public void testEstimateCostOfCriteriaTimestamp1() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example1();
FakeMetadataObject e4 = (FakeMetadataObject)metadata.getElementID("pm3.g1.e4"); //$NON-NLS-1$
e4.putProperty(FakeMetadataObject.Props.MIN_VALUE,"2007-04-03 12:12:12.10"); //$NON-NLS-1$
@@ -639,7 +590,7 @@
/**
* Timestamp Criteria - case using invalid max and min timestamp strings
*/
- public void testEstimateCostOfCriteriaTimestamp2() throws Exception {
+ @Test public void testEstimateCostOfCriteriaTimestamp2() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example1();
FakeMetadataObject e4 = (FakeMetadataObject)metadata.getElementID("pm3.g1.e4"); //$NON-NLS-1$
e4.putProperty(FakeMetadataObject.Props.MIN_VALUE,"2007-04-03"); //$NON-NLS-1$
@@ -649,56 +600,56 @@
helpTestEstimateCost(critString, 100, 33, metadata);
}
- public void testNDVEstimate() throws Exception {
+ @Test public void testNDVEstimate() throws Exception {
String crit = "US.accounts.account = 10"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 800, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testNDVEstimate1() throws Exception {
+ @Test public void testNDVEstimate1() throws Exception {
String crit = "US.accounts.account = US.accounts.customer"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 800, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testCompoundCriteriaEstimate() throws Exception {
+ @Test public void testCompoundCriteriaEstimate() throws Exception {
String crit = "US.accounts.account = 10 and US.accounts.account = US.accounts.customer"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 640, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testCompoundCriteriaEstimate1() throws Exception {
+ @Test public void testCompoundCriteriaEstimate1() throws Exception {
String crit = "US.accounts.account = 10 or US.accounts.account = US.accounts.customer"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 1000, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testNNVEstimate() throws Exception {
+ @Test public void testNNVEstimate() throws Exception {
String crit = "US.accounts.account is null"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 1, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testNNVEstimate1() throws Exception {
+ @Test public void testNNVEstimate1() throws Exception {
String crit = "US.accounts.account is null"; //$NON-NLS-1$
helpTestEstimateCost(crit, NewCalculateCostUtil.UNKNOWN_VALUE, 1, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testCompoundCriteriaEstimate2() throws Exception {
+ @Test public void testCompoundCriteriaEstimate2() throws Exception {
String crit = "US.accounts.account is null and US.accounts.account = US.accounts.customer"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 1, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testCompoundCriteriaEstimate3() throws Exception {
+ @Test public void testCompoundCriteriaEstimate3() throws Exception {
String crit = "US.accounts.account is null or US.accounts.account = US.accounts.customer"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 801, TestVirtualDepJoin.exampleVirtualDepJoin());
}
//ensures that the ordering of criteria does not effect the costing calculation
- public void testCompoundCriteriaEstimate4() throws Exception {
+ @Test public void testCompoundCriteriaEstimate4() throws Exception {
String crit = "US.accounts.account = 10 and US.accounts.account = US.accounts.customer and US.accounts.account < 100"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 213, TestVirtualDepJoin.exampleVirtualDepJoin());
@@ -708,73 +659,99 @@
helpTestEstimateCost(crit1, 1000, 213, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testCompoundCriteriaEstimate5() throws Exception {
+ @Test public void testCompoundCriteriaEstimate5() throws Exception {
String crit = "US.accounts.account is null and US.accounts.account = US.accounts.customer"; //$NON-NLS-1$
helpTestEstimateCost(crit, NewCalculateCostUtil.UNKNOWN_VALUE, 1, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testCompoundCriteriaEstimate6() throws Exception {
+ @Test public void testCompoundCriteriaEstimate6() throws Exception {
String crit = "US.accounts.account is null or US.accounts.account = US.accounts.customer"; //$NON-NLS-1$
helpTestEstimateCost(crit, NewCalculateCostUtil.UNKNOWN_VALUE, NewCalculateCostUtil.UNKNOWN_VALUE, TestVirtualDepJoin.exampleVirtualDepJoin());
}
//min and max are not set, so the default estimate is returned
- public void testRangeEstimate() throws Exception {
+ @Test public void testRangeEstimate() throws Exception {
String crit = "US.accounts.account < 100"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 333, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testRangeEstimate1() throws Exception {
+ @Test public void testRangeEstimate1() throws Exception {
String crit = "US.accounts.customer < 100"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 100, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testRangeEstimate2() throws Exception {
+ @Test public void testRangeEstimate2() throws Exception {
String crit = "US.accounts.customer > 100"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 900, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testRangeEstimate3() throws Exception {
+ @Test public void testRangeEstimate3() throws Exception {
String crit = "US.accounts.customer >= 1600"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 1, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testRangeEstimate4() throws Exception {
+ @Test public void testRangeEstimate4() throws Exception {
String crit = "US.accounts.customer < -1"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 1, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testRangeEstimate5() throws Exception {
+ @Test public void testRangeEstimate5() throws Exception {
String crit = "US.accounts.customer >= -1"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 1000, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testRangeEstimate6() throws Exception {
+ @Test public void testRangeEstimate6() throws Exception {
String crit = "US.accounts.pennies >= -2"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 1000, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testRangeEstimate7() throws Exception {
+ @Test public void testRangeEstimate7() throws Exception {
String crit = "US.accounts.pennies >= -6"; //$NON-NLS-1$
helpTestEstimateCost(crit, 1000, 800, TestVirtualDepJoin.exampleVirtualDepJoin());
}
- public void testLimitWithUnknownChildCardinality() throws Exception {
+ @Test public void testLimitWithUnknownChildCardinality() throws Exception {
String query = "select e1 from pm1.g1 limit 2"; //$NON-NLS-1$
RelationalPlan plan = (RelationalPlan)TestOptimizer.helpPlan(query, FakeMetadataFactory.example1Cached(), new String[] {"SELECT e1 FROM pm1.g1"}); //$NON-NLS-1$
assertEquals(new Float(2), plan.getRootNode().getEstimateNodeCardinality());
}
+
+ public void helpTestSetOp(String op, float cost) throws Exception {
+ String query = "SELECT customer as customer_id, convert(account, long) as account_id, convert(txnid, long) as transaction_id, case txn when 'DEP' then 1 when 'TFR' then 2 when 'WD' then 3 else -1 end as txn_type, (pennies + convert('0.00', bigdecimal)) / 100 as amount, 'US' as source FROM US.Accounts where txn != 'X'" + //$NON-NLS-1$
+ op +
+ "SELECT id, convert(accid / 10000, long), mod(accid, 10000), convert(type, integer), amount, 'EU' from Europe.CustAccts"; //$NON-NLS-1$
+
+ RelationalPlan plan = (RelationalPlan)TestOptimizer.helpPlan(query, TestVirtualDepJoin.exampleVirtualDepJoin(), new String[] {"SELECT g_0.customer, g_0.account, g_0.txnid, g_0.txn, g_0.pennies FROM US.Accounts AS g_0 WHERE g_0.txn <> 'X'", "SELECT g_0.id, g_0.accid, g_0.type, g_0.amount FROM Europe.CustAccts AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+
+ assertEquals(cost, plan.getRootNode().getEstimateNodeCardinality());
+ }
+
+ @Test public void testUnion() throws Exception {
+ helpTestSetOp("UNION ", 1375000.0f); //$NON-NLS-1$
+ }
+
+ @Test public void testUnionALL() throws Exception {
+ helpTestSetOp("UNION ALL ", 1750000.0f); //$NON-NLS-1$
+ }
+
+ @Test public void testExcept() throws Exception {
+ helpTestSetOp("EXCEPT ", 250000.0f); //$NON-NLS-1$
+ }
+
+ @Test public void testIntersect() throws Exception {
+ helpTestSetOp("INTERSECT ", 375000.0f); //$NON-NLS-1$
+ }
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestRulePushSelectCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestRulePushSelectCriteria.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestRulePushSelectCriteria.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -45,7 +45,6 @@
import com.metamatrix.query.parser.QueryParser;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.unittest.FakeMetadataFacade;
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -68,7 +68,7 @@
import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.optimizer.relational.rules.NewCalculateCostUtil;
+import com.metamatrix.query.optimizer.relational.rules.RuleChooseDependent;
import com.metamatrix.query.parser.QueryParser;
import com.metamatrix.query.processor.relational.JoinNode;
import com.metamatrix.query.processor.relational.RelationalNode;
@@ -5211,9 +5211,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
FakeMetadataObject g2 = metadata.getStore().findObject("pm2.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
Command command = helpParse(sql);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
@@ -5255,9 +5255,9 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject g1 = metadata.getStore().findObject("pm4.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST + 1000));
+ g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
FakeMetadataObject g2 = metadata.getStore().findObject("pm2.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
- g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(NewCalculateCostUtil.DEFAULT_STRONG_COST - 1));
+ g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
Command command = helpParse(sql);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLProcessor.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLProcessor.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -10000,7 +10000,7 @@
/**
- * Test for Merrill - if no data is contained in the soap elements
+ * if no data is contained in the soap elements
* (e.g. ORG:ArrayOfTaxID) and the schema allows it, eliminate the
* whole fragment
*/
Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-07-31 15:42:46 UTC (rev 1211)
+++ trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-08-04 16:37:03 UTC (rev 1212)
@@ -2216,4 +2216,11 @@
assertEquals( "e2 <= 5", ccrit.getCriteria(1).toString() ); //$NON-NLS-1$
}
+ @Test public void testRewriteLike() {
+ String original = "pm1.g1.e1 like '%'"; //$NON-NLS-1$
+ String expected = "1 = 1"; //$NON-NLS-1$
+
+ helpTestRewriteCriteria(original, expected);
+ }
+
}
15 years, 5 months