Skip to content

Commit d24698d

Browse files
committed
feat: add boolean type in athena
1 parent fbac7c7 commit d24698d

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

pegjs/athena.pegjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,7 @@ jsonb_expr
18951895

18961896
column_ref
18971897
= schema:ident tbl:(__ DOT __ ident) col:(__ DOT __ column) ce:(__ collate_expr)? {
1898-
columnList.add(`select::${schema}.${tbl[3]}::${col[3].value}`);
1898+
columnList.add(`select::${schema}.${tbl[3]}::${col[3].value || col[3]}`);
18991899
return {
19001900
type: 'column_ref',
19011901
schema: schema,
@@ -2876,6 +2876,7 @@ data_type_item
28762876
/ datetime_type
28772877
/ json_type
28782878
/ text_type
2879+
/ boolean_type
28792880

28802881
data_type_list
28812882
= head:data_type_item tail:(__ COMMA __ data_type_item)* {
@@ -2929,3 +2930,6 @@ json_type
29292930

29302931
text_type
29312932
= t:(KW_TINYTEXT / KW_TEXT / KW_MEDIUMTEXT / KW_LONGTEXT) { return { dataType: t }}
2933+
2934+
boolean_type
2935+
= 'boolean'i { return { dataType: 'BOOLEAN' }; }

test/athena.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,8 @@ describe('athena', () => {
470470
WHERE (((NOT (leads.company LIKE '%test%')) AND (NOT (leads.company LIKE '%Test%'))) AND ((NOT (leads.name LIKE '%test%')) AND (NOT (leads.name LIKE '%Test%'))))`
471471
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%'))))`)
472472
})
473+
it('should support boolean type', () => {
474+
const sql = 'SELECT * from table_name WHERE CAST ( foo.bar.baz as boolean) = false'
475+
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM "table_name" WHERE CAST("foo"."bar"."baz" AS BOOLEAN) = FALSE')
476+
})
473477
})

0 commit comments

Comments
 (0)