Skip to content

refactor entity parser#398

Open
skywhat wants to merge 1 commit into
masterfrom
parser
Open

refactor entity parser#398
skywhat wants to merge 1 commit into
masterfrom
parser

Conversation

@skywhat

@skywhat skywhat commented Aug 22, 2019

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread entity_parser.go
ttlPattern0 = regexp.MustCompile(`ttl\s*=\s*(\S*)`)

indexType = reflect.TypeOf((*Index)(nil)).Elem()
tagsKey = []string{"primaryKey", "key", "name", "columns", "etl", "ttl"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see the same strings are repeated in the below code, which can be error-prone. How about defining them as variables like:

primaryKeyTag = "primaryKey";

and use "primaryKeyTag" in the remaining places so that compiler will tell you whether or not you are spelling correctly.

Comment thread entity_parser.go
return "", nil, nil, fmt.Errorf("index field %s with an invalid dosa index tag: %s", indexName, tag)
var key *PrimaryKey
if val, ok := tagsMap["key"]; ok {
key, err = parsePrimaryKey(val)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Given that we use the same function for paring primary keys and index keys, how about calling it "parseKey"

Comment thread entity_parser.go
fullNameTag = matches[0]
name = matches[1]
// parseSinglePrimaryKey func parses the single parimary key of DOSA object
func parseSinglePrimaryKey(s string) (*PrimaryKey, error) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

parimary => primary

Comment thread entity_parser.go
// parseSinglePrimaryKey func parses the single parimary key of DOSA object
func parseSinglePrimaryKey(s string) (*PrimaryKey, error) {
s = strings.TrimSpace(s)
spaceIdx := strings.Index(s, " ")

@ateliersakura ateliersakura Aug 23, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Will this impact existing users?

Comment thread entity_parser.go
// parseCompoundPartitionKeys func parses the compund partition key of DOSA object
func parseCompoundPartitionKeys(s string) ([]string, error) {
s = strings.TrimSpace(strings.Trim(s, "()"))
fields := strings.Split(s, ",")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

do we need to check for the existence of spaces like the function above?

Comment thread entity_parser.go
for _, ckField := range ckFields {
fields := strings.Fields(ckField)
if len(fields) == 0 {
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this be an error?

@CLAassistant

CLAassistant commented Jun 13, 2020

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Gang Zhang seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

3 participants