Skip to content

Commit

Permalink
carto: columns support cleanup (#8413)
Browse files Browse the repository at this point in the history
* carto: fetchMap: support columns for verctorQuerySource
* carto: remove support for columns from spatial index sources
  • Loading branch information
zbigg committed Mar 11, 2024
1 parent a0abc74 commit 28fb60f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
11 changes: 8 additions & 3 deletions modules/carto/src/api/fetch-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,24 @@ async function _fetchMapDataset(
if (type === 'table') {
dataset.data = await vectorTableSource({...options, columns, tableName: source});
} else if (type === 'query') {
dataset.data = await vectorQuerySource({...options, sqlQuery: source, queryParameters});
dataset.data = await vectorQuerySource({
...options,
columns,
sqlQuery: source,
queryParameters
});
}
} else if (spatialDataType === 'h3') {
const options = {...globalOptions, aggregationExp, aggregationResLevel, spatialDataColumn};
if (type === 'table') {
dataset.data = await h3TableSource({...options, columns, tableName: source});
dataset.data = await h3TableSource({...options, tableName: source});
} else if (type === 'query') {
dataset.data = await h3QuerySource({...options, sqlQuery: source, queryParameters});
}
} else if (spatialDataType === 'quadbin') {
const options = {...globalOptions, aggregationExp, aggregationResLevel, spatialDataColumn};
if (type === 'table') {
dataset.data = await quadbinTableSource({...options, columns, tableName: source});
dataset.data = await quadbinTableSource({...options, tableName: source});
} else if (type === 'query') {
dataset.data = await quadbinQuerySource({...options, sqlQuery: source, queryParameters});
}
Expand Down
12 changes: 1 addition & 11 deletions modules/carto/src/sources/h3-table-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type H3TableSourceOptions = SourceOptions & TableSourceOptions & Aggregat
type UrlParameters = {
aggregationExp: string;
aggregationResLevel?: string;
columns?: string;
spatialDataType: SpatialDataType;
spatialDataColumn?: string;
name: string;
Expand All @@ -22,13 +21,7 @@ type UrlParameters = {
export const h3TableSource = async function (
options: H3TableSourceOptions
): Promise<TilejsonResult> {
const {
aggregationExp,
aggregationResLevel = 4,
columns,
spatialDataColumn = 'h3',
tableName
} = options;
const {aggregationExp, aggregationResLevel = 4, spatialDataColumn = 'h3', tableName} = options;
const urlParameters: UrlParameters = {
aggregationExp,
name: tableName,
Expand All @@ -39,8 +32,5 @@ export const h3TableSource = async function (
if (aggregationResLevel) {
urlParameters.aggregationResLevel = String(aggregationResLevel);
}
if (columns) {
urlParameters.columns = columns.join(',');
}
return baseSource<UrlParameters>('table', options, urlParameters) as Promise<TilejsonResult>;
};
5 changes: 0 additions & 5 deletions modules/carto/src/sources/quadbin-table-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type QuadbinTableSourceOptions = SourceOptions & TableSourceOptions & Agg
type UrlParameters = {
aggregationExp: string;
aggregationResLevel?: string;
columns?: string;
spatialDataType: SpatialDataType;
spatialDataColumn?: string;
name: string;
Expand All @@ -25,7 +24,6 @@ export const quadbinTableSource = async function (
const {
aggregationExp,
aggregationResLevel = 6,
columns,
spatialDataColumn = 'quadbin',
tableName
} = options;
Expand All @@ -40,8 +38,5 @@ export const quadbinTableSource = async function (
if (aggregationResLevel) {
urlParameters.aggregationResLevel = String(aggregationResLevel);
}
if (columns) {
urlParameters.columns = columns.join(',');
}
return baseSource<UrlParameters>('table', options, urlParameters) as Promise<TilejsonResult>;
};
16 changes: 9 additions & 7 deletions modules/carto/src/sources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ export type TableSourceOptions = {
*/
tableName: string;

/**
* Columns to retrieve from the table.
*
* If not present, all columns are returned.
*/
columns?: string[];

/**
* The column name and the type of geospatial support.
*
Expand All @@ -130,6 +123,15 @@ export type TilesetSourceOptions = {
tableName: string;
};

export type ColumnsOption = {
/**
* Columns to retrieve from the table.
*
* If not present, all columns are returned.
*/
columns?: string[];
};

export type SpatialDataType = 'geo' | 'h3' | 'quadbin';

export type TilejsonMapInstantiation = MapInstantiation & {
Expand Down
9 changes: 5 additions & 4 deletions modules/carto/src/sources/vector-query-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import type {
SourceOptions,
QuerySourceOptions,
SpatialDataType,
TilejsonResult
TilejsonResult,
ColumnsOption
} from './types';

export type VectorQuerySourceOptions = SourceOptions &
QuerySourceOptions &
FilterOptions & {
columns?: string[];
};
FilterOptions &
ColumnsOption;

type UrlParameters = {
columns?: string;
filters?: string;
Expand Down
6 changes: 5 additions & 1 deletion modules/carto/src/sources/vector-table-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
import {baseSource} from './base-source';
import type {
FilterOptions,
ColumnsOption,
SourceOptions,
SpatialDataType,
TableSourceOptions,
TilejsonResult
} from './types';

export type VectorTableSourceOptions = SourceOptions & TableSourceOptions & FilterOptions;
export type VectorTableSourceOptions = SourceOptions &
TableSourceOptions &
FilterOptions &
ColumnsOption;
type UrlParameters = {
columns?: string;
filters?: string;
Expand Down

0 comments on commit 28fb60f

Please sign in to comment.