Skip to content

Commit cef6bba

Browse files
authored
getSqlEscapedSource: support for databricksRest provider (#913)
1 parent b510bcc commit cef6bba

File tree

5 files changed

+44
-32
lines changed

5 files changed

+44
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Not released
44

5+
- getSqlEscapedSource: support for databricksRest provider [#913](https://github.com/CartoDB/carto-react/pull/913)
56
- cache Intl instances to improve performance [#894](https://github.com/CartoDB/carto-react/pull/894)
67
- Support for `onRowMouseEnter` and `onRowMouseLeave` handlers for Table Widget [#907](https://github.com/CartoDB/carto-react/pull/907)
78

packages/react-core/src/operations/constants/Provider.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export const Provider = Object.freeze({
88
Redshift: 'redshift',
99
Postgres: 'postgres',
1010
Snowflake: 'snowflake',
11-
Databricks: 'databricks'
11+
Databricks: 'databricks',
12+
DatabricksRest: 'databricksRest'
1213
});

packages/react-core/src/operations/constants/Provider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ export enum Provider {
33
Redshift = 'redshift',
44
Postgres = 'postgres',
55
Snowflake = 'snowflake',
6-
Databricks = 'databricks'
7-
}
6+
Databricks = 'databricks',
7+
DatabricksRest = 'databricksRest'
8+
}

packages/react-widgets/__tests__/models/fqn.test.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ describe('FQN', () => {
12251225
});
12261226
});
12271227

1228-
describe('for Databricks', () => {
1228+
describe.each([Provider.Databricks, Provider.DatabricksRest])('for %s', (provider) => {
12291229
test.each([
12301230
[
12311231
'database.schema.table',
@@ -1289,6 +1289,14 @@ describe('FQN', () => {
12891289
quoted: [null, '`schema`', '`ta``bl``e`']
12901290
},
12911291
'database.`schema`.`ta``bl``e`'
1292+
],
1293+
[
1294+
'`carto-dev-data`.support_team.airports_rls_prepared',
1295+
{
1296+
unquoted: ['carto-dev-data', 'support_team', 'airports_rls_prepared'],
1297+
quoted: ['`carto-dev-data`', 'support_team', 'airports_rls_prepared']
1298+
},
1299+
'`carto-dev-data`.support_team.airports_rls_prepared'
12921300
]
12931301
])(
12941302
'should parse %p correctly',
@@ -1300,7 +1308,7 @@ describe('FQN', () => {
13001308
},
13011309
expectedFqn
13021310
) => {
1303-
const fqnObj = new FullyQualifiedName(fqn, Provider.Databricks);
1311+
const fqnObj = new FullyQualifiedName(fqn, provider);
13041312

13051313
expect(fqnObj.getObjectName()).toEqual(objectName);
13061314
expect(fqnObj.getObjectName({ quoted: true })).toEqual(
@@ -1338,11 +1346,7 @@ describe('FQN', () => {
13381346
])(
13391347
'should parse %p correctly in left to right parsing mode',
13401348
(fqn, databaseName, schemaName, objectName, expectedFqn) => {
1341-
const fqnObj = new FullyQualifiedName(
1342-
fqn,
1343-
Provider.Databricks,
1344-
ParsingMode.LeftToRight
1345-
);
1349+
const fqnObj = new FullyQualifiedName(fqn, provider, ParsingMode.LeftToRight);
13461350
expect(fqnObj.getDatabaseName()).toEqual(databaseName);
13471351
if (schemaName) {
13481352
expect(fqnObj.getSchemaName()).toEqual(schemaName);
@@ -1365,7 +1369,7 @@ describe('FQN', () => {
13651369
});
13661370

13671371
test('should set database / schema name correctly for an incomplete FQN', () => {
1368-
const fqnObj = new FullyQualifiedName('schema.table', Provider.Databricks);
1372+
const fqnObj = new FullyQualifiedName('schema.table', provider);
13691373
fqnObj.setDatabaseName('DAT_A-base');
13701374
fqnObj.setSchemaName('my_schema');
13711375
expect(fqnObj.getDatabaseName()).toEqual('DAT_A-base');
@@ -1382,7 +1386,7 @@ describe('FQN', () => {
13821386
])(
13831387
'should get object name correctly from %p with suffix %p',
13841388
(fqn, suffix, quotedName, unquotedName) => {
1385-
const fqnObj = new FullyQualifiedName(fqn, Provider.Databricks);
1389+
const fqnObj = new FullyQualifiedName(fqn, provider);
13861390
expect(fqnObj.getObjectName({ quoted: true, suffix: suffix })).toEqual(
13871391
quotedName
13881392
);
@@ -1395,7 +1399,7 @@ describe('FQN', () => {
13951399
test('should set object name correctly when it should be escaped', () => {
13961400
const fqnObj = new FullyQualifiedName(
13971401
'database.schema',
1398-
Provider.Databricks,
1402+
provider,
13991403
ParsingMode.LeftToRight
14001404
);
14011405
fqnObj.setObjectName('ta ".ble name');
@@ -1422,25 +1426,25 @@ describe('FQN', () => {
14221426
['`a`..`b`']
14231427
])('should never accept %p', (fqn) => {
14241428
expect(
1425-
FullyQualifiedName.isValid(fqn, Provider.Databricks, {
1429+
FullyQualifiedName.isValid(fqn, provider, {
14261430
parsingMode: ParsingMode.RightToLeft,
14271431
quoted: false
14281432
})
14291433
).toEqual(false);
14301434
expect(
1431-
FullyQualifiedName.isValid(fqn, Provider.Databricks, {
1435+
FullyQualifiedName.isValid(fqn, provider, {
14321436
parsingMode: ParsingMode.RightToLeft,
14331437
quoted: true
14341438
})
14351439
).toEqual(false);
14361440
expect(
1437-
FullyQualifiedName.isValid(fqn, Provider.Databricks, {
1441+
FullyQualifiedName.isValid(fqn, provider, {
14381442
parsingMode: ParsingMode.LeftToRight,
14391443
quoted: false
14401444
})
14411445
).toEqual(false);
14421446
expect(
1443-
FullyQualifiedName.isValid(fqn, Provider.Databricks, {
1447+
FullyQualifiedName.isValid(fqn, provider, {
14441448
parsingMode: ParsingMode.LeftToRight,
14451449
quoted: true
14461450
})
@@ -1458,25 +1462,25 @@ describe('FQN', () => {
14581462
['my table']
14591463
])('should should only accept quoted %p', (fqn) => {
14601464
expect(
1461-
FullyQualifiedName.isValid(fqn, Provider.Databricks, {
1465+
FullyQualifiedName.isValid(fqn, provider, {
14621466
parsingMode: ParsingMode.RightToLeft,
14631467
quoted: false
14641468
})
14651469
).toEqual(false);
14661470
expect(
1467-
FullyQualifiedName.isValid(fqn, Provider.Databricks, {
1471+
FullyQualifiedName.isValid(fqn, provider, {
14681472
parsingMode: ParsingMode.RightToLeft,
14691473
quoted: true
14701474
})
14711475
).toEqual(true);
14721476
expect(
1473-
FullyQualifiedName.isValid(fqn, Provider.Databricks, {
1477+
FullyQualifiedName.isValid(fqn, provider, {
14741478
parsingMode: ParsingMode.LeftToRight,
14751479
quoted: false
14761480
})
14771481
).toEqual(false);
14781482
expect(
1479-
FullyQualifiedName.isValid(fqn, Provider.Databricks, {
1483+
FullyQualifiedName.isValid(fqn, provider, {
14801484
parsingMode: ParsingMode.LeftToRight,
14811485
quoted: true
14821486
})
@@ -1492,25 +1496,25 @@ describe('FQN', () => {
14921496
['`a table`']
14931497
])('should always accept %p', (fqn) => {
14941498
expect(
1495-
FullyQualifiedName.isValid(fqn, Provider.Databricks, {
1499+
FullyQualifiedName.isValid(fqn, provider, {
14961500
parsingMode: ParsingMode.RightToLeft,
14971501
quoted: false
14981502
})
14991503
).toEqual(true);
15001504
expect(
1501-
FullyQualifiedName.isValid(fqn, Provider.Databricks, {
1505+
FullyQualifiedName.isValid(fqn, provider, {
15021506
parsingMode: ParsingMode.RightToLeft,
15031507
quoted: true
15041508
})
15051509
).toEqual(true);
15061510
expect(
1507-
FullyQualifiedName.isValid(fqn, Provider.Databricks, {
1511+
FullyQualifiedName.isValid(fqn, provider, {
15081512
parsingMode: ParsingMode.LeftToRight,
15091513
quoted: false
15101514
})
15111515
).toEqual(true);
15121516
expect(
1513-
FullyQualifiedName.isValid(fqn, Provider.Databricks, {
1517+
FullyQualifiedName.isValid(fqn, provider, {
15141518
parsingMode: ParsingMode.LeftToRight,
15151519
quoted: true
15161520
})

packages/react-widgets/src/models/fqn.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const bqProjectId = /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/;
99
const bqIdentifierRegex = '((?:[^`.]*?)|`(?:(?:[^`.])*?)`)';
1010
const identifierRegex = '((?:[^".]*?)|"(?:(?:[^"]|"")*?)")';
1111
const databricksIdentifierRegex = '((?:[^`.]*?)|`(?:(?:[^`]|``)*?)`)';
12+
const databricksFqnParseRegex = new RegExp(
13+
`^${databricksIdentifierRegex}(?:\\.${databricksIdentifierRegex})?(?:\\.${databricksIdentifierRegex})?$`
14+
);
1215
const fqnParseRegex = {
1316
[Provider.BigQuery]: new RegExp(
1417
`^\`?${bqIdentifierRegex}(?:\\.${bqIdentifierRegex})?(?:\\.${bqIdentifierRegex})?\`?$`
@@ -22,33 +25,34 @@ const fqnParseRegex = {
2225
[Provider.Redshift]: new RegExp(
2326
`^${identifierRegex}(?:\\.${identifierRegex})?(?:\\.${identifierRegex})?$`
2427
),
25-
[Provider.Databricks]: new RegExp(
26-
`^${databricksIdentifierRegex}(?:\\.${databricksIdentifierRegex})?(?:\\.${databricksIdentifierRegex})?$`
27-
)
28+
[Provider.Databricks]: databricksFqnParseRegex,
29+
[Provider.DatabricksRest]: databricksFqnParseRegex
2830
};
2931

3032
const escapeCharacter = {
3133
[Provider.BigQuery]: '`',
3234
[Provider.Postgres]: '"',
3335
[Provider.Snowflake]: '"',
3436
[Provider.Redshift]: '"',
35-
[Provider.Databricks]: '`'
37+
[Provider.Databricks]: '`',
38+
[Provider.DatabricksRest]: '`'
3639
};
3740

3841
const nameNeedsQuotesChecker = {
3942
[Provider.BigQuery]: /^[^a-z_]|[^a-z_\d]/i,
4043
[Provider.Postgres]: /^[^a-z_]|[^a-z_\d$]/i,
4144
[Provider.Snowflake]: /^[^a-z_]|[^a-z_\d$]/i,
4245
[Provider.Redshift]: /^[^a-z_]|[^a-z_\d$]/i,
43-
[Provider.Databricks]: /[^a-z_\d]/i
46+
[Provider.Databricks]: /[^a-z_\d]/i,
47+
[Provider.DatabricksRest]: /[^a-z_\d]/i
4448
};
45-
4649
const caseSensitivenessChecker = {
4750
[Provider.BigQuery]: null,
4851
[Provider.Postgres]: /[A-Z]/,
4952
[Provider.Snowflake]: /[a-z]/,
5053
[Provider.Redshift]: null,
51-
[Provider.Databricks]: null
54+
[Provider.Databricks]: null,
55+
[Provider.DatabricksRest]: null
5256
};
5357

5458
export class FullyQualifiedName {
@@ -384,6 +388,7 @@ export class FullyQualifiedName {
384388
switch (this.provider) {
385389
case Provider.BigQuery:
386390
case Provider.Databricks:
391+
case Provider.DatabricksRest:
387392
return unquotedName;
388393
case Provider.Postgres:
389394
return needsQuotes ? unquotedName : unquotedName.toLowerCase();

0 commit comments

Comments
 (0)