Skip to content

Commit

Permalink
BZ1558026: DV 6.4.3 + TEIID-5377: Type mismatch when issuing recursiv…
Browse files Browse the repository at this point in the history
…e common table expression query (correcting rcte typing)
  • Loading branch information
shawkins authored and johnathonlee committed Jun 15, 2018
1 parent 2a240fc commit d4ad6b7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ <h4 class="western">from ${project.version}</h4>
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-5373'>TEIID-5373</a> - Dependent set created from prepared IN predicate fails (correcting prepared dependent behavior)
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-5377'>TEIID-5377</a> - Type mismatch when issuing recursive common table expression query (correcting rcte typing)
</ul>

<h4 class="western">from 8.12.13.6_4</h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1563,8 +1563,8 @@ protected boolean isNonAscii(Expression obj) {
}
if (obj instanceof ColumnReference) {
ColumnReference cr = (ColumnReference)obj;
return cr.getMetadataObject() == null
|| (StringUtil.startsWithIgnoreCase(cr.getMetadataObject().getNativeType(), "N")); //$NON-NLS-1$
return cr.getMetadataObject() != null
&& (StringUtil.startsWithIgnoreCase(cr.getMetadataObject().getNativeType(), "N")); //$NON-NLS-1$

}
if (obj.getType() == TypeFacility.RUNTIME_TYPES.CLOB) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,24 @@ private void helpTestVisitor(String input, String expectedOutput) throws Transla
input, output,
TRANSLATOR);
}

@Test public void testRecursiveCTEWithStringLiteral() throws Exception {
String input = "WITH tmp_cte(id, name, fk, fkname, lvl) AS \n" +
" (SELECT id, name, fk, cast(NULL as string) as fkname, 0 as lvl \n" +
" FROM cte_source WHERE fk IS NULL \n" +
" UNION ALL \n" +
" SELECT e.id, e.name, e.fk, ecte.name as fkname, lvl + 1 as lvl \n" +
" FROM cte_source AS e \n" +
" INNER JOIN tmp_cte AS ecte ON ecte.id = e.fk\n" +
" ) \n" +
"SELECT * FROM tmp_cte order by lvl"; //$NON-NLS-1$
String output = "WITH tmp_cte (id, name, fk, fkname, lvl) AS (SELECT cte_source.id, cte_source.name, cte_source.fk, NULL AS fkname, 0 AS lvl FROM cte_source WHERE cte_source.fk IS NULL UNION ALL SELECT e.id, e.name, e.fk, ecte.name AS fkname, (ecte.lvl + 1) AS lvl FROM cte_source e INNER JOIN tmp_cte ecte ON ecte.id = e.fk) "
+ "SELECT tmp_cte.id, tmp_cte.name, tmp_cte.fk, tmp_cte.fkname, tmp_cte.lvl FROM tmp_cte ORDER BY tmp_cte.lvl"; //$NON-NLS-1$

TranslationHelper.helpTestVisitor("create foreign table cte_source (id integer, name string options (native_type 'varchar(255)'), fk integer)", input,
output, TRANSLATOR);
}

@Test public void testRowLimit1() throws Exception {
String input = "select intkey from bqt1.smalla limit 10, 0"; //$NON-NLS-1$
String output = "SELECT * FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (SELECT SmallA.IntKey FROM SmallA) VIEW_FOR_LIMIT WHERE ROWNUM <= 10) WHERE ROWNUM_ > 10"; //$NON-NLS-1$
Expand Down Expand Up @@ -1317,4 +1335,5 @@ public void testGeometryInsertQueryExpression() throws Exception {
null,
output);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,22 @@ public void testNCharCast() throws Exception {

TranslationHelper.helpTestVisitor("create foreign table tbl (txt string options (native_type 'ntext'))", input, output, trans);
}

@Test public void testRecursiveCTEWithStringLiteral() throws Exception {
String input = "WITH tmp_cte(id, name, fk, fkname, lvl) AS \n" +
" (SELECT id, name, fk, cast(NULL as string) as fkname, 0 as lvl \n" +
" FROM cte_source WHERE fk IS NULL \n" +
" UNION ALL \n" +
" SELECT e.id, e.name, e.fk, ecte.name as fkname, lvl + 1 as lvl \n" +
" FROM cte_source AS e \n" +
" INNER JOIN tmp_cte AS ecte ON ecte.id = e.fk\n" +
" ) \n" +
"SELECT * FROM tmp_cte order by lvl"; //$NON-NLS-1$
String output = "WITH tmp_cte (id, name, fk, fkname, lvl) AS (SELECT cast(cte_source.id AS int), cte_source.name, cast(cte_source.fk AS int), cast(NULL AS varchar(4000)) AS fkname, cast(0 AS int) AS lvl FROM cte_source WHERE cte_source.fk IS NULL UNION ALL SELECT cast(e.id AS int), e.name, cast(e.fk AS int), cast(ecte.name AS varchar(4000)) AS fkname, cast((ecte.lvl + 1) AS int) AS lvl FROM cte_source e INNER JOIN tmp_cte ecte ON ecte.id = e.fk) "
+ "SELECT tmp_cte.id, tmp_cte.name, tmp_cte.fk, tmp_cte.fkname, tmp_cte.lvl FROM tmp_cte ORDER BY tmp_cte.lvl"; //$NON-NLS-1$

TranslationHelper.helpTestVisitor("create foreign table cte_source (id integer, name string options (native_type 'varchar(255)'), fk integer)", input,
output, trans);
}

}

0 comments on commit d4ad6b7

Please sign in to comment.