Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pegjs/athena.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ jsonb_expr

column_ref
= schema:ident tbl:(__ DOT __ ident) col:(__ DOT __ column) ce:(__ collate_expr)? {
columnList.add(`select::${schema}.${tbl[3]}::${col[3].value}`);
columnList.add(`select::${schema}.${tbl[3]}::${col[3].value || col[3]}`);
return {
type: 'column_ref',
schema: schema,
Expand Down Expand Up @@ -2876,6 +2876,7 @@ data_type_item
/ datetime_type
/ json_type
/ text_type
/ boolean_type

data_type_list
= head:data_type_item tail:(__ COMMA __ data_type_item)* {
Expand Down Expand Up @@ -2929,3 +2930,6 @@ json_type

text_type
= t:(KW_TINYTEXT / KW_TEXT / KW_MEDIUMTEXT / KW_LONGTEXT) { return { dataType: t }}

boolean_type
= 'boolean'i { return { dataType: 'BOOLEAN' }; }
4 changes: 4 additions & 0 deletions test/athena.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,8 @@ describe('athena', () => {
WHERE (((NOT (leads.company LIKE '%test%')) AND (NOT (leads.company LIKE '%Test%'))) AND ((NOT (leads.name LIKE '%test%')) AND (NOT (leads.name LIKE '%Test%'))))`
expect(getParsedSql(sql)).to.be.equal(`SELECT "leads".*, from_unixtime(CAST(substrinfg("leads"."demo_meeting_date_c", 1, 10) AS DOUBLE)) AS "demo_meeting_date_correct", CAST("first_conversion_date_c" AS DATE) AS "first_conversion_date_correct", "aes"."ae_owner", "created"."created_by" FROM (((("salesforce_leads" AS "leads" LEFT JOIN "salesforce_opportunitys" AS "opps" ON ("leads"."converted_opportunity_id" = "opps"."id")) LEFT JOIN (SELECT "id" AS "user_id", "name" AS "lead_owner" FROM "salesforce_users") AS "owners" ON ("leads"."owner_id" = "owners"."user_id")) LEFT JOIN (SELECT "id" AS "user_id", "name" AS "ae_owner" FROM "salesforce_users") AS "aes" ON ("leads"."a_e_owner_c" = "aes"."user_id")) LEFT JOIN (SELECT "id" AS "user_id", "name" AS "created_by" FROM "salesforce_users") AS "created" ON ("leads"."created_by_id" = "created"."user_id")) WHERE (((NOT("leads"."company" LIKE '%test%')) AND (NOT("leads"."company" LIKE '%Test%'))) AND ((NOT("leads"."name" LIKE '%test%')) AND (NOT("leads"."name" LIKE '%Test%'))))`)
})
it('should support boolean type', () => {
const sql = 'SELECT * from table_name WHERE CAST ( foo.bar.baz as boolean) = false'
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM "table_name" WHERE CAST("foo"."bar"."baz" AS BOOLEAN) = FALSE')
})
})