!1173 [fix] Some update and delete SQL statements are pushed down incorrectly
Merge pull request !1173 from chenpingzeng/delete_update_pushdown_fix
This commit is contained in:
commit
e6c2e4f6a8
|
|
@ -116,6 +116,20 @@ public class DataCenterQueryGenerator
|
|||
.setSchemaTableName(Optional.of(new SchemaTableName(dcTableHandle.getSchemaName(), dcTableHandle.getTableName())))
|
||||
.setSelections(selections)
|
||||
.setFrom(Optional.of(table.toString()));
|
||||
|
||||
String catalogName = dcTableHandle.getCatalogName();
|
||||
if (catalogName != null) {
|
||||
contextBuilder.setRemoteCatalogName(catalogName);
|
||||
}
|
||||
String schemaName = dcTableHandle.getSchemaName();
|
||||
if (schemaName != null) {
|
||||
contextBuilder.setRemoteSchemaName(schemaName);
|
||||
}
|
||||
String tableName = dcTableHandle.getTableName();
|
||||
if (tableName != null) {
|
||||
contextBuilder.setRemoteTablename(tableName);
|
||||
}
|
||||
|
||||
// If LIMIT has been push down, add it to context
|
||||
if (dcTableHandle.getLimit().isPresent()) {
|
||||
contextBuilder.setLimit(dcTableHandle.getLimit());
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class KylinSqlStatementWriter
|
|||
else {
|
||||
StringJoiner joiner = new StringJoiner(", ");
|
||||
for (Selection selection : selections) {
|
||||
if (selection.isAliased(pushDownParameter.getCaseInsensitiveParameter())) {
|
||||
if (selection.isAliased(!pushDownParameter.getCaseInsensitiveParameter())) {
|
||||
joiner.add(selection.getExpression() + " AS " + KylinKeywords.getAlias(selection.getAlias()));
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -419,6 +419,20 @@ public class BaseJdbcQueryGenerator
|
|||
.setSchemaTableName(Optional.of(jdbcTableHandle.getSchemaTableName()))
|
||||
.setSelections(selections)
|
||||
.setFrom(Optional.of(table.toString()));
|
||||
|
||||
String catalogName = jdbcTableHandle.getCatalogName();
|
||||
if (catalogName != null) {
|
||||
contextBuilder.setRemoteCatalogName(catalogName);
|
||||
}
|
||||
String schemaName = jdbcTableHandle.getSchemaName();
|
||||
if (schemaName != null) {
|
||||
contextBuilder.setRemoteSchemaName(schemaName);
|
||||
}
|
||||
String tableName = jdbcTableHandle.getTableName();
|
||||
if (tableName != null) {
|
||||
contextBuilder.setRemoteTablename(tableName);
|
||||
}
|
||||
|
||||
// If LIMIT has been push down, add it to context
|
||||
if (jdbcTableHandle.getLimit().isPresent()) {
|
||||
contextBuilder.setLimit(jdbcTableHandle.getLimit());
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class BaseJdbcSqlStatementWriter
|
|||
else {
|
||||
StringJoiner joiner = new StringJoiner(", ");
|
||||
for (Selection selection : selections) {
|
||||
if (selection.isAliased(nameCaseInsensitive)) {
|
||||
if (selection.isAliased(!nameCaseInsensitive)) {
|
||||
joiner.add(selection.getExpression() + " AS " + selection.getAlias());
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -281,9 +281,9 @@ public class JdbcPlanOptimizer
|
|||
context.getCatalogName().get(),
|
||||
new JdbcTableHandle(
|
||||
context.getSchemaTableName().get(),
|
||||
context.getCatalogName().get().getCatalogName(),
|
||||
context.getSchemaTableName().get().getSchemaName(),
|
||||
context.getSchemaTableName().get().getTableName(),
|
||||
context.getRemoteCatalogName(),
|
||||
context.getRemoteSchemaName(),
|
||||
context.getRemoteTableName(),
|
||||
TupleDomain.all(),
|
||||
OptionalLong.empty(),
|
||||
Optional.of(new GeneratedSql(sql, true)),
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ public final class JdbcQueryGeneratorContext
|
|||
{
|
||||
private final Optional<CatalogName> catalogName;
|
||||
private final Optional<SchemaTableName> schemaTableName;
|
||||
// cresponding to catalogName/schemaName/tableName to JdbcTableHandle
|
||||
private final String remoteCatalogName;
|
||||
private final String remoteSchemaName;
|
||||
private final String remoteTableName;
|
||||
private final Optional<ConnectorTransactionHandle> transaction;
|
||||
private final LinkedHashMap<String, Selection> selections;
|
||||
private final Set<String> groupByColumns;
|
||||
|
|
@ -50,6 +54,9 @@ public final class JdbcQueryGeneratorContext
|
|||
private JdbcQueryGeneratorContext(
|
||||
Optional<CatalogName> catalogName,
|
||||
Optional<SchemaTableName> schemaTableName,
|
||||
String remoteCatalogName,
|
||||
String remoteSchemaName,
|
||||
String remoteTableName,
|
||||
Optional<ConnectorTransactionHandle> transaction,
|
||||
Map<String, Selection> selections,
|
||||
Optional<String> from,
|
||||
|
|
@ -62,6 +69,9 @@ public final class JdbcQueryGeneratorContext
|
|||
{
|
||||
this.catalogName = catalogName;
|
||||
this.schemaTableName = schemaTableName;
|
||||
this.remoteCatalogName = remoteCatalogName;
|
||||
this.remoteSchemaName = remoteSchemaName;
|
||||
this.remoteTableName = requireNonNull(remoteTableName, "table name is null");
|
||||
this.transaction = transaction;
|
||||
this.selections = new LinkedHashMap<>(requireNonNull(selections, "selections can't be null"));
|
||||
this.from = requireNonNull(from, "from can't be null");
|
||||
|
|
@ -83,6 +93,21 @@ public final class JdbcQueryGeneratorContext
|
|||
return schemaTableName;
|
||||
}
|
||||
|
||||
public String getRemoteCatalogName()
|
||||
{
|
||||
return remoteCatalogName;
|
||||
}
|
||||
|
||||
public String getRemoteSchemaName()
|
||||
{
|
||||
return remoteSchemaName;
|
||||
}
|
||||
|
||||
public String getRemoteTableName()
|
||||
{
|
||||
return remoteTableName;
|
||||
}
|
||||
|
||||
public Optional<ConnectorTransactionHandle> getTransaction()
|
||||
{
|
||||
return transaction;
|
||||
|
|
@ -184,13 +209,17 @@ public final class JdbcQueryGeneratorContext
|
|||
|
||||
public static Builder buildAsNewTable(JdbcQueryGeneratorContext context)
|
||||
{
|
||||
return new Builder(context.getCatalogName(), context.getSchemaTableName(), context.getTransaction(), context.getGroupIdNodeInfo());
|
||||
return new Builder(context.getCatalogName(), context.getSchemaTableName(), context.getRemoteCatalogName(),
|
||||
context.getRemoteSchemaName(), context.getRemoteTableName(), context.getTransaction(), context.getGroupIdNodeInfo());
|
||||
}
|
||||
|
||||
public static final class Builder
|
||||
{
|
||||
private Optional<CatalogName> catalogName;
|
||||
private Optional<SchemaTableName> schemaTableName;
|
||||
private String remoteCatalogName;
|
||||
private String remoteSchemaName;
|
||||
private String remoteTableName;
|
||||
private Optional<ConnectorTransactionHandle> transaction;
|
||||
private LinkedHashMap<String, Selection> selections = new LinkedHashMap<>();
|
||||
private Set<String> groupByColumns = new HashSet<>();
|
||||
|
|
@ -207,6 +236,9 @@ public final class JdbcQueryGeneratorContext
|
|||
{
|
||||
this.catalogName = context.getCatalogName();
|
||||
this.schemaTableName = context.getSchemaTableName();
|
||||
this.remoteCatalogName = context.getRemoteCatalogName();
|
||||
this.remoteSchemaName = context.getRemoteSchemaName();
|
||||
this.remoteTableName = context.getRemoteTableName();
|
||||
this.transaction = context.getTransaction();
|
||||
this.selections = context.getSelections();
|
||||
this.groupByColumns = context.getGroupByColumns();
|
||||
|
|
@ -221,11 +253,17 @@ public final class JdbcQueryGeneratorContext
|
|||
private Builder(
|
||||
Optional<CatalogName> catalogName,
|
||||
Optional<SchemaTableName> schemaTableName,
|
||||
String remoteCatalogName,
|
||||
String remoteSchemaName,
|
||||
String remoteTableName,
|
||||
Optional<ConnectorTransactionHandle> transaction,
|
||||
GroupIdNodeInfo groupIdNodeInfo)
|
||||
{
|
||||
this.catalogName = catalogName;
|
||||
this.schemaTableName = schemaTableName;
|
||||
this.remoteCatalogName = remoteCatalogName;
|
||||
this.remoteSchemaName = remoteSchemaName;
|
||||
this.remoteTableName = remoteTableName;
|
||||
this.transaction = transaction;
|
||||
this.groupIdNodeInfo = groupIdNodeInfo;
|
||||
}
|
||||
|
|
@ -242,6 +280,24 @@ public final class JdbcQueryGeneratorContext
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setRemoteCatalogName(String catalogname)
|
||||
{
|
||||
this.remoteCatalogName = catalogname;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setRemoteSchemaName(String schemaName)
|
||||
{
|
||||
this.remoteSchemaName = schemaName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setRemoteTablename(String tableName)
|
||||
{
|
||||
this.remoteTableName = tableName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTransaction(Optional<ConnectorTransactionHandle> transaction)
|
||||
{
|
||||
this.transaction = transaction;
|
||||
|
|
@ -316,6 +372,9 @@ public final class JdbcQueryGeneratorContext
|
|||
return new JdbcQueryGeneratorContext(
|
||||
catalogName,
|
||||
schemaTableName,
|
||||
remoteCatalogName,
|
||||
remoteSchemaName,
|
||||
remoteTableName,
|
||||
transaction,
|
||||
selections,
|
||||
from,
|
||||
|
|
|
|||
|
|
@ -317,7 +317,7 @@ public class TestBaseBaseJdbcQueryGenerator
|
|||
Optional.of(endValue.getName())))),
|
||||
symbol("city"),
|
||||
scanNode)),
|
||||
"SELECT regionid, city, amount_out FROM (SELECT regionid, city, fare, amount, startvalue, endvalue, min(amount) OVER (RANGE BETWEEN startValue PRECEDING AND endValue FOLLOWING) AS amount_out FROM (SELECT regionid, city, fare, amount, startValue, endValue FROM 'table') hetu_table_1) hetu_table_2");
|
||||
"SELECT regionid, city, amount_out FROM (SELECT regionid, city, fare, amount, startvalue, endvalue, min(amount) OVER (RANGE BETWEEN startValue PRECEDING AND endValue FOLLOWING) AS amount_out FROM (SELECT regionid, city, fare, amount, startValue AS startvalue, endValue AS endvalue FROM 'table') hetu_table_1) hetu_table_2");
|
||||
testJQL(planBuilder -> planBuilder.project(
|
||||
Assignments.builder()
|
||||
.put(symbol("regionid"), variable("regionid"))
|
||||
|
|
@ -348,6 +348,6 @@ public class TestBaseBaseJdbcQueryGenerator
|
|||
Optional.empty()))),
|
||||
symbol("city"),
|
||||
scanNode)),
|
||||
"SELECT regionid, city, amount_out FROM (SELECT regionid, city, fare, amount, startvalue, endvalue, min(amount) OVER ( ORDER BY fare ASC NULLS FIRST ROWS BETWEEN startValue PRECEDING AND UNBOUNDED FOLLOWING) AS amount_out FROM (SELECT regionid, city, fare, amount, startValue, endValue FROM 'table') hetu_table_1) hetu_table_2");
|
||||
"SELECT regionid, city, amount_out FROM (SELECT regionid, city, fare, amount, startvalue, endvalue, min(amount) OVER ( ORDER BY fare ASC NULLS FIRST ROWS BETWEEN startValue PRECEDING AND UNBOUNDED FOLLOWING) AS amount_out FROM (SELECT regionid, city, fare, amount, startValue AS startvalue, endValue AS endvalue FROM 'table') hetu_table_1) hetu_table_2");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ public class Selection
|
|||
return alias;
|
||||
}
|
||||
|
||||
public boolean isAliased(boolean caseInsensitive)
|
||||
public boolean isAliased(boolean caseSensitive)
|
||||
{
|
||||
return caseInsensitive ? !this.alias.equals(expression) : !this.alias.toLowerCase(Locale.ENGLISH).equals(expression.toLowerCase(Locale.ENGLISH));
|
||||
return caseSensitive ? !this.alias.equals(expression) : !this.alias.toLowerCase(Locale.ENGLISH).equals(expression.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue