Skip to content

Commit

Permalink
TEIID-3624 fixing array handling and other corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Feb 21, 2017
1 parent 6e7a96c commit 054d5b2
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 25 deletions.
11 changes: 10 additions & 1 deletion api/src/main/java/org/teiid/metadata/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ public Collection<Grant> getGrants(){
return this.store.getGrants();
}

/**
* Add a domain with the given attributes. The UID must still be set.
* @param name
* @param baseType
* @param precision
* @param scale
* @param notNull
* @return
*/
public Datatype addDomain(String name, String baseType, Integer precision, Integer scale, boolean notNull) {
//TODO: allow named array types
// requires either storing the dimension on the datatype, or using a holder
Expand All @@ -271,7 +280,7 @@ public Datatype addDomain(String name, String baseType, Integer precision, Integ
dataType.setName(name);
dataType.setBasetypeName(baseType);
dataType.setType(Datatype.Type.Domain);
//dataType.setUUID(uuid);
dataType.setUUID(null);

if (precision != null) {
if (!Number.class.isAssignableFrom(DataTypeManager.getDataTypeClass(base.getRuntimeTypeName()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static int getLevel(String level) throws TeiidProcessingException {
static {
PREFIX_MAP.put(DataTypeManager.DefaultDataTypes.STRING, Arrays.asList("'", "'")); //$NON-NLS-1$ //$NON-NLS-2$
PREFIX_MAP.put(DataTypeManager.DefaultDataTypes.CHAR, Arrays.asList("'", "'")); //$NON-NLS-1$ //$NON-NLS-2$
PREFIX_MAP.put(DataTypeManager.DefaultDataTypes.VARBINARY, Arrays.asList("{'X", "'}")); //$NON-NLS-1$ //$NON-NLS-2$
PREFIX_MAP.put(DataTypeManager.DefaultDataTypes.VARBINARY, Arrays.asList("'X", "'")); //$NON-NLS-1$ //$NON-NLS-2$
PREFIX_MAP.put(DataTypeManager.DefaultDataTypes.DATE, Arrays.asList("{'d", "'}")); //$NON-NLS-1$ //$NON-NLS-2$
PREFIX_MAP.put(DataTypeManager.DefaultDataTypes.TIME, Arrays.asList("{'t", "'}")); //$NON-NLS-1$ //$NON-NLS-2$
PREFIX_MAP.put(DataTypeManager.DefaultDataTypes.TIMESTAMP, Arrays.asList("{'ts", "'}")); //$NON-NLS-1$ //$NON-NLS-2$
Expand Down Expand Up @@ -741,7 +741,7 @@ protected void fillRow(List<Object> row, Column column,
row.add(column.getSearchType().toString());
row.add(column.getFormat());
row.add(column.getDefaultValue());
row.add(dt!=null?dt.getJavaClassName():null);
row.add(column.getJavaType().getName());
row.add(column.getPrecision());
row.add(column.getCharOctetLength());
row.add(column.getRadix());
Expand All @@ -757,6 +757,10 @@ protected void fillRow(List<Object> row, Column column,
//so use the runtime type instead
typeName = dt.getRuntimeTypeName();
}
int arrayDimensions = column.getArrayDimensions();
while (arrayDimensions-- > 0) {
typeName += "[]"; //$NON-NLS-1$
}
}
row.add(typeName);
row.add(JDBCSQLTypeInfo.getSQLType(column.getRuntimeType()));
Expand Down
12 changes: 10 additions & 2 deletions engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -4814,6 +4814,7 @@ example=[source,sql]\n----\nSTRING[]\n----\n
*/
ParsedDataType parseDataType() :
{
int arraySuffixes = 0;
ParsedDataType type = null;
Token idToken = null;
}
Expand All @@ -4823,12 +4824,19 @@ ParsedDataType parseDataType() :
return type;
}
|
idToken = <ID>
(idToken = <ID>
{
String id = normalizeId(idToken.image);
id = validateName(id, true);
return new ParsedDataType(id);
type = new ParsedDataType(id);
}
(<LSBRACE><RSBRACE> {arraySuffixes++;})*
{
if (arraySuffixes > 0) {
type.type += StringUtil.join(Collections.nCopies(arraySuffixes, "[]"), "");
}
return type;
})
}

/*
Expand Down
16 changes: 16 additions & 0 deletions runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.math.BigDecimal;
import java.net.InetSocketAddress;
import java.sql.*;
import java.util.ArrayList;
Expand Down Expand Up @@ -2037,6 +2038,10 @@ public boolean isSourceRequiredForMetadata() {
ResultSet rs = c.getMetaData().getColumns(null, null, "g1", null);
rs.next();
assertEquals("x", rs.getString("TYPE_NAME"));
rs.next();
assertEquals("z", rs.getString("TYPE_NAME"));
rs.next();
assertEquals("x[]", rs.getString("TYPE_NAME"));

try {
s.execute("select cast(1 as a)"); //should fail
Expand All @@ -2052,6 +2057,17 @@ public boolean isSourceRequiredForMetadata() {
assertEquals("bigdecimal", rs.getMetaData().getColumnTypeName(1));

s.execute("select xmlcast(xmlparse(document '<a>1</a>') as z)");

s.execute("select attname, atttypid from pg_attribute where attname = 'e1'");
rs = s.getResultSet();
rs.next();
assertEquals(1043, rs.getInt(2)); //varchar

s.execute("select cast((1.0,) as z[])");
rs = s.getResultSet();
rs.next();
assertArrayEquals(new BigDecimal[] {BigDecimal.valueOf(1.0)}, (BigDecimal[])rs.getArray(1).getArray());
assertEquals("bigdecimal[]", rs.getMetaData().getColumnTypeName(1));
}

}
2 changes: 1 addition & 1 deletion runtime/src/test/resources/domains-vdb.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ CREATE DOMAIN x AS string(1000) NOT NULL;
CREATE DOMAIN z AS bigdecimal(10,2) NOT NULL;
CREATE VIRTUAL SCHEMA SchemaA;
SET SCHEMA SchemaA;
CREATE VIEW G1 (e1 x, e2 z) AS SELECT 'a', 1.0;
CREATE VIEW G1 (e1 x, e2 z, e3 x[]) AS SELECT 'a', 1.0, ('b',);
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ <h2><a name="Compatibility">Compatibility Issues</a></h2>

<h4>from 9.2</h4>
<ul>
<li><a href="https://issues.jboss.org/browse/TEIID-4574">TEIID-4574</a> Phoenix/Hbase Translator has been renamed phoenix and the usage of the HBaseExecutionFactory and the hbase translator name has been deprecated.</li>
<li><a href="https://issues.jboss.org/browse/TEIID-3624">TEIID-3624</a> The introduction of domain types modified several of the system tables. The isPhysical column was removed from the SYS.Datatypes table.
SYS.Datatypes added Type, TypeCode, Literal_Prefix, and Literal_Suffix columns. The SYS.Columns table added TypeName, TypeCode, and ColumnSize columns.</li>
</ul>

<h4>from 9.1</h4>
<ul>
<li><a href="https://issues.jboss.org/browse/TEIID-4574">TEIID-4574</a> Phoenix/Hbase Translator has been renamed phoenix and the usage of the HBaseExecutionFactory and the hbase translator name has been deprecated.</li>
<li><a href="https://issues.jboss.org/browse/TEIID-4501">TEIID-4501</a> The salesforce-34 resource adapter defaults to the version 34 api rather than version 22 api.</li>
</ul>

Expand Down
Loading

0 comments on commit 054d5b2

Please sign in to comment.