-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Preserve quotedness for Identifier when formatting Query #80
Conversation
@@ -76,7 +76,7 @@ public Identifier getField() | |||
*/ | |||
public static QualifiedName getQualifiedName(DereferenceExpression expression) | |||
{ | |||
List<String> parts = tryParseParts(expression.base, expression.field.getValue().toLowerCase(Locale.ENGLISH)); | |||
List<Identifier> parts = tryParseParts(expression.base, expression.field.getValue().toLowerCase(Locale.ENGLISH)); |
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.
It shouldn't be necessary to call toLowerCase()
. The DereferenceExpression
already deals with Identifier
s
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.
In fact, I don't think the tryParseParts
method needs to exist anymore in its current form.
@@ -1844,7 +1845,7 @@ public void testShowStats() | |||
final String[] tableNames = {"t", "s.t", "c.s.t"}; | |||
|
|||
for (String fullName : tableNames) { | |||
QualifiedName qualifiedName = QualifiedName.of(Arrays.asList(fullName.split("\\."))); | |||
QualifiedName qualifiedName = QualifiedName.of(Arrays.asList(fullName.split("\\.")).stream().map(Identifier::new).collect(Collectors.toList())); |
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.
This is a little hard to read. I'd pull it out into a makeQualifiedName
. Also, I'd structure it as:
List<Identifier> parts = Arrays.stream(fullName.split("\\."))
.map(Identifier::new)
.collect(Collectors.toList());
return QualifiedName.of(parts);
@@ -1855,7 +1856,7 @@ public void testShowStatsForQuery() | |||
final String[] tableNames = {"t", "s.t", "c.s.t"}; | |||
|
|||
for (String fullName : tableNames) { | |||
QualifiedName qualifiedName = QualifiedName.of(Arrays.asList(fullName.split("\\."))); | |||
QualifiedName qualifiedName = QualifiedName.of(Arrays.asList(fullName.split("\\.")).stream().map(Identifier::new).collect(Collectors.toList())); |
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.
Same here
@@ -734,7 +736,7 @@ public VerifierConfig setShadowWrites(boolean shadowWrites) | |||
|
|||
public QualifiedName getShadowTestTablePrefix() | |||
{ | |||
return QualifiedName.of(Splitter.on(".").splitToList(shadowTestTablePrefix)); | |||
return QualifiedName.of(Splitter.on(".").splitToList(shadowTestTablePrefix).stream().map(Identifier::new).collect(Collectors.toList())); |
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.
This can be changed to Arrays.stream(fullName.split("\\.")).xxx
like the calls in TestSqlParser and formatted across multiple lines to make it more readable.
@@ -747,7 +749,7 @@ public VerifierConfig setShadowTestTablePrefix(String prefix) | |||
|
|||
public QualifiedName getShadowControlTablePrefix() | |||
{ | |||
return QualifiedName.of(Splitter.on(".").splitToList(shadowControlTablePrefix)); | |||
return QualifiedName.of(Splitter.on(".").splitToList(shadowControlTablePrefix).stream().map(Identifier::new).collect(Collectors.toList())); |
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.
Same here
import static io.prestosql.sql.SqlFormatterUtil.getFormattedSql; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
public class TestSqlFormatterUtil |
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.
Call this TestSqlFormatter
@@ -373,7 +374,7 @@ protected Node visitShowCreate(ShowCreate node, Void context) | |||
} | |||
|
|||
Query query = parseView(viewDefinition.get().getOriginalSql(), objectName, node); | |||
String sql = formatSql(new CreateView(createQualifiedName(objectName), query, false, Optional.empty()), Optional.of(parameters)).trim(); | |||
String sql = formatSql(new CreateView(createQualifiedName(objectName, MetadataUtil.getDelimitedList(node.getName())), query, false, Optional.empty()), Optional.of(parameters)).trim(); |
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.
This seems unnecessary. It looks like you could just do: new CreateView(node.getName(), ...)
instead of trying to recreate the QualifiedName
from the QualifiedObjectName
that was derived from node.getName()
.
If you do that, you should also be able to remove MetadataUtil.getDelimitedList()
, which I'm not fond of.
5eb61f5
to
0ca9718
Compare
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.
Looks good. Can you rebase and fix the merge conflicts? I'll merge it once that's taken care of.
0ca9718
to
14558fb
Compare
@martint I have updated the code and resolved the conflicts. |
@Praveen2112, there are some build failures. Can you take a look? |
14558fb
to
be38a23
Compare
We maintain Identifier in QualifiedName for preserving its quotedness.
be38a23
to
70e6f1b
Compare
Cherry-pick of trinodb/trino#80 Presto doesn't maintain the quotedness of an identifier when using SqlQueryFormatter so it results in throwing parsing error when we run prepare query of the syntax [prestodb#10739]. This PR solves that above issue. Co-authored-by: praveenkrishna <[email protected]>
Cherry-pick of trinodb/trino#80 Presto doesn't maintain the quotedness of an identifier when using SqlQueryFormatter so it results in throwing parsing error when we run prepare query of the syntax [#10739]. This PR solves that above issue. Co-authored-by: praveenkrishna <[email protected]>
Cherry-pick of trinodb/trino#80 Presto doesn't maintain the quotedness of an identifier when using SqlQueryFormatter so it results in throwing parsing error if quoted table name is a reserved word Co-authored-by: praveenkrishna <[email protected]>
Presto doesn't maintain the quotedness of an identifier when using SqlQueryFormatter so it results in throwing parsing error when we run prepare query of the syntax [https://github.com/prestodb/presto/issues/10739]. This PR solves that above issue