Skip to content

Commit

Permalink
Merge branch 'master' into bug/sc-365844/eqt-partners-carto-3-account…
Browse files Browse the repository at this point in the history
…-map-breaks-on
  • Loading branch information
VictorVelarde authored Nov 23, 2023
2 parents 06cf5d4 + 5f07195 commit 79d500c
Show file tree
Hide file tree
Showing 15 changed files with 494 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/react-api/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export { executeModel as _executeModel } from './api/model';
export { default as FeaturesDroppedLoader } from './hooks/FeaturesDroppedLoader';
export { default as useCartoLayerProps } from './hooks/useCartoLayerProps';

export { Credentials, UseCartoLayerFilterProps } from './types';
export { Credentials, UseCartoLayerFilterProps, SourceProps } from './types';
3 changes: 2 additions & 1 deletion packages/react-api/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DataFilterExtension, MaskExtension } from '@deck.gl/extensions/typed';
import { MAP_TYPES, API_VERSIONS } from '@deck.gl/carto/typed';
import { QueryParameters } from '@deck.gl/carto/typed';
import { FeatureCollection } from 'geojson';
import { Provider } from '@carto/react-core';

type ApiVersionsType = typeof API_VERSIONS;
type MapTypesType = typeof MAP_TYPES;
Expand Down Expand Up @@ -34,7 +35,7 @@ export type SourceProps = {
aggregationExp?: string;
credentials?: Credentials;
queryParameters?: QueryParameters;
provider?: 'bigquery' | 'postgres' | 'snowflake' | 'redshift' | 'databricks';
provider?: Provider;
};

export type LayerConfig = {
Expand Down
2 changes: 2 additions & 0 deletions packages/react-core/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export { groupValuesByColumn } from './operations/groupBy';
export { histogram } from './operations/histogram';
export { scatterPlot } from './operations/scatterPlot';

export { Provider } from './operations/constants/Provider'

export { FilterTypes as _FilterTypes } from './filters/FilterTypes';

export {
Expand Down
2 changes: 2 additions & 0 deletions packages/react-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export { groupValuesByColumn } from './operations/groupBy';
export { histogram } from './operations/histogram';
export { scatterPlot } from './operations/scatterPlot';

export { Provider } from './operations/constants/Provider';

export { FilterTypes as _FilterTypes } from './filters/FilterTypes';

export {
Expand Down
12 changes: 12 additions & 0 deletions packages/react-core/src/operations/constants/Provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Enum for the different connections providers
* @enum {string}
* @readonly
*/
export const Provider = Object.freeze({
BigQuery: 'bigquery',
Redshift: 'redshift',
Postgres: 'postgres',
Snowflake: 'snowflake',
Databricks: 'databricks'
});
7 changes: 7 additions & 0 deletions packages/react-core/src/operations/constants/Provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum Provider {
BigQuery = 'bigquery',
Redshift = 'redshift',
Postgres = 'postgres',
Snowflake = 'snowflake',
Databricks = 'databricks'
}
14 changes: 10 additions & 4 deletions packages/react-redux/src/slices/cartoSlice.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { Credentials } from '@carto/react-api/';
import { SourceProps } from '@carto/react-api/types';
import { Credentials, SourceProps } from '@carto/react-api/';
import { FiltersLogicalOperators, Viewport, _FilterTypes } from '@carto/react-core';
import { CartoBasemapsNames, GMapsBasemapsNames } from '@carto/react-basemaps/';
import { InitialCartoState, CartoState, ViewState } from '../types';
import { AnyAction, Reducer } from 'redux';
import { Feature, Polygon, MultiPolygon } from 'geojson';

type FilterValues = string[] | number[] | number[][]

export type SourceFilters = {
[column: string]: Partial<Record<_FilterTypes, { values: FilterValues; owner?: string; params?: Record<string, unknown>; }>>
}

type Source = SourceProps & {
id: string;
filters?: any;
filters?: SourceFilters;
filtersLogicalOperator?: FiltersLogicalOperators;
isDroppingFeatures?: boolean;
};
Expand All @@ -23,7 +28,7 @@ type BasemapName = CartoBasemapsNames | GMapsBasemapsNames;

type FilterBasic = {
type: _FilterTypes;
values: string[] | number[] | number[][];
values: FilterValues;
owner?: string;
params?: Record<string, unknown>;
};
Expand All @@ -41,6 +46,7 @@ type SpatialFilter = {

type Filter = FilterBasic & FilterCommonProps;


type FeaturesData = {
sourceId: string;
features: [];
Expand Down
3 changes: 3 additions & 0 deletions packages/react-redux/src/slices/cartoSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export const createCartoSlice = (initialState) => {
* @param {string} data.type - type of source. Possible values are sql or bigquery.
* @param {object=} data.credentials - (optional) Custom credentials to be used in the source.
* @param {string} data.connection - connection name for CARTO 3 source.
* @param {import('./cartoSlice').SourceFilters=} data.filters - logical operator that defines how filters for different columns are joined together.
* @param {FiltersLogicalOperators=} data.filtersLogicalOperator - logical operator that defines how filters for different columns are joined together.
* @param {import('@deck.gl/carto/typed').QueryParameters} data.queryParameters - SQL query parameters.
* @param {string=} data.geoColumn - (optional) name of column containing geometries or spatial index data.
Expand All @@ -218,6 +219,7 @@ export const addSource = ({
type,
credentials,
connection,
filters = undefined,
filtersLogicalOperator = FiltersLogicalOperators.AND,
queryParameters = [],
geoColumn,
Expand All @@ -231,6 +233,7 @@ export const addSource = ({
type,
credentials,
connection,
...(filters && { filters }),
filtersLogicalOperator,
queryParameters,
geoColumn,
Expand Down
21 changes: 11 additions & 10 deletions packages/react-widgets/__tests__/models/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { MAP_TYPES, API_VERSIONS } from '@deck.gl/carto';
import {
formatTableNameWithFilters,
sourceAndFiltersToSQL,
wrapModelCall,
formatOperationColumn,
normalizeObjectKeys
} from '../../src/models/utils';
import { AggregationTypes, _filtersToSQL } from '@carto/react-core';
import { AggregationTypes, Provider, _filtersToSQL } from '@carto/react-core';

const V2_SOURCE = {
id: '__test__',
Expand All @@ -22,7 +22,8 @@ const V3_SOURCE = {
data: '__test__',
credentials: {
apiVersion: API_VERSIONS.V3
}
},
provider: Provider.BigQuery
};

const SOURCE_WITH_FILTERS = {
Expand Down Expand Up @@ -89,29 +90,29 @@ describe('utils', () => {
});
});

describe('formatTableNameWithFilters', () => {
describe('sourceAndFiltersToSQL', () => {
test('should format query sources correctly', () => {
const source = {
...V3_SOURCE,
type: MAP_TYPES.QUERY,
data: 'SELECT * FROM test;'
};
const query = formatTableNameWithFilters({ source });
const query = sourceAndFiltersToSQL(source);

expect(query).toBe(`(SELECT * FROM test) foo`);
expect(query).toBe(`SELECT * FROM (SELECT * FROM test) __source_query `);
});

test('should format table sources correctly', () => {
const query = formatTableNameWithFilters({ source: V3_SOURCE });
const query = sourceAndFiltersToSQL(V3_SOURCE);

expect(query).toBe(V3_SOURCE.data);
expect(query).toBe(`SELECT * FROM \`${V3_SOURCE.data}\` `);
});

test('should format source with filters correctly', () => {
const query = formatTableNameWithFilters({ source: SOURCE_WITH_FILTERS });
const query = sourceAndFiltersToSQL(SOURCE_WITH_FILTERS);

expect(query).toBe(
`${SOURCE_WITH_FILTERS.data} WHERE (column_1 in('value_1','value_2'))`
`SELECT * FROM \`${SOURCE_WITH_FILTERS.data}\` WHERE (column_1 in('value_1','value_2'))`
);
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/react-widgets/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ export { default as FeatureSelectionWidget } from './widgets/FeatureSelectionWid
export { default as FeatureSelectionLayer } from './layers/FeatureSelectionLayer';
export { default as useGeocoderWidgetController } from './hooks/useGeocoderWidgetController';
export { WidgetState, WidgetStateType } from './types';
export { isRemoteCalculationSupported as _isRemoteCalculationSupported, sourceAndFiltersToSQL as _sourceAndFiltersToSQL } from './models/utils';
5 changes: 4 additions & 1 deletion packages/react-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ export { default as useSourceFilters } from './hooks/useSourceFilters';
export { default as FeatureSelectionLayer } from './layers/FeatureSelectionLayer';
export { default as useGeocoderWidgetController } from './hooks/useGeocoderWidgetController';
export { WidgetStateType } from './hooks/useWidgetFetch';
export { isRemoteCalculationSupported as _isRemoteCalculationSupported } from './models/utils';
export {
isRemoteCalculationSupported as _isRemoteCalculationSupported,
sourceAndFiltersToSQL as _sourceAndFiltersToSQL
} from './models/utils';
69 changes: 69 additions & 0 deletions packages/react-widgets/src/models/fqn.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Provider } from "@carto/react-core"

export type Fragment = {
name: string,
quoted: boolean
}
export type GetIdentifierOptions = {
quoted?: boolean,
safe?: boolean
}

export type GetObjectIdentifierOptions = GetIdentifierOptions & {
suffix?: string
}

export enum ParsingMode {
LeftToRight = 'leftToRight',
RightToLeft = 'rightToLeft'
}

export class FullyQualifiedName {
protected databaseFragment: Fragment | null
protected schemaFragment: Fragment | null
protected objectFragment: Fragment | null

protected provider: Provider
protected originalFQN: string
protected parsingMode: ParsingMode

static empty (provider: Provider, mode: ParsingMode): FullyQualifiedName

constructor (fqn: string, provider: Provider, mode?: ParsingMode)

public toString (): string

public getDatabaseName<Safe extends boolean> (options: { quoted?: boolean, safe: Safe }): Safe extends true ? string | null : string
public getDatabaseName (options?: GetIdentifierOptions): string
public getDatabaseName (options?: GetIdentifierOptions): string | null

public getSchemaName<Safe extends boolean> (options: { quoted?: boolean, safe: Safe }): Safe extends true ? string | null : string
public getSchemaName (options?: GetIdentifierOptions): string
public getSchemaName (options?: GetIdentifierOptions): string | null

public getObjectName<Safe extends boolean> (options: { quoted?: boolean, safe: Safe, suffix?: string }): Safe extends true ? string | null : string
public getObjectName (options?: GetObjectIdentifierOptions): string
public getObjectName (options?: GetObjectIdentifierOptions): string | null | boolean

public setDatabaseName (databaseName: string): void

public setSchemaName (schemaName: string): void

public setObjectName (objectName: string): void

private parseFQN (fqn: string): Array<Fragment | null>

private getFragmentName (fragment: Fragment): string

private quoteFragmentName (fragment: Fragment, suffix): string

private unquoteFragmentName (fragment: Fragment, suffix): string

private isQuotedName (name: string): boolean

private quoteName (name: string): string

private unquoteName (name: string, onlyDelimiters): string

private quoteExternalIdentifier (identifier: string): string
}
Loading

0 comments on commit 79d500c

Please sign in to comment.