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
22 changes: 22 additions & 0 deletions pegjs/trino.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

'DELETE': true,
'DESC': true,
'DESCRIBE': true,
'DISTINCT': true,
'DROP': true,

Expand Down Expand Up @@ -254,6 +255,7 @@ cmd_stmt
/ set_stmt
/ lock_stmt
/ show_stmt
/ desc_stmt
/ deallocate_stmt

create_stmt
Expand Down Expand Up @@ -1988,6 +1990,25 @@ show_stmt
}
}

desc_stmt
= KW_DESCRIBE __ t:table_name {
/*
export interface desc_stmt_node {
type: 'describe';
table: table_name;
}
=> AstStatement<desc_stmt_node>
*/
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
ast: {
type: 'describe',
table: t
}
};
}

deallocate_stmt
= KW_DEALLOCATE __ p:('PREPARE'i)? __ i:(ident_name / KW_ALL) {
return {
Expand Down Expand Up @@ -4348,6 +4369,7 @@ KW_OFFSET = "OFFSET"i !ident_start { return 'OFFSET' }

KW_ASC = "ASC"i !ident_start { return 'ASC'; }
KW_DESC = "DESC"i !ident_start { return 'DESC'; }
KW_DESCRIBE = "DESCRIBE"i !ident_start { return 'DESCRIBE'; }

KW_ALL = "ALL"i !ident_start { return 'ALL'; }
KW_DISTINCT = "DISTINCT"i !ident_start { return 'DISTINCT';}
Expand Down
3 changes: 2 additions & 1 deletion src/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function commonCmdToSQL(stmt) {
function descToSQL(stmt) {
const { type, table } = stmt
const action = toUpper(type)
return `${action} ${identifierToSql(table)}`
const tableName = typeof table === 'string' ? identifierToSql(table) : tableToSQL(table)
return `${action} ${tableName}`
}

function executeToSQL(stmt) {
Expand Down
2 changes: 1 addition & 1 deletion src/sql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { unionToSQL, multipleToSQL } from './union'

const supportedTypes = ['analyze', 'attach', 'select', 'deallocate', 'delete', 'exec', 'update', 'insert', 'drop', 'rename', 'truncate', 'call', 'desc', 'use', 'alter', 'set', 'create', 'lock', 'unlock', 'declare', 'show', 'replace', 'if', 'grant', 'revoke', 'proc', 'raise', 'execute', 'transaction', 'explain', 'comment', 'load_data']
const supportedTypes = ['analyze', 'attach', 'select', 'deallocate', 'delete', 'exec', 'update', 'insert', 'drop', 'rename', 'truncate', 'call', 'desc', 'describe', 'use', 'alter', 'set', 'create', 'lock', 'unlock', 'declare', 'show', 'replace', 'if', 'grant', 'revoke', 'proc', 'raise', 'execute', 'transaction', 'explain', 'comment', 'load_data']

function checkSupported(expr) {
const ast = expr && expr.ast ? expr.ast : expr
Expand Down
1 change: 1 addition & 0 deletions src/union.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const typeToSQLFn = {
rename : renameToSQL,
call : callToSQL,
desc : descToSQL,
describe : descToSQL,
set : setVarToSQL,
lock : lockUnlockToSQL,
unlock : lockUnlockToSQL,
Expand Down
20 changes: 14 additions & 6 deletions test/trino.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,21 @@ describe('trino', () => {
{
title: 'ROW expression',
sql: [
'SELECT ROW(12 AS x, 122 y) FROM t',
"SELECT ROW(12 AS x, 122 y) FROM t",
'SELECT ROW(12 AS "x", 122 AS "y") FROM "t"'
]
}
]
SQL_LIST.forEach(sqlInfo => {
const { title, sql } = sqlInfo
],
},
{
title: "DESCRIBE statement",
sql: ["DESCRIBE my_table", 'DESCRIBE "my_table"'],
},
{
title: "DESCRIBE statement with fully qualified name",
sql: ['DESCRIBE my_catalog.my_schema.my_table', 'DESCRIBE "my_catalog"."my_schema"."my_table"'],
},
];
SQL_LIST.forEach((sqlInfo) => {
const { title, sql } = sqlInfo;
it(`should support ${title}`, () => {
expect(getParsedSql(sql[0], opt)).to.equal(sql[1])
})
Expand Down