Skip to content

Commit

Permalink
TEIID-5546 fix to ensure proper namespace resolution in ddl
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Nov 26, 2018
1 parent d2b7840 commit d9e4bfe
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
4 changes: 4 additions & 0 deletions api/src/main/java/org/teiid/metadata/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,8 @@ public Map<String, String> getNamespaces() {
return this.namespaceContainer.getNamespaces();
}

public NamespaceContainer getNamespaceContainer() {
return namespaceContainer;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -970,5 +970,13 @@ public Table getTableForCreateColumn(String objectName, ResourceType type) {
Table table = (Table)getSchemaRecord(objectName, type);
assertGrant(Grant.Permission.Privilege.ALTER, Database.ResourceType.TABLE, table);
return table;
}
}

/**
* Get the NamespaceContainer associated with the current database
* - this instance should not be modified unless in an edit context.
*/
public NamespaceContainer getCurrentNamespaceContainer() {
return getCurrentDatabase().getNamespaceContainer();
}
}
20 changes: 10 additions & 10 deletions engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -5239,7 +5239,7 @@ void createDatabase(DatabaseStore dbStore) :
}
)
]
[ optionsClause(database, null)
[ optionsClause(database, database.getNamespaceContainer())
{
OptionsUtil.setOptions(database);
}
Expand Down Expand Up @@ -5308,7 +5308,7 @@ void createSchema(DatabaseStore dbStore) :
schema.setPhysical(physical);
}
[<SERVER> readCSVString(servers)]
[ optionsClause(schema, null)
[ optionsClause(schema, dbStore.getCurrentNamespaceContainer())
{
OptionsUtil.setOptions(schema);
}
Expand Down Expand Up @@ -5411,7 +5411,7 @@ void createDataWrapper(DatabaseStore dbStore) :
}
)
[ <TYPE> (type = id(null) { wrapper.setType(type);}) ]
[ optionsClause(wrapper, null)
[ optionsClause(wrapper, dbStore.getCurrentNamespaceContainer())
{
OptionsUtil.setOptions(wrapper);
}
Expand Down Expand Up @@ -5663,7 +5663,7 @@ void createServer(DatabaseStore dbStore) :
server.setDataWrapper(wrapperName);
}
)
[ optionsClause(server, null)
[ optionsClause(server, dbStore.getCurrentNamespaceContainer())
{
OptionsUtil.setOptions(server);
}
Expand Down Expand Up @@ -6340,12 +6340,12 @@ name=options clause
description=A list of statement options.
example=[source,sql]\n----\nOPTIONS ('x' 'y', 'a' 'b')\n----\n
*/
void optionsClause(AbstractMetadataRecord record, MetadataFactory factory) :
void optionsClause(AbstractMetadataRecord record, NamespaceContainer namespaceContainer) :
{
}
{
<OPTIONS> <LPAREN>
optionPair(record, factory) (<COMMA> optionPair(record, factory))*
optionPair(record, namespaceContainer) (<COMMA> optionPair(record, namespaceContainer))*
<RPAREN>
}

Expand All @@ -6354,7 +6354,7 @@ name=option pair
description=An option key/value pair.
example=[source,sql]\n----\n'key' 'value'\n----\n
*/
void optionPair(AbstractMetadataRecord record, MetadataFactory factory) :
void optionPair(AbstractMetadataRecord record, NamespaceContainer namespaceContainer) :
{
Constant value = null;
String key = null;
Expand All @@ -6366,8 +6366,8 @@ void optionPair(AbstractMetadataRecord record, MetadataFactory factory) :
(value = nonNumericLiteral()
| [strVal = plusMinus()] value = unsignedNumericLiteral(strVal))
{
if (factory != null){
key = MetadataFactory.resolvePropertyKey(factory, key);
if (namespaceContainer != null){
key = MetadataFactory.resolvePropertyKey(namespaceContainer, key);
}
String val = null;
if (!value.isNull()) {
Expand Down Expand Up @@ -6817,7 +6817,7 @@ void importSchema(DatabaseStore dbStore) :
//[(<LIMIT> <TO> <LPAREN> readCSVString(includeTables) <RPAREN>) | (<EXCEPT> <LPAREN> readCSVString(excludeTables) <RPAREN>)]
<FROM> (<SERVER>{serverType = "native";}|<REPOSITORY>) serverName = id(null)
<INTO> schemaName = id(null)
[optionsClause(server, null)
[optionsClause(server, dbStore.getCurrentNamespaceContainer())
{
OptionsUtil.setOptions(server);
}
Expand Down
11 changes: 11 additions & 0 deletions engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1762,4 +1762,15 @@ public void testCreateInvalidQualifiedName() throws Exception {

helpParse(ddl);
}

@Test
public void testVdbPropertyNamespace() throws Exception {
String ddl = "create database vdb version '1.2.0' OPTIONS (\"teiid_rest:auto-generate\" 'true'); "
+ "USE DATABASE vdb VERSION '1.2.0';"
+ "CREATE SCHEMA S1; SET SCHEMA S1;"
+ "CREATE VIEW X (y varchar) as select 'a';";

Database db = helpParse(ddl);
assertEquals("true", db.getProperty("{http://teiid.org/rest}auto-generate", false));
}
}

0 comments on commit d9e4bfe

Please sign in to comment.