Skip to content

Commit

Permalink
[Trino] Update drag and drop suggestions to use double quotes instead…
Browse files Browse the repository at this point in the history
… of backticks
  • Loading branch information
agl29 committed Sep 25, 2024
1 parent 9111b91 commit 4e5641e
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions desktop/core/src/desktop/js/sql/sqlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,24 +267,51 @@ export default {
sqlReferenceProvider?: SqlReferenceProvider,
forceAppendBacktick?: boolean
): Promise<string> => {
// Determine the quote character based on the connector dialect
let quoteChar =
(connector.dialect_properties && connector.dialect_properties.sql_identifier_quote) || '`';

// Use double quotes for Trino
if (connector.dialect === 'trino') {
quoteChar = '"';
}

if (forceAppendBacktick) {
return identifier + '`';
return identifier + quoteChar;
}
const quoteChar =
(connector.dialect_properties && connector.dialect_properties.sql_identifier_quote) || '`';
if (identifier.indexOf(quoteChar) === 0) {

// Check if identifier is already quoted
if (identifier.startsWith(quoteChar) && identifier.endsWith(quoteChar)) {
return identifier;
}
// Check for multi-part identifiers (e.g., catalog.schema)
if (identifier.includes('.')) {
// Split the identifier into parts and quote each part separately
return identifier
.split('.')
.map(part => {
// Quote each part if it is not already quoted
if (part.startsWith(quoteChar) && part.endsWith(quoteChar)) {
return part;
} else {
return `${quoteChar}${part}${quoteChar}`;
}
})
.join('.');
}

const reservedKeywords = await (
sqlReferenceProvider || sqlReferenceRepository
).getReservedKeywords(connector.dialect || 'generic');
if (reservedKeywords.has(identifier.toUpperCase())) {
return quoteChar + identifier + quoteChar;
}

if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(identifier)) {
// Quote the identifier if it is a reserved keyword or not a valid SQL identifier
if (
reservedKeywords.has(identifier.toUpperCase()) ||
!/^[A-Za-z][A-Za-z0-9_]*$/.test(identifier)
) {
return quoteChar + identifier + quoteChar;
}

return identifier;
},
locationEquals: (a?: ParsedLocation, b?: ParsedLocation): boolean =>
Expand Down

0 comments on commit 4e5641e

Please sign in to comment.