Skip to content

Commit

Permalink
TEIID-5357: creating a ddl table with two unique columns fails (corre…
Browse files Browse the repository at this point in the history
…cting the auto-naming)
  • Loading branch information
shawkins authored and johnathonlee committed Dec 11, 2018
1 parent 56e1c2d commit 2ca1059
Show file tree
Hide file tree
Showing 22 changed files with 4,713 additions and 16,683 deletions.
12 changes: 12 additions & 0 deletions build/kits/jboss-as7/overlay/docs/teiid/teiid-releasenotes.html
Expand Up @@ -227,6 +227,18 @@ <h4 class="western">from ${project.version}</h4>
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-4476'>TEIID-4476</a> - Upgrade Cassandra Client library (updating cassandra library version)
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-5356'>TEIID-5356</a> - Infer field metadata from the source columns (logic to infer metadata, rather than use defaults for views)
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-5357'>TEIID-5357</a> - creating a ddl table with two unique columns fails (correcting the auto-naming)
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-5359'>TEIID-5359</a> - Resultset metadata defaults to case insensitive (changing the default case sensitive to true)
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-5361'>TEIID-5361</a> - Column metadata with set queries only reflects projected branch (Column metadata with set queries only reflects projected branch)
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-5369'>TEIID-5369</a> - enableDependentJoins for Redshift translator (removing the on commit clause from redshift)
Expand Down
Expand Up @@ -61,7 +61,9 @@
import org.teiid.query.sql.lang.SetQuery;
import org.teiid.query.sql.lang.SetQuery.Operation;
import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.Function;
Expand Down Expand Up @@ -94,8 +96,6 @@ public class MetaDataProcessor {

private boolean useJDBCDefaultPrecision = true;

private boolean useJDBCDefaultPrecision = true;

public MetaDataProcessor(DQPCore requestManager, SessionAwareCache<PreparedPlan> planCache, String vdbName, int vdbVersion) {
this.requestManager = requestManager;
this.planCache = planCache;
Expand Down
2 changes: 1 addition & 1 deletion engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
Expand Up @@ -5450,7 +5450,7 @@ void createColumn(MetadataFactory factory, Table table) :
if (index){
factory.addIndex("INDEX"+table.getIndexes().size(), true, columnName, table);
} else if (unique){
factory.addIndex("UNIQUE"+table.getIndexes().size(), false, columnName, table);
factory.addIndex("UNIQUE"+table.getUniqueKeys().size(), false, columnName, table);
} else if (pk) {
if (table.getPrimaryKey() != null) {
throw new MetadataException(QueryPlugin.Util.getString("SQLParser.pk_exists", table.getName()));
Expand Down
Expand Up @@ -32,14 +32,9 @@
import org.teiid.adminapi.Model;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
<<<<<<< HEAD
import org.teiid.metadata.BaseColumn.NullType;
import org.teiid.metadata.Column;
import org.teiid.metadata.Column.SearchType;
||||||| parent of b335ba12bc... broken TEIID-5356 logic to infer metadata, rather than use defaults for views
=======
import org.teiid.metadata.BaseColumn.NullType;
>>>>>>> b335ba12bc... broken TEIID-5356 logic to infer metadata, rather than use defaults for views
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.ParseException;
Expand Down Expand Up @@ -460,121 +455,13 @@ public void testSkipDocumentModel() throws Exception {
ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store);
assertTrue(printError(report), report.hasItems());
}
<<<<<<< HEAD

@Test
public void testViewWithoutColumns() throws Exception {
String ddl = "CREATE FOREIGN TABLE G1(\n" +
"e1 integer primary key,\n" +
"e2 varchar(10) unique,\n" +
"e3 date not null unique,\n" +
"e4 decimal(12,3) default 12.2 options (searchable 'unsearchable'),\n" +
"e5 integer auto_increment INDEX OPTIONS (UUID 'uuid', NAMEINSOURCE 'nis', SELECTABLE 'NO'),\n" +
"e6 varchar index default 'hello')\n" +
"OPTIONS (CARDINALITY 12, UUID 'uuid2', UPDATABLE 'true', FOO 'BAR', ANNOTATION 'Test Table'); "
+ " create view v1 as select G1.*, 'a' from G1;";

buildModel("phy1", true, this.vdb, this.store, ddl);

buildTransformationMetadata();

ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store);

assertFalse(printError(report), report.hasItems());

Table table = store.getSchema("phy1").getTable("v1");

assertTrue(table.isVirtual());
assertFalse(table.isSystem());
assertFalse(table.isMaterialized());
assertFalse(table.isDeletePlanEnabled());
assertFalse(table.supportsUpdate());

assertEquals(6, table.getColumns().size());

List<Column> columns = table.getColumns();
Column e1 = columns.get(0);
Column e2 = columns.get(1);
Column e3 = columns.get(2);
Column e4 = columns.get(3);
Column e6 = columns.get(4);
Column e7 = columns.get(5);

assertEquals("e1", e1.getName());
assertEquals("integer", e1.getDatatype().getName());

assertEquals("e2", e2.getName());
assertEquals("string", e2.getDatatype().getName());
assertEquals(NullType.Nullable, e2.getNullType());
assertEquals(10, e2.getLength());
assertEquals(0, e2.getPrecision());

assertEquals("e3", e3.getName());
assertEquals("date", e3.getDatatype().getName());
assertEquals(NullType.No_Nulls, e3.getNullType());

assertEquals("e4", e4.getName());
assertEquals("bigdecimal", e4.getDatatype().getName());
assertEquals(false, e4.isAutoIncremented());
assertEquals(12, e4.getPrecision());
assertEquals(3, e4.getScale());
assertEquals(SearchType.Searchable, e4.getSearchType());
assertEquals(null, e4.getDefaultValue());

assertEquals("e6", e6.getName());
assertEquals("string", e6.getDatatype().getName());

assertEquals("expr2", e7.getName());
assertEquals("string", e7.getDatatype().getName());
assertEquals(4000, e7.getLength());
}

@Test
public void testSetQueryViewWithoutColumns() throws Exception {
String ddl = "CREATE FOREIGN TABLE G1(\n" +
"e1 varchar(10) primary key,\n" +
"e2 varchar(100) unique,\n" +
"e3 decimal(12,5),\n" +
"e4 decimal(14,3));"
+ " create view v1 as select e1, e3 from G1 union all select e2, e4 from G1;";

buildModel("phy1", true, this.vdb, this.store, ddl);

buildTransformationMetadata();

ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store);

assertFalse(printError(report), report.hasItems());

Table table = store.getSchema("phy1").getTable("v1");

List<Column> columns = table.getColumns();
Column e1 = columns.get(0);
Column e3 = columns.get(1);

assertEquals("e1", e1.getName());
assertEquals("string", e1.getDatatype().getName());
assertEquals(100, e1.getLength());

assertEquals("e3", e3.getName());
assertEquals("bigdecimal", e3.getDatatype().getName());
assertEquals(14, e3.getPrecision());
assertEquals(5, e3.getScale());
}
||||||| parent of b335ba12bc... broken TEIID-5356 logic to infer metadata, rather than use defaults for views
=======

@Test
public void testViewWithoutColumns() throws Exception {
public void testMultipleUnique() throws Exception {
String ddl = "CREATE FOREIGN TABLE G1(\n" +
"e1 integer primary key,\n" +
"e2 varchar(10) unique,\n" +
"e3 date not null unique,\n" +
"e4 decimal(12,3) default 12.2 options (searchable 'unsearchable'),\n" +
"e5 integer auto_increment INDEX OPTIONS (UUID 'uuid', NAMEINSOURCE 'nis', SELECTABLE 'NO'),\n" +
"e6 varchar index default 'hello')\n" +
"OPTIONS (CARDINALITY 12, UUID 'uuid2', UPDATABLE 'true', FOO 'BAR', ANNOTATION 'Test Table'); "
+ " create view v1 as select G1.*, 'a' from G1;";
"e3 date not null unique)";

buildModel("phy1", true, this.vdb, this.store, ddl);

Expand All @@ -583,54 +470,7 @@ public void testViewWithoutColumns() throws Exception {
ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store);

assertFalse(printError(report), report.hasItems());

Table table = store.getSchema("phy1").getTable("v1");

assertTrue(table.isVirtual());
assertFalse(table.isSystem());
assertFalse(table.isMaterialized());
assertFalse(table.isDeletePlanEnabled());
assertFalse(table.supportsUpdate());

assertEquals(6, table.getColumns().size());

List<Column> columns = table.getColumns();
Column e1 = columns.get(0);
Column e2 = columns.get(1);
Column e3 = columns.get(2);
Column e4 = columns.get(3);
Column e6 = columns.get(4);
Column e7 = columns.get(5);

assertEquals("e1", e1.getName());
assertEquals("integer", e1.getDatatype().getName());

assertEquals("e2", e2.getName());
assertEquals("string", e2.getDatatype().getName());
assertEquals(NullType.Nullable, e2.getNullType());
assertEquals(10, e2.getLength());
assertEquals(0, e2.getPrecision());

assertEquals("e3", e3.getName());
assertEquals("date", e3.getDatatype().getName());
assertEquals(NullType.No_Nulls, e3.getNullType());

assertEquals("e4", e4.getName());
assertEquals("bigdecimal", e4.getDatatype().getName());
assertEquals(false, e4.isAutoIncremented());
assertEquals(12, e4.getPrecision());
assertEquals(3, e4.getScale());
assertEquals(SearchType.Searchable, e4.getSearchType());
assertEquals(null, e4.getDefaultValue());

assertEquals("e6", e6.getName());
assertEquals("string", e6.getDatatype().getName());

assertEquals("expr2", e7.getName());
assertEquals("string", e7.getDatatype().getName());
assertEquals(4000, e7.getLength());
}
>>>>>>> b335ba12bc... broken TEIID-5356 logic to infer metadata, rather than use defaults for views
}

private ValidatorReport helpTest(String ddl, boolean expectErrors) throws Exception {
buildModel("pm1", true, this.vdb, this.store, ddl);
Expand Down

0 comments on commit 2ca1059

Please sign in to comment.