-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature](sql-dialect)support convert hive view and presto view use sql convertor service #46308
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8b7a157
[feature](sql-dialect)support convert hive view and presto view use s…
liujiwen-up 866c8d7
[feature](sql-dialect)support convert hive view and presto view use s…
liujiwen-up 0e8fa2d
[feature](sql-dialect)support convert hive view and presto view use s…
liujiwen-up 1b45592
fix
liujiwen-up 6c8a8f9
fix test case
liujiwen-up 6f00487
fix test case
liujiwen-up cedd2f5
fix test case
liujiwen-up 270a31c
fix test case
liujiwen-up 0f4aff9
Merge branch 'apache:master' into master
liujiwen-up b71a792
fix test case
liujiwen-up de5650e
fix 1
liujiwen-up File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix test case
- Loading branch information
commit 6f00487c79adfc77762dc44327d48985b3abf20d
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/SqlDialectHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.doris.nereids.parser; | ||
|
||
import org.apache.doris.catalog.Env; | ||
import org.apache.doris.plugin.DialectConverterPlugin; | ||
import org.apache.doris.plugin.PluginMgr; | ||
import org.apache.doris.qe.SessionVariable; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.List; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Helper class for SQL dialect conversion. | ||
*/ | ||
public class SqlDialectHelper { | ||
private static final Logger LOG = LogManager.getLogger(SqlDialectHelper.class); | ||
|
||
/** | ||
* Convert SQL statement based on current SQL dialect | ||
* | ||
* @param originStmt original SQL statement | ||
* @param sessionVariable session variable containing dialect settings | ||
* @return converted SQL statement, or original statement if conversion fails | ||
*/ | ||
public static String convertSqlByDialect(String originStmt, SessionVariable sessionVariable) { | ||
String convertedStmt = originStmt; | ||
@Nullable Dialect sqlDialect = Dialect.getByName(sessionVariable.getSqlDialect()); | ||
if (sqlDialect != null && sqlDialect != Dialect.DORIS) { | ||
PluginMgr pluginMgr = Env.getCurrentEnv().getPluginMgr(); | ||
List<DialectConverterPlugin> plugins = pluginMgr.getActiveDialectPluginList(sqlDialect); | ||
for (DialectConverterPlugin plugin : plugins) { | ||
try { | ||
String convertedSql = plugin.convertSql(originStmt, sessionVariable); | ||
if (StringUtils.isNotEmpty(convertedSql)) { | ||
convertedStmt = convertedSql; | ||
break; | ||
} | ||
} catch (Throwable throwable) { | ||
LOG.warn("Convert sql with dialect {} failed, plugin: {}, sql: {}, use origin sql.", | ||
sqlDialect, plugin.getClass().getSimpleName(), originStmt, throwable); | ||
} | ||
} | ||
} | ||
return convertedStmt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
regression-test/suites/dialect_compatible/sql/viewrewrite.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
--create catalog | ||
drop catalog if exists hive_view; | ||
create catalog hive_view properties('type' = 'hms', 'hive.metastore.uris' = 'thrift://192.168.0.1:9083'); | ||
--dialect option | ||
set sql_dialect = hive; | ||
|
||
--create catalog | ||
drop catalog if exists hive; | ||
create catalog hive properties('type' = 'hms', 'hive.metastore.uris' = 'thrift://192.168.0.1:9083'); | ||
--test view rewrite | ||
select * from hive.default.department_view; | ||
select * from hive.default.department_nesting_view; | ||
select * from hive_view.default.department_view; | ||
select * from hive_view.default.department_nesting_view; | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not return originalText instead of return null when parse failed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. you can return
originalText
directly inparseTrinoViewDefinition
's return valueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and better add a UT for this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done