Author: shawkins
Date: 2012-08-31 14:45:31 -0400 (Fri, 31 Aug 2012)
New Revision: 4388
Added:
trunk/common-core/src/main/java/org/teiid/core/types/ArrayImpl.java
trunk/test-integration/common/src/test/resources/TestODBCProceduresSchema/
trunk/test-integration/common/src/test/resources/TestODBCProceduresSchema/test_Pg_Proc_with_return_table.expected
trunk/test-integration/common/src/test/resources/TestODBCSchema/testOBIEEColumnQuery.expected
trunk/test-integration/common/src/test/resources/TestSystemVirtualModel/testArrayAggType.expected
Removed:
trunk/engine/src/main/java/org/teiid/query/sql/symbol/ArrayValue.java
Modified:
trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
trunk/client/src/main/java/org/teiid/client/metadata/MetadataResult.java
trunk/client/src/main/java/org/teiid/jdbc/MetadataProvider.java
trunk/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java
trunk/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java
trunk/common-core/src/main/java/org/teiid/core/types/JDBCSQLTypeInfo.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/AnyToObjectTransform.java
trunk/common-core/src/test/java/org/teiid/core/types/TestDataTypeManager.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java
trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
trunk/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java
trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java
trunk/engine/src/main/java/org/teiid/query/function/aggregate/ArrayAgg.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentProcedureCriteriaProcessor.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentValueSource.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/navigator/AbstractNavigator.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/Array.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java
trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
trunk/engine/src/test/java/org/teiid/query/processor/TestArrayTable.java
trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
trunk/engine/src/test/java/org/teiid/query/processor/eval/TestExpressionEvaluator.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestArray.java
trunk/runtime/src/main/java/org/teiid/deployers/PgCatalogMetadataStore.java
trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
trunk/runtime/src/main/java/org/teiid/odbc/PGUtil.java
trunk/runtime/src/main/java/org/teiid/transport/PgBackendProtocol.java
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestODBCProceduresSchema.java
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestODBCSchema.java
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java
trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
trunk/test-integration/common/src/test/resources/TestODBCSchema/test_PG_INDEX.expected
trunk/test-integration/common/src/test/resources/TestSystemVirtualModel/testProperties.expected
Log:
TEIID-2166 TEIID-247 adding additional array support for internal consistency and pg
emulation
Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-08-31 18:16:59 UTC
(rev 4387)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-08-31 18:45:31 UTC
(rev 4388)
@@ -32,6 +32,7 @@
<li>TEIID-2158 <b>Rest Services</b> - when required extension metadata
defined on the virtual procedure, a REST based service on that procedure is automatically
generated and deployed upon VDB deployment.
<li>TEIID-2163 <b>Binary XMLSERIALIZE</b> - XMLSERIALIZE now supports
blob/varbinary and the encoding/version and XMLDECLARATION options.
<li>TEIID-2141 <b>OBJECTTABLE</b> - was added to extract values from
objects using arbitrary scripts. See the Reference for usage.
+ <li>TEIID-2111 <b>Vararg Procedures</b> - variable argument procedures
and functions can be created through DDL using the VARIADIC parameter type. See the
Reference for usage.
</ul>
<h2><a name="Compatibility">Compatibility
Issues</a></h2>
@@ -43,6 +44,11 @@
<h4>from 8.0</h4>
<ul>
+ <li>TEIID-2166 array_get will return null if the index is out of bounds rather
than raising an error.
+</ul>
+
+<h4>from 8.0</h4>
+<ul>
<li>org.teiid.metadata.Schema holds FunctionMethods by uuid rather than name to
accommodate overridden method signatures.
<li>MetadataFactory no longer extends Schema. Use the MetadataFactory.getSchema
method to get the target Schema.
<li>DDL created VIRTUAL pushdown functions should be referenced in the
ExecutionFactory.getSupportedFunctions by their full <schema>.<function>
name.
Modified: trunk/client/src/main/java/org/teiid/client/metadata/MetadataResult.java
===================================================================
--- trunk/client/src/main/java/org/teiid/client/metadata/MetadataResult.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/client/src/main/java/org/teiid/client/metadata/MetadataResult.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -33,18 +33,17 @@
public class MetadataResult implements Externalizable {
private static final long serialVersionUID = -1520482281079030324L;
- private Map[] columnMetadata;
- private Map[] parameterMetadata;
+ private Map<Integer, Object>[] columnMetadata;
+ private Map<Integer, Object>[] parameterMetadata;
public MetadataResult() {
}
- public MetadataResult(Map[] columnMetadata, Map[] parameterMetadata) {
- super();
+ public MetadataResult(Map<Integer, Object>[] columnMetadata, Map<Integer,
Object>[] parameterMetadata) {
this.columnMetadata = columnMetadata;
this.parameterMetadata = parameterMetadata;
}
- public Map[] getColumnMetadata() {
+ public Map<Integer, Object>[] getColumnMetadata() {
return columnMetadata;
}
Modified: trunk/client/src/main/java/org/teiid/jdbc/MetadataProvider.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/MetadataProvider.java 2012-08-31 18:16:59
UTC (rev 4387)
+++ trunk/client/src/main/java/org/teiid/jdbc/MetadataProvider.java 2012-08-31 18:45:31
UTC (rev 4388)
@@ -46,7 +46,7 @@
return column.get(metadataPropertyKey);
}
- public int getColumnCount() throws SQLException {
+ public int getColumnCount() {
return metadata.length;
}
@@ -55,8 +55,16 @@
}
public int getIntValue(int columnIndex, Integer metadataPropertyKey) throws
SQLException {
- return ((Integer) getValue(columnIndex, metadataPropertyKey)).intValue();
+ return getIntValue(columnIndex, metadataPropertyKey, 0);
}
+
+ public int getIntValue(int columnIndex, Integer metadataPropertyKey, int
defaultValue) throws SQLException {
+ Integer val = (Integer) getValue(columnIndex, metadataPropertyKey);
+ if (val == null) {
+ return defaultValue;
+ }
+ return val;
+ }
public boolean getBooleanValue(int columnIndex, Integer metadataPropertyKey) throws
SQLException {
return ((Boolean) getValue(columnIndex, metadataPropertyKey)).booleanValue();
Modified: trunk/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -98,7 +98,7 @@
}
public int getColumnDisplaySize(int index) throws SQLException {
- return provider.getIntValue(adjustColumn(index),
ResultsMetadataConstants.DISPLAY_SIZE);
+ return provider.getIntValue(adjustColumn(index),
ResultsMetadataConstants.DISPLAY_SIZE, Integer.MAX_VALUE);
}
public String getColumnLabel(int index) throws SQLException {
Copied: trunk/common-core/src/main/java/org/teiid/core/types/ArrayImpl.java (from rev
4382, trunk/engine/src/main/java/org/teiid/query/sql/symbol/ArrayValue.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/ArrayImpl.java
(rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/ArrayImpl.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -0,0 +1,198 @@
+/*
+ * 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.core.types;
+
+import java.io.Serializable;
+import java.sql.Array;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Map;
+
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.util.HashCodeUtil;
+
+/**
+ * Provides a serializable {@link Array} implementation with minimal JDBC functionality.
+ */
+public final class ArrayImpl implements Comparable<ArrayImpl>, Serializable, Array
{
+ private static final long serialVersionUID = 517794153664734815L;
+ /**
+ * a regrettable hack for pg compatibility since we want to avoid adding a vector type
+ */
+ private boolean zeroBased;
+ private Object[] values;
+
+ @SuppressWarnings("serial")
+ public final static class NullException extends RuntimeException {};
+ private final static NullException ex = new NullException();
+
+ public ArrayImpl(Object[] values) {
+ this.values = values;
+ }
+
+ @Override
+ public int compareTo(ArrayImpl o) {
+ return compareTo(o, false, null);
+ }
+
+ public int compareTo(ArrayImpl o, boolean noNulls, Comparator<Object> comparator)
{
+ if (zeroBased != o.zeroBased) {
+ throw new TeiidRuntimeException("Incompatible types"); //$NON-NLS-1$
+ }
+ int len1 = values.length;
+ int len2 = o.values.length;
+ int lim = Math.min(len1, len2);
+ for (int k = 0; k < lim; k++) {
+ Object object1 = values[k];
+ Object object2 = o.values[k];
+ if (object1 == null) {
+ if (noNulls) {
+ throw ex;
+ }
+ if (object2 != null) {
+ return -1;
+ }
+ continue;
+ } else if (object2 == null) {
+ if (noNulls) {
+ throw ex;
+ }
+ return 1;
+ }
+ int comp = 0;
+ if (comparator != null) {
+ comp = comparator.compare(object1, object2);
+ } else {
+ comp = ((Comparable)object1).compareTo(object2);
+ }
+ if (comp != 0) {
+ return comp;
+ }
+ }
+ return len1 - len2;
+ }
+
+ @Override
+ public int hashCode() {
+ return HashCodeUtil.expHashCode(0, this.values);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof ArrayImpl)) {
+ return false;
+ }
+ ArrayImpl other = (ArrayImpl)obj;
+ return zeroBased == other.zeroBased && Arrays.equals(values, other.values);
+ }
+
+ public Object[] getValues() {
+ return values;
+ }
+
+ @Override
+ public String toString() {
+ return Arrays.toString(this.values);
+ }
+
+ public boolean isZeroBased() {
+ return zeroBased;
+ }
+
+ public void setZeroBased(boolean zeroBased) {
+ this.zeroBased = zeroBased;
+ }
+
+ @Override
+ public void free() throws SQLException {
+
+ }
+
+ @Override
+ public Object getArray() throws SQLException {
+ return values;
+ }
+
+ @Override
+ public Object getArray(Map<String, Class<?>> map) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ @Override
+ public Object getArray(long index, int count) throws SQLException {
+ if (index > Integer.MAX_VALUE) {
+ throw new ArrayIndexOutOfBoundsException(String.valueOf(index));
+ }
+ int offset = zeroBased?0:1;
+ int iIndex = (int)index - offset;
+ if (iIndex >= values.length || iIndex < 0) {
+ throw new ArrayIndexOutOfBoundsException(iIndex);
+ }
+ return Arrays.copyOfRange(values, iIndex, Math.min(iIndex + count, values.length));
+ }
+
+ @Override
+ public Object getArray(long index, int count, Map<String, Class<?>> map)
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ @Override
+ public int getBaseType() throws SQLException {
+ return
JDBCSQLTypeInfo.getSQLType(DataTypeManager.getDataTypeName(values.getClass().getComponentType()));
+ }
+
+ @Override
+ public String getBaseTypeName() throws SQLException {
+ return DataTypeManager.getDataTypeName(values.getClass().getComponentType());
+ }
+
+ @Override
+ public ResultSet getResultSet() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ @Override
+ public ResultSet getResultSet(Map<String, Class<?>> map)
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ @Override
+ public ResultSet getResultSet(long index, int count) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ @Override
+ public ResultSet getResultSet(long index, int count,
+ Map<String, Class<?>> map) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+}
Property changes on: trunk/common-core/src/main/java/org/teiid/core/types/ArrayImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -31,15 +31,7 @@
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import org.teiid.core.CorePlugin;
import org.teiid.core.types.basic.*;
@@ -66,7 +58,7 @@
*/
public class DataTypeManager {
- private static final String ARRAY_SUFFIX = "[]"; //$NON-NLS-1$
+ static final String ARRAY_SUFFIX = "[]"; //$NON-NLS-1$
private static final boolean USE_VALUE_CACHE =
PropertiesUtils.getBooleanProperty(System.getProperties(),
"org.teiid.useValueCache", false); //$NON-NLS-1$
private static final boolean COMPARABLE_LOBS =
PropertiesUtils.getBooleanProperty(System.getProperties(),
"org.teiid.comparableLobs", false); //$NON-NLS-1$
private static final boolean COMPARABLE_OBJECT =
PropertiesUtils.getBooleanProperty(System.getProperties(),
"org.teiid.comparableObject", false); //$NON-NLS-1$
@@ -308,6 +300,9 @@
/** Base data type names and classes, Type class --> Type name */
private static Map<Class<?>, String> dataTypeClasses = new
LinkedHashMap<Class<?>, String>(128);
+
+ private static Map<Class<?>, Class<?>> arrayTypes = new
HashMap<Class<?>, Class<?>>(128);
+ private static Map<Class<?>, String> arrayTypeNames = new
HashMap<Class<?>, String>(128);
private static Set<String> DATA_TYPE_NAMES;
@@ -324,6 +319,12 @@
loadBasicTransforms();
loadSourceConversions();
+
+ for (Map.Entry<String, Class<?>> entry : dataTypeNames.entrySet()) {
+ Class<?> arrayType = getArrayType(entry.getValue());
+ arrayTypes.put(entry.getValue(), arrayType);
+ arrayTypeNames.put(arrayType, getDataTypeName(arrayType));
+ }
}
/**
@@ -379,13 +380,17 @@
}
if (dataTypeClass == null) {
- if (name.endsWith(ARRAY_SUFFIX)) {
+ if (isArrayType(name)) {
return getArrayType(getDataTypeClass(name.substring(0, name.length() - 2)));
}
dataTypeClass = DefaultDataClasses.OBJECT;
}
return dataTypeClass;
}
+
+ public static boolean isArrayType(String name) {
+ return name.endsWith(ARRAY_SUFFIX);
+ }
public static String getDataTypeName(Class<?> typeClass) {
if (typeClass == null) {
@@ -394,11 +399,14 @@
String result = dataTypeClasses.get(typeClass);
if (result == null) {
if (typeClass.isArray()) {
- return getDataTypeName(typeClass.getComponentType()) + ARRAY_SUFFIX;
+ result = arrayTypeNames.get(typeClass);
+ if (result == null) {
+ return getDataTypeName(typeClass.getComponentType()) + ARRAY_SUFFIX;
+ }
+ return result;
}
result = DefaultDataTypes.OBJECT;
}
-
return result;
}
@@ -517,18 +525,22 @@
innerMap.put(targetName, transform);
}
- public static List<String> getImplicitConversions(String type) {
+ public static void getImplicitConversions(String type, Collection<String> result)
{
Map<String, Transform> innerMap = transforms.get(type);
if (innerMap != null) {
- List<String> result = new ArrayList<String>(innerMap.size());
for (Map.Entry<String, Transform> entry : innerMap.entrySet()) {
if (!entry.getValue().isExplicit()) {
result.add(entry.getKey());
}
}
- return result;
+ return;
}
- return Collections.emptyList();
+ String previous = DataTypeManager.DefaultDataTypes.OBJECT;
+ while (isArrayType(type)) {
+ previous += ARRAY_SUFFIX;
+ result.add(previous);
+ type = getComponentType(type);
+ }
}
public static boolean isImplicitConversion(String srcType, String tgtType) {
@@ -536,9 +548,19 @@
if (t != null) {
return !t.isExplicit();
}
+ if (DefaultDataTypes.NULL.equals(srcType) &&
!DefaultDataTypes.NULL.equals(tgtType)) {
+ return true;
+ }
+ if (isArrayType(srcType) && isArrayType(tgtType)) {
+ return isImplicitConversion(getComponentType(srcType), getComponentType(tgtType));
+ }
return false;
}
+ private static String getComponentType(String srcType) {
+ return srcType.substring(0, srcType.length() - ARRAY_SUFFIX.length());
+ }
+
public static boolean isExplicitConversion(String srcType, String tgtType) {
Transform t = getTransform(srcType, tgtType);
if (t != null) {
@@ -913,6 +935,10 @@
}
public static Class<?> getArrayType(Class<?> classType) {
+ Class<?> result = arrayTypes.get(classType);
+ if (result != null) {
+ return result;
+ }
return Array.newInstance(classType, 0).getClass();
}
Modified: trunk/common-core/src/main/java/org/teiid/core/types/JDBCSQLTypeInfo.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/JDBCSQLTypeInfo.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/common-core/src/main/java/org/teiid/core/types/JDBCSQLTypeInfo.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -22,6 +22,7 @@
package org.teiid.core.types;
+import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.SQLXML;
@@ -93,6 +94,11 @@
addType(DataTypeManager.DefaultDataTypes.XML, Integer.MAX_VALUE, Integer.MAX_VALUE,
SQLXML.class.getName(), Types.SQLXML);
addType(DataTypeManager.DefaultDataTypes.NULL, 4, 1, null, Types.NULL);
addType(DataTypeManager.DefaultDataTypes.VARBINARY,
DataTypeManager.MAX_LOB_MEMORY_BYTES, DataTypeManager.MAX_LOB_MEMORY_BYTES,
byte[].class.getName(), Types.VARBINARY, Types.BINARY);
+ addType(DataTypeManager.DefaultDataTypes.VARBINARY,
DataTypeManager.MAX_LOB_MEMORY_BYTES, DataTypeManager.MAX_LOB_MEMORY_BYTES,
byte[].class.getName(), Types.VARBINARY, Types.BINARY);
+
+ TypeInfo typeInfo = new TypeInfo(Integer.MAX_VALUE, 0, "ARRAY",
Array.class.getName(), new int[Types.ARRAY]); //$NON-NLS-1$
+ CLASSNAME_TO_TYPEINFO.put(Array.class.getName(), typeInfo);
+ TYPE_TO_TYPEINFO.put(Types.ARRAY, typeInfo);
}
private static TypeInfo addType(String typeName, int maxDisplaySize, int precision,
String javaClassName, int... sqlTypes) {
@@ -117,7 +123,7 @@
/**
* This method is used to obtain a short indicating JDBC SQL type for any object.
* The short values that give the type info are from java.sql.Types.
- * @param Name of the metamatrix type.
+ * @param Name of the teiid type.
* @return A short value representing SQL Type for the given java type.
*/
public static final int getSQLType(String typeName) {
@@ -129,6 +135,9 @@
TypeInfo sqlType = NAME_TO_TYPEINFO.get(typeName);
if (sqlType == null) {
+ if (DataTypeManager.isArrayType(typeName)) {
+ return Types.ARRAY;
+ }
return Types.JAVA_OBJECT;
}
Modified:
trunk/common-core/src/main/java/org/teiid/core/types/basic/AnyToObjectTransform.java
===================================================================
---
trunk/common-core/src/main/java/org/teiid/core/types/basic/AnyToObjectTransform.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/common-core/src/main/java/org/teiid/core/types/basic/AnyToObjectTransform.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -35,7 +35,7 @@
}
@Override
- public Class getSourceType() {
+ public Class<?> getSourceType() {
return sourceType;
}
@@ -55,7 +55,7 @@
* Type of the outgoing value.
* @return Target type
*/
- public Class getTargetType() {
+ public Class<?> getTargetType() {
return DataTypeManager.DefaultDataClasses.OBJECT;
}
Modified: trunk/common-core/src/test/java/org/teiid/core/types/TestDataTypeManager.java
===================================================================
---
trunk/common-core/src/test/java/org/teiid/core/types/TestDataTypeManager.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/common-core/src/test/java/org/teiid/core/types/TestDataTypeManager.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -25,7 +25,9 @@
import static org.junit.Assert.*;
import java.sql.Types;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import java.util.Set;
import javax.sql.rowset.serial.SerialBlob;
@@ -174,6 +176,8 @@
assertEquals(Types.SQLXML,
JDBCSQLTypeInfo.getSQLTypeFromRuntimeType(DataTypeManager.DefaultDataClasses.XML));
assertEquals(DataTypeManager.DefaultDataTypes.STRING,
JDBCSQLTypeInfo.getTypeName(Types.CHAR));
assertEquals(Types.CHAR,
JDBCSQLTypeInfo.getSQLTypeFromRuntimeType(DataTypeManager.DefaultDataClasses.CHAR));
+
+ assertEquals(Types.ARRAY,
JDBCSQLTypeInfo.getSQLType(DataTypeManager.getDataTypeName(DataTypeManager.getArrayType(DataTypeManager.DefaultDataClasses.BIG_DECIMAL))));
}
@Test public void testRuntimeTypeConversion() throws Exception {
@@ -197,12 +201,14 @@
}
@Test public void testImplicitConversions() {
+ List<String> c = new ArrayList<String>();
+ DataTypeManager.getImplicitConversions(DataTypeManager.DefaultDataTypes.INTEGER,
c);
assertEquals(Arrays.asList(DataTypeManager.DefaultDataTypes.LONG,
DataTypeManager.DefaultDataTypes.BIG_INTEGER,
DataTypeManager.DefaultDataTypes.DOUBLE,
DataTypeManager.DefaultDataTypes.BIG_DECIMAL,
DataTypeManager.DefaultDataTypes.STRING,
- DataTypeManager.DefaultDataTypes.OBJECT),
DataTypeManager.getImplicitConversions(DataTypeManager.DefaultDataTypes.INTEGER));
+ DataTypeManager.DefaultDataTypes.OBJECT), c);
}
@Test(expected=TransformationException.class) public void testStringToXML() throws
Exception {
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -32,6 +32,7 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.types.ArrayImpl;
import org.teiid.core.types.DataTypeManager;
import org.teiid.language.*;
import org.teiid.language.DerivedColumn;
@@ -586,7 +587,7 @@
result.setValueIndex(valueIndex++);
return result;
}
- if (constant.getValue() instanceof ArrayValue) {
+ if (constant.getValue() instanceof ArrayImpl) {
//TODO: we could check if there is a common base type (also needs to be in the
dependent logic)
// and expand binding options in the translators
@@ -597,7 +598,7 @@
//result.setBindEligible(constant.isBindEligible());
//return result;
- ArrayValue av = (ArrayValue)constant.getValue();
+ ArrayImpl av = (ArrayImpl)constant.getValue();
List<Constant> vals = new ArrayList<Constant>();
Class<?> baseType = null;
for (Object o : av.getValues()) {
@@ -820,7 +821,7 @@
Literal value = null;
if (direction != Direction.OUT) {
if (param.isVarArg()) {
- ArrayValue av = (ArrayValue) ((Constant)param.getExpression()).getValue();
+ ArrayImpl av = (ArrayImpl) ((Constant)param.getExpression()).getValue();
for (Object obj : av.getValues()) {
Argument arg = new Argument(direction, new Literal(obj,
param.getClassType().getComponentType()), param.getClassType().getComponentType(),
metadataParam);
translatedParameters.add(arg);
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -147,7 +147,7 @@
// For each projected symbol, construct a metadata map
private MetadataResult getMetadataForCommand(Command originalCommand) throws
TeiidComponentException {
- Map[] columnMetadata = null;
+ Map<Integer, Object>[] columnMetadata = null;
switch(originalCommand.getType()) {
case Command.TYPE_QUERY:
@@ -196,7 +196,7 @@
}
}
List<Reference> params =
ReferenceCollectorVisitor.getReferences(originalCommand);
- Map[] paramMetadata = new Map[params.size()];
+ Map<Integer, Object>[] paramMetadata = new Map[params.size()];
for (int i = 0; i < params.size(); i++) {
Reference param = params.get(i);
paramMetadata[i] = getDefaultColumn(null, paramMap.get(param), param.getType());
@@ -205,8 +205,8 @@
return new MetadataResult(columnMetadata, paramMetadata);
}
- private Map[] createProjectedSymbolMetadata(Command originalCommand) throws
TeiidComponentException {
- Map[] columnMetadata;
+ private Map<Integer, Object>[] createProjectedSymbolMetadata(Command
originalCommand) throws TeiidComponentException {
+ Map<Integer, Object>[] columnMetadata;
// Allow command to use temporary metadata
TempMetadataStore tempMetadata = originalCommand.getTemporaryMetadata();
if(tempMetadata != null && tempMetadata.getData().size() > 0) {
@@ -250,9 +250,9 @@
return getMetadataForCommand(command);
}
- private Map createXMLColumnMetadata(Query xmlCommand) {
+ private Map<Integer, Object> createXMLColumnMetadata(Query xmlCommand) {
GroupSymbol doc = xmlCommand.getFrom().getGroups().get(0);
- Map xmlMetadata = getDefaultColumn(doc.getName(), XML_COLUMN_NAME,
XMLType.class);
+ Map<Integer, Object> xmlMetadata = getDefaultColumn(doc.getName(),
XML_COLUMN_NAME, XMLType.class);
// Override size as XML may be big
xmlMetadata.put(ResultsMetadataConstants.DISPLAY_SIZE,
JDBCSQLTypeInfo.XML_COLUMN_LENGTH);
@@ -260,7 +260,7 @@
return xmlMetadata;
}
- private Map createColumnMetadata(String label, Expression symbol) throws
QueryMetadataException, TeiidComponentException {
+ private Map<Integer, Object> createColumnMetadata(String label, Expression
symbol) throws QueryMetadataException, TeiidComponentException {
if(symbol instanceof ElementSymbol) {
return createElementMetadata(label, (ElementSymbol) symbol);
}
@@ -273,7 +273,7 @@
return createTypedMetadata(label, symbol);
}
- private Map createElementMetadata(String label, ElementSymbol symbol) throws
QueryMetadataException, TeiidComponentException {
+ private Map<Integer, Object> createElementMetadata(String label, ElementSymbol
symbol) throws QueryMetadataException, TeiidComponentException {
Object elementID = symbol.getMetadataID();
Map<Integer, Object> column = new HashMap<Integer, Object>();
@@ -339,7 +339,7 @@
return column;
}
- private Map createAggregateMetadata(String shortColumnName,
+ private Map<Integer, Object> createAggregateMetadata(String shortColumnName,
AggregateSymbol symbol) throws
QueryMetadataException, TeiidComponentException {
Type function = symbol.getAggregateFunction();
@@ -352,7 +352,7 @@
return createTypedMetadata(shortColumnName, symbol);
}
- private Map createTypedMetadata(String shortColumnName, Expression symbol) {
+ private Map<Integer, Object> createTypedMetadata(String shortColumnName,
Expression symbol) {
return getDefaultColumn(null, shortColumnName, symbol.getType());
}
Modified: trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java 2012-08-31 18:16:59 UTC
(rev 4387)
+++ trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java 2012-08-31 18:45:31 UTC
(rev 4388)
@@ -367,7 +367,6 @@
TEIID30411,
TEIID30412,
TEIID30413,
- TEIID30415,
TEIID30416,
TEIID30418,
TEIID30419,
Modified: trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2012-08-31 18:16:59 UTC
(rev 4387)
+++ trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2012-08-31 18:45:31 UTC
(rev 4388)
@@ -54,15 +54,7 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidRuntimeException;
-import org.teiid.core.types.BaseLob;
-import org.teiid.core.types.BlobType;
-import org.teiid.core.types.ClobType;
-import org.teiid.core.types.InputStreamFactory;
-import org.teiid.core.types.SQLXMLImpl;
-import org.teiid.core.types.Sequencable;
-import org.teiid.core.types.Streamable;
-import org.teiid.core.types.TransformationException;
-import org.teiid.core.types.XMLType;
+import org.teiid.core.types.*;
import org.teiid.core.types.XMLType.Type;
import org.teiid.core.types.basic.StringToSQLXMLTransform;
import org.teiid.core.util.EquivalenceUtil;
@@ -544,11 +536,11 @@
//semantics. each element is treated as an individual comparison,
//so null implies unknown. h2 (and likely other dbms) allow for null
//array element equality
- if (leftValue instanceof ArrayValue) {
- ArrayValue av = (ArrayValue)leftValue;
+ if (leftValue instanceof ArrayImpl) {
+ ArrayImpl av = (ArrayImpl)leftValue;
try {
- compare = av.compareTo((ArrayValue)value, true);
- } catch (ArrayValue.NullException e) {
+ compare = av.compareTo((ArrayImpl)value, true, Constant.COMPARATOR);
+ } catch (ArrayImpl.NullException e) {
return null;
}
} else {
@@ -664,11 +656,11 @@
} else if (expression instanceof Array) {
Array array = (Array)expression;
List<Expression> exprs = array.getExpressions();
- Object[] result = new Object[exprs.size()];
+ Object[] result = (Object[])
java.lang.reflect.Array.newInstance(array.getComponentType(), exprs.size());
for (int i = 0; i < exprs.size(); i++) {
result[i] = internalEvaluate(exprs.get(i), tuple);
}
- return new ArrayValue(result);
+ return new ArrayImpl(result);
} else {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30329,
QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30329, expression.getClass().getName()));
}
Modified: trunk/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -30,6 +30,7 @@
import org.teiid.api.exception.query.FunctionExecutionException;
import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.types.ArrayImpl;
import org.teiid.core.types.BinaryType;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.TransformationException;
@@ -38,7 +39,6 @@
import org.teiid.metadata.FunctionMethod.Determinism;
import org.teiid.metadata.FunctionMethod.PushDown;
import org.teiid.query.QueryPlugin;
-import org.teiid.query.sql.symbol.ArrayValue;
import org.teiid.query.util.CommandContext;
@@ -224,7 +224,7 @@
}
if (method.isVarArgs()) {
if (calledWithVarArgArrayParam) {
- ArrayValue av = (ArrayValue)values[values.length -1];
+ ArrayImpl av = (ArrayImpl)values[values.length -1];
if (av != null) {
Object[] vals = av.getValues();
values[values.length - 1] = vals;
@@ -296,6 +296,9 @@
}
}
result = DataTypeManager.convertToRuntimeType(result);
+ if (expectedType.isArray() && result instanceof ArrayImpl) {
+ return result;
+ }
result = DataTypeManager.transformValue(result, expectedType);
if (result instanceof String) {
String s = (String)result;
Modified: trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -59,7 +59,6 @@
import org.teiid.language.SQLConstants;
import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.QueryPlugin;
-import org.teiid.query.sql.symbol.ArrayValue;
import org.teiid.query.util.CommandContext;
/**
@@ -1402,30 +1401,24 @@
public static Object array_get(Object array, int index) throws
FunctionExecutionException, SQLException {
try {
- if (array.getClass().isArray()) {
- return Array.get(array, index - 1);
- }
if (array instanceof java.sql.Array) {
return Array.get(((java.sql.Array)array).getArray(index, 1), 0);
}
- if (array instanceof ArrayValue) {
- return ((ArrayValue)array).getValues()[index - 1];
+ if (array.getClass().isArray()) {
+ return Array.get(array, index - 1);
}
} catch (ArrayIndexOutOfBoundsException e) {
- throw new FunctionExecutionException(QueryPlugin.Event.TEIID30415,
QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30415, index));
+ return null;
}
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30416,
QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30416, array.getClass()));
}
public static int array_length(Object array) throws FunctionExecutionException,
SQLException {
- if (array.getClass().isArray()) {
- return Array.getLength(array);
- }
if (array instanceof java.sql.Array) {
return Array.getLength(((java.sql.Array)array).getArray());
}
- if (array instanceof ArrayValue) {
- return ((ArrayValue)array).getValues().length;
+ if (array.getClass().isArray()) {
+ return Array.getLength(array);
}
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30416,
QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30416, array.getClass()));
}
Modified: trunk/engine/src/main/java/org/teiid/query/function/aggregate/ArrayAgg.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/aggregate/ArrayAgg.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/engine/src/main/java/org/teiid/query/function/aggregate/ArrayAgg.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -21,6 +21,7 @@
*/
package org.teiid.query.function.aggregate;
+import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
@@ -28,12 +29,20 @@
import org.teiid.api.exception.query.FunctionExecutionException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.ArrayImpl;
+import org.teiid.core.types.DataTypeManager;
import org.teiid.query.util.CommandContext;
public class ArrayAgg extends SingleArgumentAggregateFunction {
private ArrayList<Object> result;
+ private Class<?> componentType;
+ @Override
+ public void initialize(Class<?> dataType, Class<?> inputType) {
+ this.componentType = inputType;
+ }
+
@Override
public void addInputDirect(Object input, List<?> tuple, CommandContext
commandContext) throws TeiidComponentException, TeiidProcessingException {
if (this.result == null) {
@@ -50,7 +59,14 @@
if (this.result == null) {
return null;
}
- return this.result.toArray();
+ if (this.componentType == DataTypeManager.DefaultDataClasses.OBJECT) {
+ return new ArrayImpl(this.result.toArray());
+ }
+ Object array = Array.newInstance(componentType, this.result.size());
+ for (int i = 0; i < result.size(); i++) {
+ Array.set(array, i, result.get(i));
+ }
+ return new ArrayImpl((Object[]) array);
}
@Override
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -253,7 +253,7 @@
private void connectSubqueryContainers(PlanNode plan) throws QueryPlannerException,
QueryMetadataException, TeiidComponentException {
Set<GroupSymbol> groupSymbols = getGroupSymbols(plan);
- for (PlanNode node : NodeEditor.findAllNodes(plan, NodeConstants.Types.PROJECT |
NodeConstants.Types.SELECT | NodeConstants.Types.JOIN | NodeConstants.Types.SOURCE)) {
+ for (PlanNode node : NodeEditor.findAllNodes(plan, NodeConstants.Types.PROJECT |
NodeConstants.Types.SELECT | NodeConstants.Types.JOIN | NodeConstants.Types.SOURCE |
NodeConstants.Types.GROUP)) {
List<SubqueryContainer> subqueryContainers =
node.getSubqueryContainers();
if (subqueryContainers.isEmpty()){
continue;
@@ -267,7 +267,7 @@
Command subCommand = (Command)container.getCommand().clone();
ArrayList<Reference> correlatedReferences = new
ArrayList<Reference>();
CorrelatedReferenceCollectorVisitor.collectReferences(subCommand,
localGroupSymbols, correlatedReferences);
- if (node.getType() != NodeConstants.Types.JOIN) {
+ if (node.getType() != NodeConstants.Types.JOIN && node.getType()
!= NodeConstants.Types.GROUP) {
PlanNode grouping = NodeEditor.findNodePreOrder(node,
NodeConstants.Types.GROUP, NodeConstants.Types.SOURCE | NodeConstants.Types.JOIN);
if (grouping != null && !correlatedReferences.isEmpty()) {
SymbolMap map = (SymbolMap) grouping.getProperty(Info.SYMBOL_MAP);
Modified: trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -48,6 +48,7 @@
import org.teiid.common.buffer.BufferManager.TupleSourceType;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.ArrayImpl;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.Assertion;
import org.teiid.dqp.internal.process.DataTierTupleSource;
@@ -71,7 +72,6 @@
import org.teiid.query.sql.ProcedureReservedWords;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.symbol.ArrayValue;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.util.VariableContext;
@@ -252,8 +252,8 @@
if (value == null) {
throw new QueryValidatorException(QueryPlugin.Event.TEIID30164,
QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30164, param));
}
- if (value instanceof ArrayValue && metadata.isVariadic(param.getMetadataID()))
{
- ArrayValue av = (ArrayValue)value;
+ if (value instanceof ArrayImpl && metadata.isVariadic(param.getMetadataID()))
{
+ ArrayImpl av = (ArrayImpl)value;
for (Object o : av.getValues()) {
if (o == null) {
throw new QueryValidatorException(QueryPlugin.Event.TEIID30164,
QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30164, param));
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentProcedureCriteriaProcessor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentProcedureCriteriaProcessor.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentProcedureCriteriaProcessor.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -29,13 +29,13 @@
import org.teiid.common.buffer.BlockedException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.ArrayImpl;
import org.teiid.core.util.Assertion;
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.IsNullCriteria;
import org.teiid.query.sql.symbol.Array;
-import org.teiid.query.sql.symbol.ArrayValue;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.Reference;
@@ -101,7 +101,7 @@
validRow = false;
break;
}
- ArrayValue valueArray = (ArrayValue)value;
+ ArrayImpl valueArray = (ArrayImpl)value;
for (int j = 0; j < array.getExpressions().size(); j++) {
validRow = setParam(context, valueArray.getValues()[j], nullAllowed,
(Reference) array.getExpressions().get(j));
if (!validRow) {
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentValueSource.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentValueSource.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentValueSource.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -33,10 +33,10 @@
import org.teiid.common.buffer.TupleBuffer;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.ArrayImpl;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.Assertion;
import org.teiid.query.sql.symbol.Array;
-import org.teiid.query.sql.symbol.ArrayValue;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.util.ValueIteratorSource;
@@ -76,7 +76,7 @@
int index = 0;
if (valueExpression != null) {
if (valueExpression instanceof Array) {
- Array array = (Array)valueExpression;
+ final Array array = (Array)valueExpression;
List<Expression> exprs = array.getExpressions();
final int[] indexes = new int[exprs.size()];
for (int i = 0; i < exprs.size(); i++) {
@@ -86,14 +86,14 @@
@Override
public Object next() throws TeiidComponentException {
List<?> tuple = super.nextTuple();
- Object[] a = new Object[indexes.length];
+ Object[] a = (Object[])
java.lang.reflect.Array.newInstance(array.getComponentType(), indexes.length);
for (int i = 0; i < indexes.length; i++) {
a[i] = tuple.get(indexes[i]);
if (a[i] == null) {
return null; //TODO: this is a hack
}
}
- return new ArrayValue(a);
+ return new ArrayImpl(a);
}
};
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -105,32 +105,56 @@
* @param typeNames an ordered array of unique type names.
* @return a type name to which all the given types can be converted
*/
- public static String getCommonType(String[] typeNames) {
+ @SuppressWarnings("null")
+ public static String getCommonType(String[] typeNames) {
if (typeNames == null || typeNames.length == 0) {
return null;
}
- // If there is only one type, then simply return it
if (typeNames.length == 1) {
- return typeNames[0];
+ return typeNames[0];
}
- // A type can be implicitly converted to itself, so we put the implicit
- // conversions as well as the original type in the working list of
- // conversions.
- HashSet<String> commonConversions = new LinkedHashSet<String>();
- commonConversions.add(typeNames[0]);
- commonConversions.addAll(DataTypeManager.getImplicitConversions(typeNames[0]));
- for (int i = 1; i < typeNames.length; i++ ) {
- HashSet<String> conversions = new
LinkedHashSet<String>(DataTypeManager.getImplicitConversions(typeNames[i]));
- conversions.add(typeNames[i]);
- // Equivalent to set intersection
- commonConversions.retainAll(conversions);
+ LinkedHashSet<String> commonConversions = null;
+ Set<String> types = new LinkedHashSet<String>();
+ Set<String> conversions = null;
+ boolean first = true;
+ for (int i = 0; i < typeNames.length && (first ||
!commonConversions.isEmpty()); i++) {
+ String string = typeNames[i];
+ if (string == null) {
+ return null;
+ }
+ if (DataTypeManager.DefaultDataTypes.NULL.equals(string) || !types.add(string)) {
+ continue;
+ }
+ if (first) {
+ commonConversions = new LinkedHashSet<String>();
+ // A type can be implicitly convertd to itself, so we put the implicit
+ // conversions as well as the original type in the working list of
+ // conversions.
+ commonConversions.add(string);
+ DataTypeManager.getImplicitConversions(string, commonConversions);
+ first = false;
+ } else {
+ if (conversions == null) {
+ conversions = new HashSet<String>();
+ }
+ DataTypeManager.getImplicitConversions(string, conversions);
+ conversions.add(string);
+ // Equivalent to set intersection
+ commonConversions.retainAll(conversions);
+ conversions.clear();
+ }
+
+ }
+ // If there is only one type, then simply return it
+ if (types.size() == 1) {
+ return types.iterator().next();
}
- if (commonConversions.isEmpty()) {
- return null;
+ if (types.isEmpty()) {
+ return DataTypeManager.DefaultDataTypes.NULL;
}
- for (int i = 0; i < typeNames.length; i++) {
- if (commonConversions.contains(typeNames[i])) {
- return typeNames[i];
+ for (String string : types) {
+ if (commonConversions.contains(string)) {
+ return string;
}
}
commonConversions.remove(DefaultDataTypes.STRING);
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -57,7 +57,8 @@
public class ResolverVisitor extends LanguageVisitor {
- private static final String SYS_PREFIX = CoreConstants.SYSTEM_MODEL + '.';
+ public static final String TEIID_PASS_THROUGH_TYPE =
"teiid:pass-through-type"; //$NON-NLS-1$
+ private static final String SYS_PREFIX = CoreConstants.SYSTEM_MODEL + '.';
private static class ElementMatch {
ElementSymbol element;
@@ -542,6 +543,9 @@
} else if (FunctionLibrary.ARRAY_GET.equalsIgnoreCase(fd.getName()) &&
args[0].getType().isArray()) {
//hack to use typed array values
fd = library.copyFunctionChangeReturnType(fd, args[0].getType().getComponentType());
+ } else if (Boolean.valueOf(fd.getMethod().getProperty(TEIID_PASS_THROUGH_TYPE,
false))) {
+ //hack largely to support pg
+ fd = library.copyFunctionChangeReturnType(fd, args[0].getType());
}
function.setFunctionDescriptor(fd);
@@ -958,16 +962,12 @@
for (int i = 0; i < whenCount; i++) {
then = obj.getThenExpression(i);
setDesiredType(then, thenType, obj);
- if (!thenTypeNames.contains(DataTypeManager.getDataTypeName(then.getType()))) {
- thenTypeNames.add(DataTypeManager.getDataTypeName(then.getType()));
- }
+ thenTypeNames.add(DataTypeManager.getDataTypeName(then.getType()));
}
// Set the type of the else expression
if (elseExpr != null) {
setDesiredType(elseExpr, thenType, obj);
- if
(!thenTypeNames.contains(DataTypeManager.getDataTypeName(elseExpr.getType()))) {
- thenTypeNames.add(DataTypeManager.getDataTypeName(elseExpr.getType()));
- }
+ thenTypeNames.add(DataTypeManager.getDataTypeName(elseExpr.getType()));
}
// Invariants: all the expressions' types are non-null
@@ -977,7 +977,7 @@
if (thenTypeName == null) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30079,
QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30079, "THEN/ELSE", obj));
//$NON-NLS-1$
}
- ArrayList thens = new ArrayList(whenCount);
+ ArrayList<Expression> thens = new ArrayList<Expression>(whenCount);
for (int i = 0; i < whenCount; i++) {
thens.add(ResolverUtil.convertExpression(obj.getThenExpression(i), thenTypeName,
metadata));
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/navigator/AbstractNavigator.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/sql/navigator/AbstractNavigator.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/engine/src/main/java/org/teiid/query/sql/navigator/AbstractNavigator.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -23,6 +23,8 @@
package org.teiid.query.sql.navigator;
import java.util.Collection;
+import java.util.List;
+import java.util.RandomAccess;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
@@ -63,11 +65,18 @@
}
protected void visitNodes(Collection<? extends LanguageObject> nodes) {
- if(this.visitor.shouldAbort()) {
+ if(this.visitor.shouldAbort() || nodes == null) {
return;
}
-
- if (nodes != null && nodes.size() > 0) {
+ int size = nodes.size();
+ if (size > 0) {
+ if (nodes instanceof List<?> && nodes instanceof RandomAccess) {
+ List<? extends LanguageObject> list = (List<? extends
LanguageObject>) nodes;
+ for (int i = 0; i < size; i++) {
+ visitNode(list.get(i));
+ }
+ return;
+ }
for (LanguageObject languageObject : nodes) {
visitNode(languageObject);
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -197,7 +197,10 @@
expressionType = this.getArg(0).getType();
return AVG_TYPES.get(expressionType);
case ARRAY_AGG:
- return DataTypeManager.DefaultDataClasses.OBJECT;
+ if (this.getArg(0) == null) {
+ return null;
+ }
+ return DataTypeManager.getArrayType(this.getArg(0).getType());
case TEXTAGG:
return DataTypeManager.DefaultDataClasses.BLOB;
case USER_DEFINED:
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/Array.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/Array.java 2012-08-31 18:16:59
UTC (rev 4387)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/Array.java 2012-08-31 18:45:31
UTC (rev 4388)
@@ -66,7 +66,8 @@
@Override
public Array clone() {
- Array clone = new Array(type, LanguageObject.Util.deepClone(getExpressions(),
Expression.class));
+ Array clone = new Array(LanguageObject.Util.deepClone(getExpressions(),
Expression.class));
+ clone.type = type;
clone.implicit = implicit;
return clone;
}
@@ -92,7 +93,7 @@
@Override
public int hashCode() {
- return HashCodeUtil.hashCode(0, getExpressions());
+ return HashCodeUtil.expHashCode(type.hashCode(), getExpressions());
}
@Override
Deleted: trunk/engine/src/main/java/org/teiid/query/sql/symbol/ArrayValue.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/ArrayValue.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/ArrayValue.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -1,102 +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 org.teiid.query.sql.symbol;
-
-import java.io.Serializable;
-import java.util.Arrays;
-
-import org.teiid.query.sql.visitor.SQLStringVisitor;
-
-public class ArrayValue implements Comparable<ArrayValue>, Serializable {
- private static final long serialVersionUID = 517794153664734815L;
- private Object[] values;
-
- @SuppressWarnings("serial")
- public final static class NullException extends RuntimeException {};
- private final static NullException ex = new NullException();
-
- public ArrayValue(Object[] values) {
- this.values = values;
- }
-
- @Override
- public int compareTo(ArrayValue o) {
- return compareTo(o, false);
- }
-
- public int compareTo(ArrayValue o, boolean noNulls) {
- int len1 = values.length;
- int len2 = o.values.length;
- int lim = Math.min(len1, len2);
- for (int k = 0; k < lim; k++) {
- Object object1 = values[k];
- Object object2 = o.values[k];
- if (object1 == null) {
- if (noNulls) {
- throw ex;
- }
- if (object2 != null) {
- return -1;
- }
- continue;
- } else if (object2 == null) {
- if (noNulls) {
- throw ex;
- }
- return 1;
- }
- int comp = Constant.COMPARATOR.compare(object1, object2);
- if (comp != 0) {
- return comp;
- }
- }
- return len1 - len2;
- }
-
- @Override
- public int hashCode() {
- return Arrays.hashCode(values);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof ArrayValue)) {
- return false;
- }
- ArrayValue other = (ArrayValue)obj;
- return Arrays.equals(values, other.values);
- }
-
- public Object[] getValues() {
- return values;
- }
-
- @Override
- public String toString() {
- return SQLStringVisitor.getSQLString(new Constant(this));
- }
-
-}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -30,6 +30,7 @@
import java.util.List;
import java.util.Map;
+import org.teiid.core.types.ArrayImpl;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.StringUtil;
import org.teiid.language.SQLConstants;
@@ -1155,8 +1156,8 @@
constantParts = new String[] {"null"}; //$NON-NLS-1$
}
} else {
- if (value.getClass() == ArrayValue.class) {
- ArrayValue av = (ArrayValue)value;
+ if (value.getClass() == ArrayImpl.class) {
+ ArrayImpl av = (ArrayImpl)value;
append(Tokens.LPAREN);
for (int i = 0; i < av.getValues().length; i++) {
if (i > 0) {
Modified: trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -47,6 +47,7 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidException;
import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.ArrayImpl;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.language.SQLConstants;
@@ -373,8 +374,8 @@
Object evaluatedValue = Evaluator.evaluate(param.getExpression());
if(evaluatedValue == null) {
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0055",
param.getParameterSymbol()), param.getParameterSymbol()); //$NON-NLS-1$
- } else if (evaluatedValue instanceof ArrayValue &&
getMetadata().isVariadic(param.getMetadataID())) {
- ArrayValue av = (ArrayValue)evaluatedValue;
+ } else if (evaluatedValue instanceof ArrayImpl &&
getMetadata().isVariadic(param.getMetadataID())) {
+ ArrayImpl av = (ArrayImpl)evaluatedValue;
for (Object o : av.getValues()) {
if (o == null) {
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0055",
param.getParameterSymbol()), param.getParameterSymbol()); //$NON-NLS-1$
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-08-31 18:16:59
UTC (rev 4387)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-08-31 18:45:31
UTC (rev 4388)
@@ -3692,6 +3692,7 @@
QueryCommand subquery = null;
Integer index = null;
Expression condition = null;
+ Expression indexExpr = null;
}
{
(
@@ -3721,7 +3722,7 @@
return new Constant(normalizeStringLiteral(symbolImage));
}
} | symbol=nonReserved())
- (<LSBRACE> index = intVal() <RSBRACE>)?
+ (<LSBRACE> indexExpr = commonValueExpression(info) <RSBRACE>)?
)
|
LOOKAHEAD(subquery(info)) subquery = subquery(info)
@@ -3729,7 +3730,7 @@
( <LPAREN>
expression = expression(info)
<RPAREN>
- (<LSBRACE> index = intVal() <RSBRACE>)?
+ (<LSBRACE> indexExpr = commonValueExpression(info) <RSBRACE>)?
)
|
// Searched CASE expressions
@@ -3748,8 +3749,8 @@
if (condition != null) {
((AggregateSymbol)expression).setCondition(condition);
}
- if (index != null) {
- expression = new Function("array_get", new Expression[] {expression, new
Constant(index)});
+ if (indexExpr != null) {
+ expression = new Function("array_get", new Expression[] {expression,
indexExpr});
}
return expression;
}
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-08-31 18:16:59
UTC (rev 4387)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-08-31 18:45:31
UTC (rev 4388)
@@ -902,7 +902,6 @@
TEIID30561=The multisource plan must execute a procedure returning parameter values
exactly 1: {0}
TEIID30546=Unknown log level: {0}, expected one of {1}
-TEIID30415=Array index out of range: {0}
TEIID30190=Could not convert value for column: {0}
TEIID30116={0} is not a valid view.
Modified:
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -174,6 +174,14 @@
helpCheckNumericAttributes(response, 2, 22, 20, 0);
helpCheckNumericAttributes(response, 3, 22, 20, 0);
}
+
+ @Test public void testArrayAgg() throws Exception {
+ QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
+ String sql = "SELECT array_agg(e1) FROM pm1.g2"; //$NON-NLS-1$
+
+ MetadataResult response = helpTestQuery(metadata, sql,
RealMetadataFactory.example1VDB());
+ assertEquals("string[]",
response.getColumnMetadata()[0].get(ResultsMetadataConstants.DATA_TYPE));
+ }
@Test public void testWindowFunction() throws Exception {
QueryMetadataInterface metadata =
TestMetaDataProcessor.examplePrivatePhysicalModel();
Modified:
trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -35,6 +35,7 @@
import org.teiid.UserDefinedAggregate;
import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.common.buffer.impl.BufferManagerImpl;
+import org.teiid.core.types.ArrayImpl;
import org.teiid.core.types.DataTypeManager;
import org.teiid.metadata.AggregateAttributes;
import org.teiid.metadata.FunctionMethod;
@@ -415,8 +416,8 @@
// Create expected results
List[] expected = new List[] {
- Arrays.asList((Object)new Integer[] {1, 0, 0, 2}),
- Arrays.asList((Object)new Integer[] {3, 1}),
+ Arrays.asList(new ArrayImpl(new Integer[] {1, 0, 0, 2})),
+ Arrays.asList(new ArrayImpl(new Integer[] {3, 1})),
};
// Construct data manager with data
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestArrayTable.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestArrayTable.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestArrayTable.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -65,10 +65,13 @@
process(sql, expected);
}
- @Test(expected=TeiidProcessingException.class) public void testCorrelatedTextTable3()
throws Exception {
+ @Test public void testCorrelatedTextTable3() throws Exception {
String sql = "select x.* from bqt1.smalla, arraytable(objectvalue COLUMNS x
string, y integer, z integer, aa object) x"; //$NON-NLS-1$
- List[] expected = new List[] {};
+ List[] expected = new List[] {
+ Arrays.asList("a", 1, 2, null),
+ Arrays.asList("b", 3, 6, null),
+ };
process(sql, expected);
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -321,10 +321,7 @@
compareDocuments((String)expectedResults[i].get(0), actualDoc);
continue;
}
- } else if (cellValue instanceof Object[]) {
- assertArrayEquals((Object[])expectedResults[i].get(0),
(Object[])cellValue);
- continue;
- }
+ }
}
assertEquals("Row " + i + " does not match expected: ",
expectedResults[i], record); //$NON-NLS-1$ //$NON-NLS-2$
Modified:
trunk/engine/src/test/java/org/teiid/query/processor/eval/TestExpressionEvaluator.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/eval/TestExpressionEvaluator.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/engine/src/test/java/org/teiid/query/processor/eval/TestExpressionEvaluator.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -480,8 +480,8 @@
}
@Test public void testArrayEquality() throws Exception {
- assertEquals(Boolean.TRUE, Evaluator.evaluate(new CompareCriteria(new
Array(Arrays.asList((Expression)new Constant(1))), CompareCriteria.EQ, new
Array(Arrays.asList((Expression)new Constant(1))))));
- assertNull(new Evaluator(null, null, null).evaluateTVL(new CompareCriteria(new
Array(Arrays.asList((Expression)new Constant(1))), CompareCriteria.EQ, new
Array(Arrays.asList((Expression)new Constant(null)))), null));
+ assertEquals(Boolean.TRUE, Evaluator.evaluate(new CompareCriteria(new
Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression)new
Constant(1))), CompareCriteria.EQ, new Array(DataTypeManager.DefaultDataClasses.INTEGER,
Arrays.asList((Expression)new Constant(1))))));
+ assertNull(new Evaluator(null, null, null).evaluateTVL(new CompareCriteria(new
Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression)new
Constant(1))), CompareCriteria.EQ, new Array(DataTypeManager.DefaultDataClasses.INTEGER,
Arrays.asList((Expression)new Constant(null)))), null));
}
}
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -2913,5 +2913,15 @@
@Test public void testImplicitTempTableWithExplicitColumns() {
helpResolve("insert into #temp(x, y) select e1, e2 from pm1.g1");
}
+
+ @Test public void testArrayCase() {
+ Command c = helpResolve("select case when e1 is null then array_agg(e4) when e2
is null then array_agg(e4+1) end from pm1.g1 group by e1, e2");
+ assertTrue(c.getProjectedSymbols().get(0).getType().isArray());
+ }
+
+ @Test public void testArrayCase1() {
+ Command c = helpResolve("select case when e1 is null then array_agg(e1) when e2
is null then array_agg(e4+1) end from pm1.g1 group by e1, e2");
+ assertTrue(c.getProjectedSymbols().get(0).getType().isArray());
+ }
}
\ No newline at end of file
Modified: trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestArray.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestArray.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestArray.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -35,6 +35,7 @@
import org.junit.Test;
import org.teiid.client.BatchSerializer;
import org.teiid.common.buffer.TupleBuffer;
+import org.teiid.core.types.ArrayImpl;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.query.sql.visitor.SQLStringVisitor;
@@ -43,17 +44,17 @@
public class TestArray {
@Test public void testArrayValueCompare() {
- ArrayValue a1 = new ArrayValue(new Object[] {1, 2, 3});
+ ArrayImpl a1 = new ArrayImpl(new Object[] {1, 2, 3});
UnitTestUtil.helpTestEquivalence(0, a1, a1);
- ArrayValue a2 = new ArrayValue(new Object[] {1, 2});
+ ArrayImpl a2 = new ArrayImpl(new Object[] {1, 2});
UnitTestUtil.helpTestEquivalence(1, a1, a2);
}
@Test public void testArrayValueToString() {
- ArrayValue a1 = new ArrayValue(new Object[] {1, "x'2", 3});
+ ArrayImpl a1 = new ArrayImpl(new Object[] {1, "x'2", 3});
assertEquals("(1, 'x''2', 3)",
SQLStringVisitor.getSQLString(new Constant(a1)));
}
@@ -64,11 +65,12 @@
Array a1 = array.clone();
assertNotSame(a1, array);
+ assertEquals(a1, array);
assertNotSame(a1.getExpressions().get(0), array.getExpressions().get(0));
}
@Test public void testArrayValueSerialization() throws Exception {
- ArrayValue a1 = new ArrayValue(new Integer[] {1, 2, 3});
+ ArrayImpl a1 = new ArrayImpl(new Integer[] {1, 2, 3});
String[] types = TupleBuffer.getTypeNames(Arrays.asList(new Array(Integer.class,
null)));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
@@ -80,4 +82,18 @@
assertEquals(a1, batch.get(0).get(0));
}
+ @Test public void testZeroBasedArray() throws Exception {
+ ArrayImpl a1 = new ArrayImpl(new Integer[] {1, 2, 3});
+ a1.setZeroBased(true);
+ assertEquals(2, java.lang.reflect.Array.get(a1.getArray(1, 1), 0));
+ }
+
+ /**
+ * This is for compatibility with array_get
+ * @throws Exception
+ */
+ @Test(expected=IndexOutOfBoundsException.class) public void testIndexOutOfBounds()
throws Exception {
+ ArrayImpl a1 = new ArrayImpl(new Integer[] {1, 2, 3});
+ a1.getArray(-1, 1);
+ }
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/PgCatalogMetadataStore.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/PgCatalogMetadataStore.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/runtime/src/main/java/org/teiid/deployers/PgCatalogMetadataStore.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -21,11 +21,14 @@
*/
package org.teiid.deployers;
+import static org.teiid.odbc.PGUtil.*;
+
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Map;
import java.util.Properties;
+import org.teiid.core.types.ArrayImpl;
import org.teiid.core.types.DataTypeManager;
import org.teiid.metadata.Column;
import org.teiid.metadata.Datatype;
@@ -35,14 +38,11 @@
import org.teiid.metadata.FunctionMethod.PushDown;
import org.teiid.metadata.Table.Type;
import org.teiid.odbc.ODBCServerRemoteImpl;
+import org.teiid.query.resolver.util.ResolverVisitor;
import org.teiid.translator.TranslatorException;
public class PgCatalogMetadataStore extends MetadataFactory {
private static final long serialVersionUID = 2158418324376966987L;
- public static final int PG_TYPE_OIDVECTOR = 30;
- public static final int PG_TYPE_OIDARRAY = 1028;
- public static final int PG_TYPE_CHARARRAY = 1002;
- public static final int PG_TYPE_TEXTARRAY = 1009;
public PgCatalogMetadataStore(String modelName, Map<String, Datatype> dataTypes)
throws TranslatorException {
super(modelName, 1, modelName, dataTypes, new Properties(), null);
@@ -62,6 +62,8 @@
addFunction("hasPerm", "has_function_privilege"); //$NON-NLS-1$
//$NON-NLS-2$
addFunction("getExpr2", "pg_get_expr"); //$NON-NLS-1$
//$NON-NLS-2$
addFunction("getExpr3", "pg_get_expr"); //$NON-NLS-1$
//$NON-NLS-2$
+ FunctionMethod func = addFunction("asPGVector", "asPGVector");
//$NON-NLS-1$ //$NON-NLS-2$
+ func.setProperty(ResolverVisitor.TEIID_PASS_THROUGH_TYPE, Boolean.TRUE.toString());
}
private Table createView(String name) throws TranslatorException {
@@ -213,7 +215,8 @@
// The OID of the pg_class entry for this index
addColumn("indexrelid", DataTypeManager.DefaultDataTypes.INTEGER, t);
//$NON-NLS-1$
// The OID of the pg_class entry for the table this index is for
- addColumn("indrelid", DataTypeManager.DefaultDataTypes.INTEGER, t);
//$NON-NLS-1$
+ addColumn("indrelid", DataTypeManager.DefaultDataTypes.INTEGER, t);
//$NON-NLS-1$
+ addColumn("indnatts", DataTypeManager.DefaultDataTypes.SHORT, t);
//$NON-NLS-1$
// If true, the table was last clustered on this index
addColumn("indisclustered", DataTypeManager.DefaultDataTypes.BOOLEAN, t);
//$NON-NLS-1$
// If true, this is a unique index
@@ -224,20 +227,24 @@
// column references. This is a list with one element for each zero entry in indkey.
// NULL if all index attributes are simple references
addColumn("indexprs", DataTypeManager.DefaultDataTypes.STRING, t);
//$NON-NLS-1$
+
// This is an array of indnatts values that indicate which table columns this index
indexes.
- addColumn("indkey", DataTypeManager.DefaultDataTypes.STRING, t);
//$NON-NLS-1$
+ Column c = addColumn("indkey", DataTypeManager.DefaultDataTypes.STRING, t);
//$NON-NLS-1$
+ c.setRuntimeType(DataTypeManager.getDataTypeName(DataTypeManager.getArrayType(DataTypeManager.DefaultDataClasses.SHORT)));
+ c.setProperty("pg_type:oid", String.valueOf(PG_TYPE_INT2VECTOR));
//$NON-NLS-1$
addPrimaryKey("pk_pg_index", Arrays.asList("oid"), t);
//$NON-NLS-1$ //$NON-NLS-2$
- String transformation = "SELECT t1.OID as oid, " + //$NON-NLS-1$
- "t1.OID as indexrelid, " + //$NON-NLS-1$
+ String transformation = "SELECT min(t1.OID) as oid, " + //$NON-NLS-1$
+ "min(t1.OID) as indexrelid, " + //$NON-NLS-1$
"(SELECT OID FROM SYS.Tables WHERE SchemaName = t1.SchemaName AND Name =
t1.TableName) as indrelid, " + //$NON-NLS-1$
+ "cast(count(t1.OID) as short) as indnatts, " + //$NON-NLS-1$
"false indisclustered, " + //$NON-NLS-1$
"(CASE t1.KeyType WHEN 'Unique' THEN true ELSE false END) as
indisunique, " + //$NON-NLS-1$
"(CASE t1.KeyType WHEN 'Primary' THEN true ELSE false END) as
indisprimary, " + //$NON-NLS-1$
- "'' as indexprs, " + //$NON-NLS-1$
- "'0' as indkey " + //$NON-NLS-1$
- "FROM SYS.KeyColumns as t1"; //$NON-NLS-1$
+ "'' as indexprs, asPGVector(" + //$NON-NLS-1$
+ arrayAgg("(select at.attnum FROM pg_attribute as at WHERE at.attname = t1.Name
AND at.attrelid = (SELECT OID FROM SYS.Tables WHERE SchemaName = t1.SchemaName AND Name =
t1.TableName))", "t1.position") +") as indkey " + //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+ "FROM SYS.KeyColumns as t1 GROUP BY t1.uid, t1.KeyType, t1.SchemaName,
t1.TableName, t1.Name"; //$NON-NLS-1$
t.setSelectTransformation(transformation);
t.setMaterialized(true);
return t;
@@ -277,15 +284,20 @@
Column c = addColumn("proargtypes", DataTypeManager.DefaultDataTypes.OBJECT,
t); //$NON-NLS-1$
c.setProperty("pg_type:oid", String.valueOf(PG_TYPE_OIDVECTOR));
//$NON-NLS-1$
+ c.setRuntimeType(DataTypeManager.getDataTypeName(DataTypeManager.getArrayType(DataTypeManager.DefaultDataClasses.INTEGER)));
c = addColumn("proargnames", DataTypeManager.DefaultDataTypes.OBJECT, t);
//$NON-NLS-1$
c.setProperty("pg_type:oid", String.valueOf(PG_TYPE_TEXTARRAY));
//$NON-NLS-1$
+ c.setRuntimeType(DataTypeManager.getDataTypeName(DataTypeManager.getArrayType(DataTypeManager.DefaultDataClasses.STRING)));
c = addColumn("proargmodes", DataTypeManager.DefaultDataTypes.OBJECT, t);
//$NON-NLS-1$
c.setProperty("pg_type:oid", String.valueOf(PG_TYPE_CHARARRAY));
//$NON-NLS-1$
+ //TODO: we don't yet understand that we can cast from string[] to char[]
+ c.setRuntimeType(DataTypeManager.getDataTypeName(DataTypeManager.getArrayType(DataTypeManager.DefaultDataClasses.CHAR)));
c = addColumn("proallargtypes", DataTypeManager.DefaultDataTypes.OBJECT, t);
//$NON-NLS-1$
c.setProperty("pg_type:oid", String.valueOf(PG_TYPE_OIDARRAY));
//$NON-NLS-1$
+ c.setRuntimeType(DataTypeManager.getDataTypeName(DataTypeManager.getArrayType(DataTypeManager.DefaultDataClasses.INTEGER)));
// The OID of the namespace that contains this function
addColumn("pronamespace", DataTypeManager.DefaultDataTypes.INTEGER, t);
//$NON-NLS-1$
@@ -296,9 +308,9 @@
String transformation = "SELECT t1.OID as oid, t1.Name as proname, (SELECT (CASE
WHEN count(pp.Type)>0 THEN true else false END) as x FROM ProcedureParams pp WHERE
pp.ProcedureName = t1.Name AND pp.SchemaName = t1.SchemaName and
pp.Type='ResultSet') as proretset, " + //$NON-NLS-1$
"CASE WHEN (SELECT count(dt.oid) FROM ProcedureParams pp, matpg_datatype dt WHERE
pp.ProcedureName = t1.Name AND pp.SchemaName = t1.SchemaName AND pp.Type IN
('ReturnValue', 'ResultSet') AND dt.Name = pp.DataType) IS NULL THEN
(select oid from pg_type WHERE typname = 'void') WHEN (SELECT count(dt.oid) FROM
ProcedureParams pp, matpg_datatype dt WHERE pp.ProcedureName = t1.Name AND pp.SchemaName =
t1.SchemaName AND pp.Type = 'ResultSet' AND dt.Name = pp.DataType) IS NOT NULL
THEN (select oid from pg_type WHERE typname = 'record') ELSE (SELECT dt.oid FROM
ProcedureParams pp, matpg_datatype dt WHERE pp.ProcedureName = t1.Name AND pp.SchemaName =
t1.SchemaName AND pp.Type = 'ReturnValue' AND dt.Name = pp.DataType) END as
prorettype, " + //$NON-NLS-1$
"convert((SELECT count(*) FROM ProcedureParams pp WHERE pp.ProcedureName = t1.Name
AND pp.SchemaName = t1.SchemaName AND pp.Type IN ('In', 'InOut')), short)
as pronargs, " + //$NON-NLS-1$
- "(select "+arrayAgg("y.oid","y.type, y.position" )+"
FROM ("+paramTable("'ResultSet','ReturnValue',
'Out'")+") as y) as proargtypes, " +//$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+ "asPGVector((select "+arrayAgg("y.oid","y.type,
y.position" )+" FROM
("+paramTable("'ResultSet','ReturnValue',
'Out'")+") as y)) as proargtypes, " +//$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
"(select "+arrayAgg("y.name", "y.type,
y.position")+" FROM (SELECT pp.Name as name, pp.position as position, pp.Type as
type FROM ProcedureParams pp WHERE pp.ProcedureName = t1.Name AND pp.SchemaName =
t1.SchemaName AND pp.Type NOT IN ('ReturnValue' )) as y) as proargnames, " +
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- "(select case WHEN count(distinct(y.type)) = 1 THEN null ELSE
"+arrayAgg("CASE WHEN (y.type ='In') THEN 'i' WHEN (y.type =
'Out') THEN 'o' WHEN (y.type = 'InOut') THEN 'b' WHEN
(y.type = 'ResultSet') THEN 't' END",
"y.type,y.position")+" END FROM (SELECT pp.Type as type, pp.Position as
position FROM ProcedureParams pp WHERE pp.ProcedureName = t1.Name AND pp.SchemaName =
t1.SchemaName AND pp.Type NOT IN ('ReturnValue')) as y) as proargmodes, " +
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ "(select case WHEN count(distinct(y.type)) = 1 THEN null ELSE
"+arrayAgg("CASE WHEN (y.type ='In') THEN cast('i' as char) WHEN
(y.type = 'Out') THEN cast('o' as char) WHEN (y.type = 'InOut')
THEN cast('b' as char) WHEN (y.type = 'ResultSet') THEN cast('t'
as char) END", "y.type,y.position")+" END FROM (SELECT pp.Type as
type, pp.Position as position FROM ProcedureParams pp WHERE pp.ProcedureName = t1.Name AND
pp.SchemaName = t1.SchemaName AND pp.Type NOT IN ('ReturnValue')) as y) as
proargmodes, " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"(select case WHEN count(distinct(y.oid)) = 1 THEN null ELSE
"+arrayAgg("y.oid", "y.type, y.position")+" END FROM
("+paramTable("'ReturnValue'")+") as y) as proallargtypes,
" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
//$NON-NLS-6$
"(SELECT OID FROM SYS.Schemas WHERE Name = t1.SchemaName) as pronamespace " +
//$NON-NLS-1$
"FROM SYS.Procedures as t1";//$NON-NLS-1$
@@ -408,9 +420,11 @@
"1182,_date,-1,b,0,-1,0,1082\n" + //$NON-NLS-1$
"1183,_time,-1,b,0,-1,0,1083\n" + //$NON-NLS-1$
"2287,_record,-1,b,0,-1,0,2249\n" + //$NON-NLS-1$
- "2283,anyelement,4,p,0,-1,0,0" + //$NON-NLS-1$
+ "2283,anyelement,4,p,0,-1,0,0\n" + //$NON-NLS-1$
+ "22,int2vector,-1,b,0,-1,0,0" + //$NON-NLS-1$
"' columns oid integer, typname string, typlen short, typtype char,
typbasetype integer, typtypmod integer, typrelid integer, typelem integer) AS t";
//$NON-NLS-1$
- t.setSelectTransformation(transformation);
+ t.setSelectTransformation(transformation);
+ t.setMaterialized(true);
return t;
}
@@ -540,5 +554,12 @@
@SuppressWarnings("unused") Boolean prettyPrint) {
return text;
}
+
+ public static Object asPGVector(Object obj) {
+ if (obj instanceof ArrayImpl) {
+ ((ArrayImpl)obj).setZeroBased(true);
+ }
+ return obj;
+ }
}
}
Modified: trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -599,7 +599,9 @@
// this call resolution is ambiguous
return "SELECT ''"; //$NON-NLS-1$
}
-
+ else if (sql.equals("SELECT typinput='array_in'::regproc, typtype FROM
pg_catalog.pg_type WHERE typname = $1")) { //$NON-NLS-1$
+ return "SELECT substring(typname,1,1) = '_', typtype FROM
pg_catalog.pg_type WHERE typname = ?"; //$NON-NLS-1$
+ }
}
else if (sql.equalsIgnoreCase("show max_identifier_length")){ //$NON-NLS-1$
return "select 63"; //$NON-NLS-1$
Modified: trunk/runtime/src/main/java/org/teiid/odbc/PGUtil.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/odbc/PGUtil.java 2012-08-31 18:16:59 UTC (rev
4387)
+++ trunk/runtime/src/main/java/org/teiid/odbc/PGUtil.java 2012-08-31 18:45:31 UTC (rev
4388)
@@ -23,8 +23,6 @@
import java.sql.Types;
-import org.teiid.deployers.PgCatalogMetadataStore;
-
public class PGUtil {
public static final int PG_TYPE_VARCHAR = 1043;
@@ -41,10 +39,11 @@
public static final int PG_TYPE_FLOAT8 = 701;
public static final int PG_TYPE_UNKNOWN = 705;
- public static final int PG_TYPE_OIDVECTOR = PgCatalogMetadataStore.PG_TYPE_OIDVECTOR;
- public static final int PG_TYPE_OIDARRAY = PgCatalogMetadataStore.PG_TYPE_OIDARRAY;
- public static final int PG_TYPE_CHARARRAY = PgCatalogMetadataStore.PG_TYPE_CHARARRAY;
- public static final int PG_TYPE_TEXTARRAY = PgCatalogMetadataStore.PG_TYPE_TEXTARRAY;
+ public static final int PG_TYPE_OIDVECTOR = 30;
+ public static final int PG_TYPE_INT2VECTOR = 22;
+ public static final int PG_TYPE_OIDARRAY = 1028;
+ public static final int PG_TYPE_CHARARRAY = 1002;
+ public static final int PG_TYPE_TEXTARRAY = 1009;
public static final int PG_TYPE_DATE = 1082;
public static final int PG_TYPE_TIME = 1083;
Modified: trunk/runtime/src/main/java/org/teiid/transport/PgBackendProtocol.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/PgBackendProtocol.java 2012-08-31
18:16:59 UTC (rev 4387)
+++ trunk/runtime/src/main/java/org/teiid/transport/PgBackendProtocol.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -53,6 +53,7 @@
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.ssl.SslHandler;
import org.teiid.client.util.ResultsFuture;
+import org.teiid.core.types.ArrayImpl;
import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.ReflectionHelper;
import org.teiid.core.util.SqlUtil;
@@ -514,11 +515,11 @@
case PG_TYPE_TEXTARRAY:
case PG_TYPE_OIDARRAY:
{
- Object[] obj = (Object[])rs.getObject(column);
+ ArrayImpl obj = (ArrayImpl)rs.getObject(column);
if (obj != null) {
writer.append("{");
boolean first = true;
- for (Object o:obj) {
+ for (Object o:obj.getValues()) {
if (!first) {
writer.append(",");
}
@@ -538,13 +539,13 @@
}
}
break;
-
+ case PG_TYPE_INT2VECTOR:
case PG_TYPE_OIDVECTOR:
{
- Object[] obj = (Object[])rs.getObject(column);
+ ArrayImpl obj = (ArrayImpl)rs.getObject(column);
if (obj != null) {
boolean first = true;
- for (Object o:obj) {
+ for (Object o:obj.getValues()) {
if (!first) {
writer.append(" ");
}
Modified:
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestODBCProceduresSchema.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestODBCProceduresSchema.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestODBCProceduresSchema.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -23,6 +23,8 @@
import static org.junit.Assert.*;
+import java.sql.Array;
+
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -30,6 +32,7 @@
import org.teiid.core.util.UnitTestUtil;
import org.teiid.jdbc.AbstractMMQueryTestCase;
import org.teiid.jdbc.FakeServer;
+import org.teiid.jdbc.TestMMDatabaseMetaData;
@SuppressWarnings("nls")
public class TestODBCProceduresSchema extends AbstractMMQueryTestCase {
@@ -63,10 +66,10 @@
assertEquals(true, this.internalResultSet.getBoolean(3)); //proretset
assertEquals(2249, this.internalResultSet.getInt(4)); //prorettype
assertEquals(14, this.internalResultSet.getInt(5)); //pronargs
- assertArrayEquals(new Object[]
{1700,1043,700,20,701,21,1082,1083,1114,16,1043,21,1700,1700},
(Object[])this.internalResultSet.getObject(6)); //proargtypes
- assertArrayEquals(new Object[]
{"intNum","stringNum","floatNum","longNum","doubleNum","byteNum","dateValue","timeValue","timestampValue","booValue","charValue","shortNum","bigIntNum","bigdecimalNum","col","col2"},
(Object[])this.internalResultSet.getObject(7)); //proargnames
- assertArrayEquals(new Object[]
{"i","i","i","i","i","i","i","i","i","i","i","i","i","i","t","t"},
(Object[])this.internalResultSet.getObject(8)); //proargmodes
- assertArrayEquals(new Object[]
{1700,1043,700,20,701,21,1082,1083,1114,16,1043,21,1700,1700,1043,1700},
(Object[])this.internalResultSet.getObject(9)); //proallargtypes
+ assertArrayEquals(new Object[]
{1700,1043,700,20,701,21,1082,1083,1114,16,1043,21,1700,1700},
(Object[])((Array)this.internalResultSet.getObject(6)).getArray()); //proargtypes
+ assertArrayEquals(new Object[]
{"intNum","stringNum","floatNum","longNum","doubleNum","byteNum","dateValue","timeValue","timestampValue","booValue","charValue","shortNum","bigIntNum","bigdecimalNum","col","col2"},
(Object[])((Array)this.internalResultSet.getObject(7)).getArray()); //proargnames
+ assertArrayEquals(new Object[]
{'i','i','i','i','i','i','i','i','i','i','i','i','i','i','t','t'},
(Object[])((Array)this.internalResultSet.getObject(8)).getArray()); //proargmodes
+ assertArrayEquals(new Object[]
{1700,1043,700,20,701,21,1082,1083,1114,16,1043,21,1700,1700,1043,1700},
(Object[])((Array)this.internalResultSet.getObject(9)).getArray()); //proallargtypes
assertEquals(1, this.internalResultSet.getInt(10)); //pronamespace
}
@@ -78,10 +81,10 @@
assertEquals(false, this.internalResultSet.getBoolean(3)); //proretset
assertEquals(2278, this.internalResultSet.getInt(4)); //prorettype
assertEquals(2, this.internalResultSet.getInt(5)); //pronargs
- assertArrayEquals(new Object[] {1700,1043},
(Object[])this.internalResultSet.getObject(6)); //proargtypes
- assertArrayEquals(new Object[] {"intNum","stringNum"},
(Object[])this.internalResultSet.getObject(7)); //proargnames
- assertArrayEquals(null, (Object[])this.internalResultSet.getObject(8)); //proargmodes
- assertArrayEquals(new Object[] {1700,1043},
(Object[])this.internalResultSet.getObject(9)); //proallargtypes
+ assertArrayEquals(new Object[] {1700,1043},
(Object[])((Array)this.internalResultSet.getObject(6)).getArray()); //proargtypes
+ assertArrayEquals(new Object[] {"intNum","stringNum"},
(Object[])((Array)this.internalResultSet.getObject(7)).getArray()); //proargnames
+ assertNull(this.internalResultSet.getObject(8)); //proargmodes
+ assertArrayEquals(new Object[] {1700,1043},
(Object[])((Array)this.internalResultSet.getObject(9)).getArray()); //proallargtypes
assertEquals(1, this.internalResultSet.getInt(10)); //pronamespace
}
@@ -93,25 +96,15 @@
assertEquals(false, this.internalResultSet.getBoolean(3)); //proretset
assertEquals(20, this.internalResultSet.getInt(4)); //prorettype
assertEquals(3, this.internalResultSet.getInt(5)); //pronargs
- assertArrayEquals(new Object[] {1700,1043,700},
(Object[])this.internalResultSet.getObject(6)); //proargtypes
- assertArrayEquals(new Object[]
{"intNum","stringNum","floatNum"},
(Object[])this.internalResultSet.getObject(7)); //proargnames
- assertArrayEquals(null, (Object[])this.internalResultSet.getObject(8)); //proargmodes
- assertArrayEquals(new Object[] {1700,1043,700},
(Object[])this.internalResultSet.getObject(9)); //proallargtypes
+ assertArrayEquals(new Object[] {1700,1043,700},
(Object[])((Array)this.internalResultSet.getObject(6)).getArray()); //proargtypes
+ assertArrayEquals(new Object[]
{"intNum","stringNum","floatNum"},
(Object[])((Array)this.internalResultSet.getObject(7)).getArray()); //proargnames
+ assertNull(this.internalResultSet.getObject(8)); //proargmodes
+ assertArrayEquals(new Object[] {1700,1043,700},
(Object[])((Array)this.internalResultSet.getObject(9)).getArray()); //proallargtypes
assertEquals(1, this.internalResultSet.getInt(10)); //pronamespace
}
@Test public void test_Pg_Proc_with_return_table() throws Exception {
execute("select oid, proname, proretset,prorettype, pronargs, proargtypes,
proargnames, proargmodes, proallargtypes, pronamespace FROM pg_proc where
proname='ProcedureReturnTable'"); //$NON-NLS-1$
- assertTrue(this.internalResultSet.next());
- assertEquals(2, this.internalResultSet.getInt(1)); //oid
- assertEquals("ProcedureReturnTable", this.internalResultSet.getString(2));
//proname
- assertEquals(true, this.internalResultSet.getBoolean(3)); //proretset
- assertEquals(2249, this.internalResultSet.getInt(4)); //prorettype
- assertEquals(2, this.internalResultSet.getInt(5)); //pronargs
- assertArrayEquals(new Object[] {1700,1700},
(Object[])this.internalResultSet.getObject(6)); //proargtypes
- assertArrayEquals(new Object[]
{"intNum","bigDecimalNum","col1","col2"},
(Object[])this.internalResultSet.getObject(7)); //proargnames
- assertArrayEquals(new Object[]
{"i","i","t","t"},
(Object[])this.internalResultSet.getObject(8)); //proargmodes
- assertArrayEquals(new Object[] {1700,1700,1043,1114},
(Object[])this.internalResultSet.getObject(9)); //proallargtypes
- assertEquals(1, this.internalResultSet.getInt(10)); //pronamespace
+ TestMMDatabaseMetaData.compareResultSet(this.internalResultSet);
}
}
Modified:
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestODBCSchema.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestODBCSchema.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestODBCSchema.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -75,6 +75,11 @@
TestMMDatabaseMetaData.compareResultSet(this.internalResultSet);
}
+ @Test public void testOBIEEColumnQuery() throws Exception {
+ execute("select ta.attname, ia.attnum, ic.relname, n.nspname, tc.relname from
pg_catalog.pg_attribute ta, pg_catalog.pg_attribute ia, pg_catalog.pg_class tc,
pg_catalog.pg_index i, pg_catalog.pg_namespace n, pg_catalog.pg_class ic where tc.oid =
i.indrelid AND n.oid = tc.relnamespace AND i.indisprimary = 't' AND ia.attrelid =
i.indexrelid AND ta.attrelid = i.indrelid AND ta.attnum = i.indkey[ia.attnum-1] AND (NOT
ta.attisdropped) AND (NOT ia.attisdropped) AND ic.oid = i.indexrelid order by
ia.attnum");
+ TestMMDatabaseMetaData.compareResultSet(this.internalResultSet);
+ }
+
@Test public void testOIDUniquness() throws Exception {
for (String table : new String[] {"Tables", "Columns",
"Schemas", "DataTypes", "Keys", "Procedures",
"ProcedureParams", "Properties"}) {
execute("select count(distinct oid), count(*) from SYS."+table);
Modified:
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -266,4 +266,9 @@
assertEquals(cs.getBoolean(1), cs.getBoolean("logged"));
}
+ @Test public void testArrayAggType() throws Exception {
+ String sql = "SELECT array_agg(name) from tables"; //$NON-NLS-1$
+ checkResult("testArrayAggType", sql); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
}
Modified:
trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2012-08-31
18:45:31 UTC (rev 4388)
@@ -306,6 +306,7 @@
ResultSet rs = stmt.executeQuery("select * from pg_proc");
rs.next();
assertEquals("oid", rs.getArray("proargtypes").getBaseTypeName());
+ TestMMDatabaseMetaData.compareResultSet(rs); //compare the rest
}
// this does not work as JDBC always sends the queries in prepared form
@@ -384,4 +385,10 @@
assertTrue(rs.next());
assertEquals("Columns", rs.getString(1));
}
+
+ @Test public void testInt2Vector() throws Exception {
+ Statement s = conn.createStatement();
+ ResultSet rs = s.executeQuery("select indkey FROM pg_index");
+ TestMMDatabaseMetaData.compareResultSet(rs);
+ }
}
Added:
trunk/test-integration/common/src/test/resources/TestODBCProceduresSchema/test_Pg_Proc_with_return_table.expected
===================================================================
---
trunk/test-integration/common/src/test/resources/TestODBCProceduresSchema/test_Pg_Proc_with_return_table.expected
(rev 0)
+++
trunk/test-integration/common/src/test/resources/TestODBCProceduresSchema/test_Pg_Proc_with_return_table.expected 2012-08-31
18:45:31 UTC (rev 4388)
@@ -0,0 +1,15 @@
+integer string boolean
integer short integer[]
string[] char[]
integer[]
integer
+oid proname proretset
prorettype pronargs proargtypes
proargnames proargmodes
proallargtypes
pronamespace
+2 ProcedureReturnTable true
2249 2 [1700, 1700]
[intNum, bigDecimalNum, col1, col2] [i, i, t, t]
[1700, 1700, 1043, 1114]
1
+Row Count : 1
+getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel
getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision
getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable
isReadOnly isSearchable isSigned isWritable
+oid 4 bqt java.lang.Integer oid
integer pg_catalog pg_proc 11 10 0
false false false false 1 true
true true false
+proname 12 bqt java.lang.String proname string
pg_catalog pg_proc 4000 4000 0
false true false false 1 true
true false false
+proretset -7 bqt java.lang.Boolean proretset
boolean pg_catalog pg_proc 5 1 0
false false false false 1 true
true false false
+prorettype 4 bqt java.lang.Integer prorettype
integer pg_catalog pg_proc 11 10 0
false false false false 1 true
true true false
+pronargs 5 bqt java.lang.Short pronargs short
pg_catalog pg_proc 6 5 0
false false false false 1 true
true true false
+proargtypes 2003 bqt java.sql.Array proargtypes
integer[] pg_catalog pg_proc 2147483647 2147483647 0
false false false false 1 true
false false false
+proargnames 2003 bqt java.sql.Array proargnames
string[] pg_catalog pg_proc 2147483647 2147483647 0
false false false false 1 true
false false false
+proargmodes 2003 bqt java.sql.Array proargmodes char[]
pg_catalog pg_proc 2147483647 2147483647 0
false false false false 1 true
false false false
+proallargtypes 2003 bqt java.sql.Array proallargtypes
integer[] pg_catalog pg_proc 2147483647 2147483647 0
false false false false 1 true
false false false
+pronamespace 4 bqt java.lang.Integer pronamespace
integer pg_catalog pg_proc 11 10 0
false false false false 1 true
true true false
Added:
trunk/test-integration/common/src/test/resources/TestODBCSchema/testOBIEEColumnQuery.expected
===================================================================
---
trunk/test-integration/common/src/test/resources/TestODBCSchema/testOBIEEColumnQuery.expected
(rev 0)
+++
trunk/test-integration/common/src/test/resources/TestODBCSchema/testOBIEEColumnQuery.expected 2012-08-31
18:45:31 UTC (rev 4388)
@@ -0,0 +1,24 @@
+string short string
string
string
+attname attnum relname
nspname
relname
+PART_ID 1
PARTSSUPPLIER.PARTS PartsSupplier
PARTSSUPPLIER.PARTS
+SHIPPER_ID 1
PARTSSUPPLIER.SHIP_VIA PartsSupplier
PARTSSUPPLIER.SHIP_VIA
+STATUS_ID 1
PARTSSUPPLIER.STATUS PartsSupplier
PARTSSUPPLIER.STATUS
+SUPPLIER_ID 1
PARTSSUPPLIER.SUPPLIER PartsSupplier
PARTSSUPPLIER.SUPPLIER
+SUPPLIER_ID 1 Columns
PartsSupplier
PARTSSUPPLIER.SUPPLIER_PARTS
+PART_ID 1 DataTypes
PartsSupplier
PARTSSUPPLIER.SUPPLIER_PARTS
+oid 1
ProcedureParams pg_catalog
matpg_datatype
+name 1 Procedures
pg_catalog
matpg_datatype
+attname 1 Schemas
pg_catalog
matpg_relatt
+relname 1 Tables
pg_catalog
matpg_relatt
+nspname 1
VirtualDatabases pg_catalog
matpg_relatt
+oid 1 matpg_datatype
pg_catalog
pg_attribute
+oid 1 matpg_relatt
pg_catalog
pg_class
+oid 1 pg_am
pg_catalog
pg_index
+oid 1 pg_attrdef
pg_catalog
pg_proc
+Row Count : 15
+getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel
getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision
getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable
isReadOnly isSearchable isSigned isWritable
+attname 12 PartsSupplier java.lang.String attname string
pg_catalog pg_attribute 4000 4000 0
false true false false 1 true
true false false
+attnum 5 PartsSupplier java.lang.Short attnum short
pg_catalog pg_attribute 6 5 0
false false false false 1 true
true true false
+relname 12 PartsSupplier java.lang.String relname string
pg_catalog pg_class 4000 4000 0
false true false false 1 true
true false false
+nspname 12 PartsSupplier java.lang.String nspname string
pg_catalog pg_namespace 4000 4000 0
false true false false 1 true
true false false
+relname 12 PartsSupplier java.lang.String relname string
pg_catalog pg_class 4000 4000 0
false true false false 1 true
true false false
Modified:
trunk/test-integration/common/src/test/resources/TestODBCSchema/test_PG_INDEX.expected
===================================================================
---
trunk/test-integration/common/src/test/resources/TestODBCSchema/test_PG_INDEX.expected 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/test-integration/common/src/test/resources/TestODBCSchema/test_PG_INDEX.expected 2012-08-31
18:45:31 UTC (rev 4388)
@@ -1,34 +1,35 @@
-integer integer integer boolean boolean boolean string
string
-oid indexrelid indrelid indisclustered indisunique indisprimary
indexprs indkey
-1 1 1 false false true
0
-2 2 2 false false true
0
-3 3 3 false false true
0
-4 4 4 false false true
0
-5 5 4 false false false
0
-6 6 5 false false true
0
-7 7 5 false false true
0
-8 8 5 false false false
0
-9 9 5 false false false
0
-10 10 19 false false true
0
-11 11 19 false false true
0
-12 12 19 false false false
0
-13 13 19 false false false
0
-14 14 20 false false true
0
-15 15 20 false false true
0
-16 16 20 false false true
0
-17 17 20 false false false
0
-18 18 20 false false false
0
-19 19 23 false false true
0
-20 20 24 false false true
0
-21 21 26 false false true
0
-22 22 28 false false true
0
+integer integer integer short boolean boolean boolean
string short[]
+oid indexrelid indrelid indnatts indisclustered indisunique
indisprimary indexprs indkey
+1 1 1 1 false false true
[1]
+2 2 2 1 false false true
[1]
+3 3 3 1 false false true
[1]
+4 4 4 1 false false true
[1]
+5 5 4 1 false false false
[3]
+6 6 5 1 false false true
[1]
+7 7 5 1 false false true
[2]
+8 8 5 1 false false false
[2]
+9 9 5 1 false false false
[1]
+10 10 19 1 false false true
[1]
+11 11 19 1 false false true
[3]
+12 12 19 1 false false false
[2]
+13 13 19 1 false false false
[1]
+14 14 20 1 false false true
[3]
+15 15 20 1 false false true
[4]
+16 16 20 1 false false true
[5]
+17 17 20 1 false false false
[1]
+18 18 20 1 false false false
[2]
+19 19 23 1 false false true
[1]
+20 20 24 1 false false true
[1]
+21 21 26 1 false false true
[1]
+22 22 28 1 false false true
[1]
Row Count : 22
getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel
getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision
getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable
isReadOnly isSearchable isSigned isWritable
oid 4 PartsSupplier java.lang.Integer oid
integer pg_catalog pg_index 11 10 0
false false false false 1 true
true true false
indexrelid 4 PartsSupplier java.lang.Integer indexrelid
integer pg_catalog pg_index 11 10 0
false false false false 1 true
true true false
indrelid 4 PartsSupplier java.lang.Integer indrelid
integer pg_catalog pg_index 11 10 0
false false false false 1 true
true true false
+indnatts 5 PartsSupplier java.lang.Short indnatts short
pg_catalog pg_index 6 5 0
false false false false 1 true
true true false
indisclustered -7 PartsSupplier java.lang.Boolean indisclustered
boolean pg_catalog pg_index 5 1 0
false false false false 1 true
true false false
indisunique -7 PartsSupplier java.lang.Boolean indisunique
boolean pg_catalog pg_index 5 1 0
false false false false 1 true
true false false
indisprimary -7 PartsSupplier java.lang.Boolean indisprimary
boolean pg_catalog pg_index 5 1 0
false false false false 1 true
true false false
indexprs 12 PartsSupplier java.lang.String indexprs string
pg_catalog pg_index 4000 4000 0
false true false false 1 true
true false false
-indkey 12 PartsSupplier java.lang.String indkey string
pg_catalog pg_index 4000 4000 0
false true false false 1 true
true false false
+indkey 2003 PartsSupplier java.sql.Array indkey
short[] pg_catalog pg_index 2147483647 4000 0
false true false false 1 true
true false false
Added:
trunk/test-integration/common/src/test/resources/TestSystemVirtualModel/testArrayAggType.expected
===================================================================
---
trunk/test-integration/common/src/test/resources/TestSystemVirtualModel/testArrayAggType.expected
(rev 0)
+++
trunk/test-integration/common/src/test/resources/TestSystemVirtualModel/testArrayAggType.expected 2012-08-31
18:45:31 UTC (rev 4388)
@@ -0,0 +1,6 @@
+string[]
+expr1
+[PARTSSUPPLIER.PARTS, PARTSSUPPLIER.SHIP_VIA, PARTSSUPPLIER.STATU$
+Row Count : 1
+getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel
getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision
getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable
isReadOnly isSearchable isSigned isWritable
+expr1 2003 PartsSupplier java.sql.Array expr1
string[] <null> <null> 2147483647 0
0 false false false true 1
false true true true
Modified:
trunk/test-integration/common/src/test/resources/TestSystemVirtualModel/testProperties.expected
===================================================================
---
trunk/test-integration/common/src/test/resources/TestSystemVirtualModel/testProperties.expected 2012-08-31
18:16:59 UTC (rev 4387)
+++
trunk/test-integration/common/src/test/resources/TestSystemVirtualModel/testProperties.expected 2012-08-31
18:45:31 UTC (rev 4388)
@@ -1,10 +1,11 @@
string string
string
integer clob
Name Value
UID
OID ClobValue
-pg_type:oid 30
tid:7ff2755e9621-c69d9997-0000003a
1 Clob[2]
-pg_type:oid 1009
tid:7ff2755e9621-c63e1866-0000003b
2 Clob[4]
-pg_type:oid 1002
tid:7ff2755e9621-c6363c4e-0000003c
3 Clob[4]
-pg_type:oid 1028
tid:7ff2755e9621-f418fbbe-0000003d
4 Clob[4]
-Row Count : 4
+pg_type:oid 22
tid:7ff2755e9621-ef456826-00000030
1 Clob[2]
+pg_type:oid 30
tid:7ff2755e9621-c69d99b6-0000003b
2 Clob[2]
+pg_type:oid 1009
tid:7ff2755e9621-c63e1885-0000003c
3 Clob[4]
+pg_type:oid 1002
tid:7ff2755e9621-c6363c6d-0000003d
4 Clob[4]
+pg_type:oid 1028
tid:7ff2755e9621-f418fbdd-0000003e
5 Clob[4]
+Row Count : 5
getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel
getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision
getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable
isReadOnly isSearchable isSigned isWritable
Name 12 PartsSupplier java.lang.String Name string
SYS Properties 255 255 0
false true false false 0 true
true false false
Value 12 PartsSupplier java.lang.String Value string
SYS Properties 255 255 0
false true false false 0 true
true false false