teiid SVN: r4525 - in branches/7.7.x/connectors/translator-jdbc/src: test/java/org/teiid/translator/jdbc/oracle and 1 other directory.
by teiid-commits@lists.jboss.org
Author: jolee
Date: 2012-10-31 17:31:09 -0400 (Wed, 31 Oct 2012)
New Revision: 4525
Modified:
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
Log:
TEIID-669: Support "pass though" SQL commands to sources - fix
Modified: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2012-10-31 21:06:10 UTC (rev 4524)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2012-10-31 21:31:09 UTC (rev 4525)
@@ -414,6 +414,9 @@
if (obj.getMetadataObject() != null) {
String nativeQuery = obj.getMetadataObject().getProperty(TEIID_NATIVE_QUERY, false);
if (nativeQuery != null) {
+ if (obj.getCorrelationName() == null) {
+ throw new IllegalArgumentException("alias needed. When native query is being used, then alias name must be defined for table in the query.");
+ }
buffer.append(Tokens.LPAREN).append(nativeQuery).append(Tokens.RPAREN);
if (obj.getCorrelationName() == null) {
buffer.append(Tokens.SPACE);
@@ -421,6 +424,7 @@
buffer.append(AS).append(Tokens.SPACE);
}
}
+ return;
}
}
super.appendBaseName(obj);
Modified: branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2012-10-31 21:06:10 UTC (rev 4524)
+++ branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2012-10-31 21:31:09 UTC (rev 4525)
@@ -896,7 +896,7 @@
Mockito.verify(cs, Mockito.times(1)).getObject(1);
}
- @Test public void testNativeQuery() throws Exception {
+ @Test (expected=IllegalArgumentException.class)public void testNativeQueryWithNoCorrelationName() throws Exception {
String input = "SELECT (DoubleNum * 1.0) FROM x"; //$NON-NLS-1$
String output = "SELECT (x.DoubleNum * 1.0) FROM (select c from d) x"; //$NON-NLS-1$
@@ -905,6 +905,14 @@
helpTestVisitor(metadata, input, EMPTY_CONTEXT, null, output);
}
+ @Test public void testNativeQuery() throws Exception {
+ String input = "SELECT (DoubleNum * 1.0) FROM x as y"; //$NON-NLS-1$
+ String output = "SELECT (y.DoubleNum * 1.0) FROM (select c from d) y"; //$NON-NLS-1$
+
+ QueryMetadataInterface metadata = getOracleSpecificMetadata();
+ helpTestVisitor(metadata, input, EMPTY_CONTEXT, null, output);
+ }
+
@Test public void testNativeQueryProc() throws Exception {
String input = "call proc(2)"; //$NON-NLS-1$
String output = "select x from y where z = ?"; //$NON-NLS-1$
12 years, 2 months
teiid SVN: r4524 - in branches/7.7.x: engine/src/main/java/org/teiid/query/util and 2 other directories.
by teiid-commits@lists.jboss.org
Author: jolee
Date: 2012-10-31 17:06:10 -0400 (Wed, 31 Oct 2012)
New Revision: 4524
Added:
branches/7.7.x/engine/src/main/java/org/teiid/query/util/Options.java
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
branches/7.7.x/engine/src/main/java/org/teiid/query/util/CommandContext.java
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestOrderByProcessing.java
branches/7.7.x/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestTPCR.java
Log:
TEIID-2245: Limit pushdown of nulls first/last- previous commit was faulty
Modified: branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2012-10-31 18:45:08 UTC (rev 4523)
+++ branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2012-10-31 21:06:10 UTC (rev 4524)
@@ -506,8 +506,7 @@
if (!supportsNullOrdering) {
item.setNullOrdering(null);
}
- // assuming true for backport, context.getOptions().isPushdownDefaultNullOrder()
- } else if (userOrdering && supportsNullOrdering && defaultNullOrder != NullOrder.LOW && true) {
+ } else if (userOrdering && supportsNullOrdering && defaultNullOrder != NullOrder.LOW && context.getOptions().isPushdownDefaultNullOrder()) {
//try to match the expected default of low
if (item.isAscending()) {
if (defaultNullOrder != NullOrder.FIRST) {
Modified: branches/7.7.x/engine/src/main/java/org/teiid/query/util/CommandContext.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/query/util/CommandContext.java 2012-10-31 18:45:08 UTC (rev 4523)
+++ branches/7.7.x/engine/src/main/java/org/teiid/query/util/CommandContext.java 2012-10-31 21:06:10 UTC (rev 4524)
@@ -143,6 +143,8 @@
private Executor executor = ExecutorUtils.getDirectExecutor();
private LRUCache<String, DecimalFormat> decimalFormatCache;
private LRUCache<String, SimpleDateFormat> dateFormatCache;
+
+ private Options options;
}
private GlobalState globalState = new GlobalState();
@@ -692,4 +694,16 @@
return result;
}
+ public Options getOptions() {
+ if (this.globalState.options == null) {
+ this.globalState.options = new Options();
+ }
+ return this.globalState.options;
+ }
+
+ public void setOptions(Options options) {
+ this.globalState.options = options;
+ }
+
+
}
Added: branches/7.7.x/engine/src/main/java/org/teiid/query/util/Options.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/query/util/Options.java (rev 0)
+++ branches/7.7.x/engine/src/main/java/org/teiid/query/util/Options.java 2012-10-31 21:06:10 UTC (rev 4524)
@@ -0,0 +1,73 @@
+/*
+ * 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.query.util;
+
+import java.util.Properties;
+
+/**
+ * A holder for options
+ */
+public class Options {
+
+ public static final String UNNEST_DEFAULT = "org.teiid.subqueryUnnestDefault"; //$NON-NLS-1$
+ public static final String PUSHDOWN_DEFAULT_NULL_ORDER = "org.teiid.pushdownDefaultNullOrder"; //$NON-NLS-1$
+
+ private Properties properties;
+ private boolean subqueryUnnestDefault;
+ private boolean pushdownDefaultNullOrder;
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Properties properties) {
+ this.properties = properties;
+ }
+
+ public boolean isSubqueryUnnestDefault() {
+ return subqueryUnnestDefault;
+ }
+
+ public void setSubqueryUnnestDefault(boolean subqueryUnnestDefault) {
+ this.subqueryUnnestDefault = subqueryUnnestDefault;
+ }
+
+ public Options subqueryUnnestDefault(boolean s) {
+ this.subqueryUnnestDefault = s;
+ return this;
+ }
+
+ public boolean isPushdownDefaultNullOrder() {
+ return pushdownDefaultNullOrder;
+ }
+
+ public void setPushdownDefaultNullOrder(boolean virtualizeDefaultNullOrdering) {
+ this.pushdownDefaultNullOrder = virtualizeDefaultNullOrdering;
+ }
+
+ public Options pushdownDefaultNullOrder(boolean p) {
+ this.pushdownDefaultNullOrder = p;
+ return this;
+ }
+
+}
Modified: branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestOrderByProcessing.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestOrderByProcessing.java 2012-10-31 18:45:08 UTC (rev 4523)
+++ branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestOrderByProcessing.java 2012-10-31 21:06:10 UTC (rev 4524)
@@ -35,6 +35,7 @@
import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.query.util.CommandContext;
+import org.teiid.query.util.Options;
import org.teiid.translator.ExecutionFactory.NullOrder;
@SuppressWarnings({"nls", "unchecked"})
@@ -142,7 +143,7 @@
@Test public void testNullOrdering() throws Exception {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
- //caps.setCapabilitySupport(Capability.QUERY_ORDERBY_NULL_ORDERING, true);
+ caps.setCapabilitySupport(Capability.QUERY_ORDERBY_NULL_ORDERING, true);
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
ProcessorPlan plan = TestOptimizer.helpPlan("select e1 from pm1.g1 order by e1 desc, e2 asc", //$NON-NLS-1$
@@ -163,10 +164,10 @@
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
CommandContext cc = new CommandContext();
- //cc.setOptions(new Options().pushdownDefaultNullOrder(true));
+ cc.setOptions(new Options().pushdownDefaultNullOrder(true));
ProcessorPlan plan = TestOptimizer.getPlan(TestOptimizer.helpGetCommand("select e1 from pm1.g1 order by e1 desc, e2 asc NULLS LAST", metadata, null), metadata, capFinder, null, true, cc);
TestOptimizer.checkAtomicQueries(new String[] { "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0 DESC NULLS LAST, g_0.e2 NULLS LAST"}, plan); //$NON-NLS-1$
- TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+ TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
/**
@@ -192,18 +193,17 @@
* @throws Exception
*/
@Test public void testNullOrdering4() throws Exception {
- FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
- caps.setCapabilitySupport(Capability.QUERY_ORDERBY_NULL_ORDERING, true);
- caps.setSourceProperty(Capability.QUERY_ORDERBY_DEFAULT_NULL_ORDER, NullOrder.UNKNOWN);
- capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
- CommandContext cc = new CommandContext();
- //cc.setOptions(new Options().pushdownDefaultNullOrder(true));
- ProcessorPlan plan = TestOptimizer.getPlan(TestOptimizer.helpGetCommand("select e1 from pm1.g1 order by e1 desc, e2 asc", metadata, null), metadata, capFinder, null, true, cc);
- TestOptimizer.checkAtomicQueries(new String[] { "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0 DESC NULLS LAST, g_0.e2 NULLS FIRST"}, plan); //$NON-NLS-1$
- TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
- }
-
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_ORDERBY_NULL_ORDERING, true);
+ caps.setSourceProperty(Capability.QUERY_ORDERBY_DEFAULT_NULL_ORDER, NullOrder.UNKNOWN);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
+ CommandContext cc = new CommandContext();
+ cc.setOptions(new Options().pushdownDefaultNullOrder(true));
+ ProcessorPlan plan = TestOptimizer.getPlan(TestOptimizer.helpGetCommand("select e1 from pm1.g1 order by e1 desc, e2 asc", metadata, null), metadata, capFinder, null, true, cc);
+ TestOptimizer.checkAtomicQueries(new String[] { "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0 DESC NULLS LAST, g_0.e2 NULLS FIRST"}, plan); //$NON-NLS-1$
+ TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+ }
}
Modified: branches/7.7.x/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestTPCR.java
===================================================================
--- branches/7.7.x/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestTPCR.java 2012-10-31 18:45:08 UTC (rev 4523)
+++ branches/7.7.x/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestTPCR.java 2012-10-31 21:06:10 UTC (rev 4524)
@@ -63,7 +63,7 @@
Arrays.asList(new Object[] { new Double(3459808.0), new BigDecimal("405838.6989"), TimestampUtil.createDate(95, 2, 4), new Double(0.0) }), //$NON-NLS-1$
Arrays.asList(new Object[] { new Double(492164.0), new BigDecimal("390324.0610"), TimestampUtil.createDate(95, 1, 19), new Double(0.0) }) }; //$NON-NLS-1$
- dataMgr.addData("SELECT g_2.l_orderkey AS c_0, SUM((g_2.l_extendedprice * (1 - g_2.l_discount))) AS c_1, g_1.o_orderdate AS c_2, g_1.o_shippriority AS c_3 FROM TPCR_Oracle_9i.CUSTOMER AS g_0, TPCR_Oracle_9i.ORDERS AS g_1, TPCR_Oracle_9i.LINEITEM AS g_2 WHERE (g_0.c_custkey = g_1.o_custkey) AND (g_2.l_orderkey = g_1.o_orderkey) AND (g_0.c_mktsegment = 'BUILDING') AND (g_1.o_orderdate < {d'1995-03-15'}) AND (g_2.l_shipdate > {ts'1995-03-15 00:00:00.0'}) GROUP BY g_2.l_orderkey, g_1.o_orderdate, g_1.o_shippriority ORDER BY c_1 DESC NULLS LAST, c_2 NULLS FIRST", //$NON-NLS-1$
+ dataMgr.addData("SELECT g_2.l_orderkey AS c_0, SUM((g_2.l_extendedprice * (1 - g_2.l_discount))) AS c_1, g_1.o_orderdate AS c_2, g_1.o_shippriority AS c_3 FROM TPCR_Oracle_9i.CUSTOMER AS g_0, TPCR_Oracle_9i.ORDERS AS g_1, TPCR_Oracle_9i.LINEITEM AS g_2 WHERE (g_0.c_custkey = g_1.o_custkey) AND (g_2.l_orderkey = g_1.o_orderkey) AND (g_0.c_mktsegment = 'BUILDING') AND (g_1.o_orderdate < {d'1995-03-15'}) AND (g_2.l_shipdate > {ts'1995-03-15 00:00:00.0'}) GROUP BY g_2.l_orderkey, g_1.o_orderdate, g_1.o_shippriority ORDER BY c_1 DESC, c_2", //$NON-NLS-1$
expected);
doProcess(METADATA,
@@ -191,7 +191,7 @@
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT custsale.cntrycode, COUNT(*) AS numcust, SUM(c_acctbal) AS totacctbal FROM (SELECT left(C_PHONE, 2) AS cntrycode, CUSTOMER.C_ACCTBAL FROM CUSTOMER WHERE (left(C_PHONE, 2) IN ('13','31','23','29','30','18','17')) AND (CUSTOMER.C_ACCTBAL > (SELECT AVG(CUSTOMER.C_ACCTBAL) FROM CUSTOMER WHERE (CUSTOMER.C_ACCTBAL > 0.0) AND (left(C_PHONE, 2) IN ('13','31','23','29','30','18','17')))) AND (NOT (EXISTS (SELECT * FROM ORDERS WHERE O_CUSTKEY = C_CUSTKEY)))) AS custsale GROUP BY custsale.cntrycode ORDER BY custsale.cntrycode", //$NON-NLS-1$
METADATA, null, finder,
- new String[] {"SELECT left(g_0.C_PHONE, 2) AS c_0, COUNT(*) AS c_1, SUM(g_0.C_ACCTBAL) AS c_2 FROM TPCR_Oracle_9i.CUSTOMER AS g_0 WHERE (left(g_0.C_PHONE, 2) IN ('13', '31', '23', '29', '30', '18', '17')) AND (g_0.C_ACCTBAL > (SELECT AVG(g_1.C_ACCTBAL) FROM TPCR_Oracle_9i.CUSTOMER AS g_1 WHERE (g_1.C_ACCTBAL > 0E-15) AND (left(g_1.C_PHONE, 2) IN ('13', '31', '23', '29', '30', '18', '17')))) AND (NOT EXISTS (SELECT 1 FROM TPCR_Oracle_9i.ORDERS AS g_2 WHERE g_2.O_CUSTKEY = g_0.C_CUSTKEY)) GROUP BY left(g_0.C_PHONE, 2) ORDER BY c_0 NULLS FIRST"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ new String[] {"SELECT left(g_0.C_PHONE, 2) AS c_0, COUNT(*) AS c_1, SUM(g_0.C_ACCTBAL) AS c_2 FROM TPCR_Oracle_9i.CUSTOMER AS g_0 WHERE (left(g_0.C_PHONE, 2) IN ('13', '31', '23', '29', '30', '18', '17')) AND (g_0.C_ACCTBAL > (SELECT AVG(g_1.C_ACCTBAL) FROM TPCR_Oracle_9i.CUSTOMER AS g_1 WHERE (g_1.C_ACCTBAL > 0E-15) AND (left(g_1.C_PHONE, 2) IN ('13', '31', '23', '29', '30', '18', '17')))) AND (NOT EXISTS (SELECT 1 FROM TPCR_Oracle_9i.ORDERS AS g_2 WHERE g_2.O_CUSTKEY = g_0.C_CUSTKEY)) GROUP BY left(g_0.C_PHONE, 2) ORDER BY c_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
12 years, 2 months