Skip to content

Commit

Permalink
Merge pull request #858 from taozhi8833998/feat-rlike-hive
Browse files Browse the repository at this point in the history
feat: support rlike in hive
  • Loading branch information
taozhi8833998 committed Dec 2, 2021
2 parents 2f96d56 + 61c6fff commit 56b237c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pegjs/hive.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,7 @@ between_or_not_between_op
like_op
= nk:(KW_NOT __ KW_LIKE) { return nk[0] + ' ' + nk[2]; }
/ KW_LIKE
/ KW_RLIKE

in_op
= nk:(KW_NOT __ KW_IN) { return nk[0] + ' ' + nk[2]; }
Expand Down Expand Up @@ -2042,6 +2043,7 @@ KW_BETWEEN = "BETWEEN"i !ident_start { return 'BETWEEN'; }
KW_IN = "IN"i !ident_start { return 'IN'; }
KW_IS = "IS"i !ident_start { return 'IS'; }
KW_LIKE = "LIKE"i !ident_start { return 'LIKE'; }
KW_RLIKE = "RLIKE"i !ident_start { return 'RLIKE'; }
KW_EXISTS = "EXISTS"i !ident_start { return 'EXISTS'; }

KW_NOT = "NOT"i !ident_start { return 'NOT'; }
Expand Down
7 changes: 7 additions & 0 deletions test/hive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ describe('Hive', () => {
)`
expect(getParsedSql(sql)).to.be.equal("SELECT * FROM `ab` WHERE ((`upstream`.`created_time` >= from_unixtime((`businessBeginTime` - 3600000) / 1000, 'yyyy-MM-dd hh:mm:ss') AND `upstream`.`created_time` < from_unixtime((`businessEndTime` - 3600000) / 1000, 'yyyy-MM-dd hh:mm:ss')) OR (`item`.`create_time` >= `businessBeginTime` - 3600000 AND `item`.`create_time` < from_unixtime((`businessEndTime` - 3600000) / 1000, 'yyyy-MM-dd hh:mm:ss'))) AND (`upstream`.`upper_amount` IS NULL OR `item`.`amount` IS NULL OR coalesce(`upstream`.`upper_amount`, 0) <> coalesce(`item`.`amount`, 0) OR `upstream`.`settle_type` <> `item`.`settle_type`)")
})

it('should support rlike', () => {
const sql = `select emp_id,name,email_id
from emp_info
where email_id RLIKE '^([0-9]|[a-z]|[A-Z])';`
expect(getParsedSql(sql)).to.be.equal("SELECT `emp_id`, `name`, `email_id` FROM `emp_info` WHERE `email_id` RLIKE '^([0-9]|[a-z]|[A-Z])'")
})
})

0 comments on commit 56b237c

Please sign in to comment.