Skip to content

Commit

Permalink
support for table prefix operator
Browse files Browse the repository at this point in the history
  • Loading branch information
kanha-gupta committed May 29, 2023
1 parent 82eecfd commit dd9a777
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SubqueryTableSegment;
import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.SQLSegmentConverter;
import org.apache.shardingsphere.sqlfederation.optimizer.converter.segment.from.TableConverter;
import org.apache.shardingsphere.sqlfederation.optimizer.converter.statement.select.SelectStatementConverter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Optional;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Subquery table converter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void assertConvert(final String sqlCaseId, final SQLCaseType sqlCaseType, final
return;
}
String sql = SQL_CASES.getSQL(sqlCaseId, sqlCaseType, SQL_PARSER_TEST_CASES.get(sqlCaseId).getParameters());
String actual = SQLNodeConverterEngine.convert(parseSQLStatement(databaseType, sql)).toSqlString(SQLDialectFactory.getSQLDialect(databaseType)).getSql().replace("\n", " ");
String actual = SQLNodeConverterEngine.convert(parseSQLStatement(databaseType, sql)).toSqlString(SQLDialectFactory.getSQLDialect(databaseType)).getSql().replace("\n", " ").replace("\r", "");
assertThat(actual, is(expected));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>

<sql-node-converter-test-cases>
<test-cases sql-case-id="select_from_with_table" expected-sql="SELECT * FROM (TABLE `t0`) AS `dt`" db-types="MySQL" />
</sql-node-converter-test-cases>
4 changes: 3 additions & 1 deletion test/it/parser/src/main/resources/case/dal/explain.xml
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,16 @@

<describe sql-case-id="explain_table">
<select>
<simple-table name="t_order" start-index="14" stop-index="20" />
<order-by>
<column-item name="order_id" start-index="31" stop-index="38" />
</order-by>
<limit start-index="40" stop-index="55">
<offset value="2" literal-start-index="55" literal-stop-index="55" />
<row-count value="1" start-index="46" stop-index="46" />
</limit>
<from>
<simple-table name="t_order" start-index="8" stop-index="20" />
</from>
</select>
</describe>

Expand Down
20 changes: 15 additions & 5 deletions test/it/parser/src/main/resources/case/dml/table.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

<sql-parser-test-cases>
<select sql-case-id="table_with_order_by_limit_offset">
<simple-table name="t_order" start-index="6" stop-index="12" />
<from>
<simple-table name="t_order" start-index="0" stop-index="12" />
</from>
<order-by>
<column-item name="order_id" start-index="23" stop-index="30" />
</order-by>
Expand All @@ -29,13 +31,19 @@
</select>

<select sql-case-id="table_union">
<simple-table name="T1" start-index="6" stop-index="7" />
<from>
<simple-table name="T1" start-index="0" stop-index="7" />
</from>
<combine combine-type="UNION" start-index="9" stop-index="22">
<left>
<simple-table name="T1" start-index="6" stop-index="7" />
<from>
<simple-table name="T1" start-index="0" stop-index="7" />
</from>
</left>
<right>
<simple-table name="T2" start-index="21" stop-index="22" />
<from>
<simple-table name="T2" start-index="15" stop-index="22" />
</from>
</right>
</combine>
</select>
Expand All @@ -48,7 +56,9 @@
<subquery-table alias="dt">
<subquery>
<select>
<simple-table name="t0" start-index="21" stop-index="22" />
<from>
<simple-table name="t0" start-index="15" stop-index="22" />
</from>
</select>
</subquery>
</subquery-table>
Expand Down

0 comments on commit dd9a777

Please sign in to comment.