Author: shawkins
Date: 2012-01-12 11:13:09 -0500 (Thu, 12 Jan 2012)
New Revision: 3791
Modified:
trunk/api/src/main/java/org/teiid/language/SQLConstants.java
trunk/documentation/reference/src/main/docbook/en-US/content/sql_clauses.xml
trunk/engine/src/main/java/org/teiid/query/processor/relational/TextTableNode.java
trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/TextTable.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/UpdateValidator.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/query/processor/TestTextTable.java
Log:
TEIID-1819 adding selector logic to texttable
Modified: trunk/api/src/main/java/org/teiid/language/SQLConstants.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/SQLConstants.java 2012-01-11 21:37:46 UTC
(rev 3790)
+++ trunk/api/src/main/java/org/teiid/language/SQLConstants.java 2012-01-12 16:13:09 UTC
(rev 3791)
@@ -73,6 +73,8 @@
public static final String HEADER = "HEADER"; //$NON-NLS-1$
public static final String QUOTE = "QUOTE"; //$NON-NLS-1$
public static final String COLUMNS = "COLUMNS"; //$NON-NLS-1$
+ public static final String SELECTOR = "SELECTOR"; //$NON-NLS-1$
+ public static final String SKIP = "SKIP"; //$NON-NLS-1$
//xmltable
public static final String ORDINALITY = "ORDINALITY"; //$NON-NLS-1$
public static final String PASSING = "PASSING"; //$NON-NLS-1$
@@ -113,7 +115,7 @@
public static final String ENABLED = "ENABLED"; //$NON-NLS-1$
public static final String DISABLED = "DISABLED"; //$NON-NLS-1$
- public static final String TRIM = "TRIM";
+ public static final String TRIM = "TRIM"; //$NON-NLS-1$
}
public interface Reserved {
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/sql_clauses.xml
===================================================================
---
trunk/documentation/reference/src/main/docbook/en-US/content/sql_clauses.xml 2012-01-11
21:37:46 UTC (rev 3790)
+++
trunk/documentation/reference/src/main/docbook/en-US/content/sql_clauses.xml 2012-01-12
16:13:09 UTC (rev 3791)
@@ -104,7 +104,8 @@
</para>
<para>
Usage:
- <synopsis label="Usage">TEXTTABLE(expression COLUMNS
<COLUMN>, ... [NO ROW DELIMITER] [DELIMITER char] [(QUOTE|ESCAPE) char]
[HEADER [integer]] [SKIP integer]) AS name</synopsis>
+ <synopsis label="Usage">TEXTTABLE(expression COLUMNS
<COLUMN>, ... [NO ROW DELIMITER] [DELIMITER char] [(QUOTE|ESCAPE) char]
+ [HEADER [integer]] [SKIP integer] [SELECTOR string]) AS name</synopsis>
<synopsis label="Usage">COLUMN := name datatype [WIDTH integer
[NO TRIM]]</synopsis>
</para>
<itemizedlist>
@@ -142,6 +143,10 @@
</para>
</listitem>
<listitem>
+ <para>SELECTOR specifies that delemited lines should only match if the
line begins with the selector string followed by a delimiter. The selector value is a
valid column value.
+ </para>
+ </listitem>
+ <listitem>
<para>WIDTH indicates the fixed-width length of a column in characters -
not bytes. The CR NL newline value counts as a single character.
</para>
</listitem>
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/TextTableNode.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/TextTableNode.java 2012-01-11
21:37:46 UTC (rev 3790)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/TextTableNode.java 2012-01-12
16:13:09 UTC (rev 3791)
@@ -170,6 +170,10 @@
break;
}
+ if (table.getSelector() != null && !line.startsWith(table.getSelector())) {
+ continue;
+ }
+
List<String> vals = parseLine(line);
List<Object> tuple = new ArrayList<Object>(projectionIndexes.length);
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2012-01-11
21:37:46 UTC (rev 3790)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2012-01-12
16:13:09 UTC (rev 3791)
@@ -36,9 +36,7 @@
import org.teiid.api.exception.query.QueryValidatorException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.core.util.StringUtil;
import org.teiid.dqp.internal.process.Request;
-import org.teiid.language.SQLConstants;
import org.teiid.logging.LogManager;
import org.teiid.query.QueryPlugin;
import org.teiid.query.analysis.AnalysisRecord;
@@ -500,11 +498,7 @@
private static UpdateType determineType(String plan) {
UpdateType type = UpdateType.INHERENT;
if (plan != null) {
- if (StringUtil.startsWithIgnoreCase(plan, SQLConstants.Reserved.CREATE)) {
- type = UpdateType.UPDATE_PROCEDURE;
- } else {
- type = UpdateType.INSTEAD_OF;
- }
+ type = UpdateType.INSTEAD_OF;
}
return type;
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/TextTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/TextTable.java 2012-01-11 21:37:46
UTC (rev 3790)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/TextTable.java 2012-01-12 16:13:09
UTC (rev 3791)
@@ -95,9 +95,18 @@
private Integer header;
private Integer skip;
private boolean usingRowDelimiter = true;
+ private String selector;
private boolean fixedWidth;
+ public String getSelector() {
+ return selector;
+ }
+
+ public void setSelector(String selector) {
+ this.selector = selector;
+ }
+
public Character getQuote() {
return quote;
}
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-01-11
21:37:46 UTC (rev 3790)
+++
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2012-01-12
16:13:09 UTC (rev 3791)
@@ -1726,10 +1726,16 @@
}
if (obj.getSkip() != null) {
append(SPACE);
- append("SKIP"); //$NON-NLS-1$
+ append(NonReserved.SKIP);
append(SPACE);
append(obj.getSkip());
}
+ if (obj.getSelector() != null) {
+ append(SPACE);
+ append(NonReserved.SELECTOR);
+ append(SPACE);
+ append(escapeSinglePart(obj.getSelector()));
+ }
append(")");//$NON-NLS-1$
append(SPACE);
append(AS);
Modified: trunk/engine/src/main/java/org/teiid/query/validator/UpdateValidator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/UpdateValidator.java 2012-01-11
21:37:46 UTC (rev 3790)
+++ trunk/engine/src/main/java/org/teiid/query/validator/UpdateValidator.java 2012-01-12
16:13:09 UTC (rev 3791)
@@ -64,10 +64,6 @@
*/
INHERENT,
/**
- * A procedure handler has been defined
- */
- UPDATE_PROCEDURE,
- /**
* An instead of trigger (TriggerAction) has been defined
*/
INSTEAD_OF
Modified: trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2012-01-11
21:37:46 UTC (rev 3790)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2012-01-12
16:13:09 UTC (rev 3791)
@@ -75,7 +75,6 @@
import org.teiid.query.sql.visitor.SQLStringVisitor;
import org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import org.teiid.query.validator.UpdateValidator.UpdateInfo;
-import org.teiid.query.validator.UpdateValidator.UpdateType;
import org.teiid.query.xquery.saxon.SaxonXQueryExpression;
import org.teiid.translator.SourceSystemFunctions;
@@ -679,14 +678,6 @@
if(((Constant)value).isNull() && !
getMetadata().elementSupports(elementID.getMetadataID(), SupportConstants.Element.NULL))
{
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0060",
SQLStringVisitor.getSQLString(elementID)), elementID); //$NON-NLS-1$
}// end of if
- } else if (info != null && info.getUpdateType() ==
UpdateType.UPDATE_PROCEDURE &&
getMetadata().isVirtualGroup(update.getGroup().getMetadataID()) &&
!EvaluatableVisitor.willBecomeConstant(value)) {
- // If this is an update on a virtual group, verify that no elements
are in the right side
- Collection<ElementSymbol> elements =
ElementCollectorVisitor.getElements(value, false);
- for (ElementSymbol element : elements) {
- if(! element.isExternalReference()) {
-
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0061",
SQLStringVisitor.getSQLString(value)), value); //$NON-NLS-1$
- }
- }
}
}
if (info != null && info.isInherentUpdate()) {
@@ -1213,7 +1204,7 @@
}
}
if (widthSet) {
- if (obj.getDelimiter() != null || obj.getHeader() != null || obj.getQuote() !=
null) {
+ if (obj.getDelimiter() != null || obj.getHeader() != null || obj.getQuote() != null
|| obj.getSelector() != null) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.text_table_width"),
obj); //$NON-NLS-1$
}
} else {
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-01-11 21:37:46
UTC (rev 3790)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-01-12 16:13:09
UTC (rev 3791)
@@ -2165,6 +2165,7 @@
Character quote = null;
Integer header = null;
Integer skip = null;
+ String selector = null;
String aliasID = null;
}
{
@@ -2211,6 +2212,10 @@
LOOKAHEAD(<ID>, { "skip".equalsIgnoreCase(getToken(1).image) })
<ID>
skip = intVal()
]
+ [
+ LOOKAHEAD(<ID>, { "selector".equalsIgnoreCase(getToken(1).image) })
<ID>
+ selector = stringVal()
+ ]
<RPAREN>
[<AS>] aliasID=id()
{
@@ -2224,6 +2229,7 @@
result.setName(validateAlias(aliasID));
result.setQuote(quote);
result.setUsingRowDelimiter(useRowDelimiter);
+ result.setSelector(selector);
return result;
}
}
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-01-11 21:37:46
UTC (rev 3790)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-01-12 16:13:09
UTC (rev 3791)
@@ -216,7 +216,6 @@
ERR.015.012.0055 = Element {0} does not allow nulls.
ERR.015.012.0059 = Left side of update expression must be an element that supports
update: {0}
ERR.015.012.0060 = Element {0} does not allow nulls.
-ERR.015.012.0061 = Views using update procedures must have update values that are
constant expressions. The expression ''{0}'' cannot be evaluated to a
constant.
ERR.015.012.0062 = Elements cannot appear more than once in a SET or USING clause. The
following elements are duplicated: {0}
ERR.015.012.0063 = Multiple failures occurred during validation:
ERR.015.012.0064 = Validation succeeded
@@ -710,7 +709,7 @@
ValidationVisitor.drop_of_nontemptable=Cannot drop a non temporary table
"{0}".
ValidationVisitor.orderby_expression_xml=XML queries cannot order by an expression.
ValidationVisitor.text_table_invalid_width=For a fixed width text table, all columns must
have width set.
-ValidationVisitor.text_table_width=Fixed width text tables should not have DELIMITER,
QUOTE, ESCAPE, or HEADER specified.
+ValidationVisitor.text_table_width=Fixed width text tables should not have DELIMITER,
QUOTE, ESCAPE, SELECTOR or HEADER specified.
ValidationVisitor.text_table_negative=Text table WIDTH, HEADER, or SKIP values must not
be negative.
ValidationVisitor.text_table_delimiter=Text DELIMITER cannot be the same as the QUOTE or
ESCAPE characters.
ValidationVisitor.text_table_newline=Text DELIMITER, QUOTE, and ESCAPE characters cannot
be the new line character.
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java 2012-01-11
21:37:46 UTC (rev 3790)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java 2012-01-12
16:13:09 UTC (rev 3791)
@@ -314,8 +314,18 @@
sampleData1(dataManager);
RelationalPlan plan = (RelationalPlan)helpGetPlan(helpParse(sql),
RealMetadataFactory.example1Cached());
helpProcess(plan, createCommandContext(), dataManager, expected);
- }
+ }
+ @Test public void testTextTableSelector() throws Exception {
+ String sql = "select x.* from (select * from pm1.g1) y, texttable(e1 ||
'\n' || e2 || '\n' || e3 COLUMNS x string SELECTOR 'c') x";
+
+ List[] expected = new List[] {
+ Arrays.asList("c"),
+ };
+
+ process(sql, expected);
+ }
+
public static void process(String sql, List[] expectedResults) throws Exception {
FakeDataManager dataManager = new FakeDataManager();
sampleData1(dataManager);