Skip to content
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

Automatic Query Fixer: init the project and implement a query token service #73

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mingen-pan
Copy link
Contributor

init a project with basic structures

create and test the QueryTokenService

create and test a QueryTokenService
@mingen-pan mingen-pan changed the title [Automatic Query Fixer] init the project and implement a query token service Automatic Query Fixer: init the project and implement a query token service Jun 25, 2020
@mingen-pan mingen-pan requested review from kikkyo and Bei-z June 29, 2020 21:59

compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
implementation 'org.apache.calcite.avatica:avatica-core:1.17.0'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still decided to use this :)?

Copy link
Contributor Author

@mingen-pan mingen-pan Jun 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. It seems some place can be replaced by AutoValue, but not every class acts as an immutable value and some may need to be modified (by setter) after creation. Thus, I think lombok may be better in some situations. If AutoValue can do the similar job, I will change to it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autovalue builder pattern can help you generate getters/setters.
https://github.com/google/auto/blob/master/value/userguide/builders.md
We are open to use lib we want not sure if one is significant better than the other given the current use case.

public static void main(String[] args) {

if (args.length == 0 ) {
System.out.println("not enough arguments");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,14 @@
package com.google.cloud.bigquery.utils.auto_query_fixer;

public class Application {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite like "Application"
I saw many people use "'MyClass'Main" or similar
maybe 'QueryFixerMain'?

return;
}

String query = args[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we never use this? Add a TODO?

Copy link
Collaborator

@kikkyo kikkyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/google/google-java-format maybe we can install this :)

import java.util.ArrayList;
import java.util.List;

public class QueryTokenService {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comment for the class and each method according to the style guide. It would be harder to understand without comments :).

List<IToken> tokens = new ArrayList<>();

// a parser contains token manager, which will be used to tokenize sql.
final SqlParser.ConfigBuilder configBuilder =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a class member iso it can be used in other places too?

Copy link
Contributor Author

@mingen-pan mingen-pan Jul 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to the new class BigQueryParserFactory

0f80bd6#diff-bc6e7d45c3985d53fb022f9fdb5b309b

SqlBabelParserImpl parserImpl = (SqlBabelParserImpl) configBuilder.build().parserFactory().getParser(new SourceStringReader(sql));

Token token;
while ((token = parserImpl.getNextToken()).kind != 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious what is 'kind' here? why we can use this as termination condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String[] lines = sql.split("\n");
validateToken(lines, token);

// the token's line and column number are 1-index,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Comments should start with Upper case, // 'The' token's line and ...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Looks like the comment line is not well formatted, you can use the java formatter to help format it better: ).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

// end index is excluded!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Please remove random comment or make it more readable :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import lombok.Data;

@Data
public class Choice {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comment for each class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants