Author: shawkins
Date: 2011-12-19 15:24:05 -0500 (Mon, 19 Dec 2011)
New Revision: 3751
Added:
branches/7.6.x/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java
Modified:
branches/7.6.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
Log:
TEIID-1868 fix for partial remapping of a temp table query
Modified:
branches/7.6.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
---
branches/7.6.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2011-12-19
18:29:52 UTC (rev 3750)
+++
branches/7.6.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2011-12-19
20:24:05 UTC (rev 3751)
@@ -80,6 +80,7 @@
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.Update;
import org.teiid.query.sql.navigator.PostOrderNavigator;
import org.teiid.query.sql.symbol.Constant;
@@ -357,12 +358,33 @@
throws TeiidComponentException, QueryMetadataException,
TeiidProcessingException, ExpressionEvaluationException,
QueryProcessingException {
- final GroupSymbol group = query.getFrom().getGroups().get(0);
+ GroupSymbol group = query.getFrom().getGroups().get(0);
if (!group.isTempGroupSymbol()) {
return null;
}
final String tableName = group.getNonCorrelationName().toUpperCase();
- boolean remapColumns = !tableName.equalsIgnoreCase(group.getName());
+ if (!tableName.equalsIgnoreCase(group.getName())) {
+ group = group.clone();
+ group.setName(tableName);
+ group.setDefinition(null);
+ query.getFrom().getClauses().clear();
+ query.getFrom().addClause(new UnaryFromClause(group));
+ final GroupSymbol newGroup = group;
+ //convert to the actual table symbols (this is typically handled by the
languagebridgefactory
+ ExpressionMappingVisitor emv = new ExpressionMappingVisitor(null) {
+ @Override
+ public Expression replaceExpression(Expression element) {
+ if (element instanceof ElementSymbol) {
+ ElementSymbol es = (ElementSymbol)element;
+ es = es.clone();
+ es.setGroupSymbol(newGroup);
+ return es;
+ }
+ return element;
+ }
+ };
+ PostOrderNavigator.doVisit(query, emv);
+ }
TempTable table = null;
if (group.isGlobalTable()) {
final GlobalTableStore globalStore = context.getGlobalTableStore();
@@ -403,21 +425,6 @@
}
}
}
- if (remapColumns) {
- //convert to the actual table symbols (this is typically handled by the
languagebridgefactory
- ExpressionMappingVisitor emv = new ExpressionMappingVisitor(null) {
- @Override
- public Expression replaceExpression(Expression element) {
- if (element instanceof ElementSymbol) {
- ElementSymbol es = (ElementSymbol)element;
- es.getGroupSymbol().setName(tableName);
- es.getGroupSymbol().setDefinition(null);
- }
- return element;
- }
- };
- PostOrderNavigator.doVisit(query, emv);
- }
return table.createTupleSource(query.getProjectedSymbols(), query.getCriteria(),
query.getOrderBy());
}
Added:
branches/7.6.x/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java
===================================================================
---
branches/7.6.x/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java
(rev 0)
+++
branches/7.6.x/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java 2011-12-19
20:24:05 UTC (rev 3751)
@@ -0,0 +1,95 @@
+/*
+ * 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.systemmodel;
+
+import static org.junit.Assert.*;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.LinkedHashMap;
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.deployers.VDBRepository;
+import org.teiid.jdbc.FakeServer;
+import org.teiid.metadata.MetadataFactory;
+import org.teiid.metadata.MetadataStore;
+import org.teiid.metadata.Table;
+import org.teiid.metadata.index.VDBMetadataFactory;
+import org.teiid.query.metadata.TransformationMetadata.Resource;
+
+@SuppressWarnings("nls")
+public class TestMatViewAliasing {
+
+ private static final String MATVIEWS = "matviews";
+ private Connection conn;
+ private FakeServer server;
+
+ @Before public void setUp() throws Exception {
+ server = new FakeServer();
+
+ VDBRepository vdbRepository = new VDBRepository();
+ vdbRepository.setSystemStore(VDBMetadataFactory.getSystem());
+ MetadataFactory mf = new MetadataFactory("foo",
vdbRepository.getBuiltinDatatypes(), new Properties());
+
+ Table mat = mf.addTable("mat");
+ mat.setVirtual(true);
+ mat.setMaterialized(true);
+ mat.setSelectTransformation("/*+ cache(ttl:0) */ select 1 as x, 'y' as
Name");
+
+ mf.addColumn("x", DataTypeManager.DefaultDataTypes.INTEGER, mat);
+ mf.addColumn("Name", DataTypeManager.DefaultDataTypes.STRING, mat);
+
+ MetadataStore ms = mf.getMetadataStore();
+
+ server.deployVDB(MATVIEWS, ms, new LinkedHashMap<String, Resource>());
+ conn = server.createConnection("jdbc:teiid:"+MATVIEWS);
+ }
+
+ @After public void tearDown() throws Exception {
+ server.stop();
+ conn.close();
+ }
+
+ @Test public void testSystemMatViewsWithImplicitLoad() throws Exception {
+ Statement s = conn.createStatement();
+ ResultSet rs = s.executeQuery("select * from MatViews order by name");
+ assertTrue(rs.next());
+ assertEquals("NEEDS_LOADING", rs.getString("loadstate"));
+ assertEquals(false, rs.getBoolean("valid"));
+
+ rs = s.executeQuery("select * from mat order by x");
+ assertTrue(rs.next());
+ rs = s.executeQuery("select * from MatViews where name = 'mat'");
+ assertTrue(rs.next());
+ assertEquals("LOADED", rs.getString("loadstate"));
+
+ rs = s.executeQuery("select * from mat as a, mat as b where a.x = b.name order by
a.x");
+ assertFalse(rs.next());
+ }
+
+}
Property changes on:
branches/7.6.x/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Show replies by date