[teiid-commits] teiid SVN: r3766 - in branches/7.4.x: test-integration/common/src/test/java/org/teiid/systemmodel and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Jan 3 17:02:44 EST 2012


Author: jolee
Date: 2012-01-03 17:02:42 -0500 (Tue, 03 Jan 2012)
New Revision: 3766

Added:
   branches/7.4.x/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java
Modified:
   branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
Log:
SOA-3687 TEIID-1868 fix for partial remapping of a temp table query

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java	2012-01-03 21:29:22 UTC (rev 3765)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java	2012-01-03 22:02:42 UTC (rev 3766)
@@ -86,6 +86,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;
@@ -444,17 +445,36 @@
 			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;
 		}
 		String viewName = null;
 		final String tableName = group.getNonCorrelationName().toUpperCase();
-		boolean remapColumns = !tableName.equalsIgnoreCase(group.getName());
-		TempMetadataID groupID = (TempMetadataID)group.getMetadataID();
-		if (groupID.getOriginalMetadataID() != null) {
-			viewName = context.getMetadata().getFullName(groupID.getOriginalMetadataID());
-		}		
+
+		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 TempTableStore globalStore = context.getGlobalTableStore();
@@ -496,21 +516,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.4.x/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java
===================================================================
--- branches/7.4.x/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java	                        (rev 0)
+++ branches/7.4.x/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java	2012-01-03 22:02:42 UTC (rev 3766)
@@ -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;
+
+ at 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());
+	}
+	
+}



More information about the teiid-commits mailing list