MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / mapboxFilterToCqlFilter

Function mapboxFilterToCqlFilter

src/common/util/FilterCondition.js:102–172  ·  view source on GitHub ↗
(filter, dataType)

Source from the content-addressed store, hash-verified

100}
101
102function mapboxFilterToCqlFilter(filter, dataType) {
103 if (!isSimpleComparison(filter)) {
104 return '';
105 }
106 const [operator, ...operands] = filter;
107 const field = dataType === 'STRUCTURE_DATA' ? `"${operands[0]}"` : operands[0];
108 let value;
109 switch (operator) {
110 case '>':
111 case '>=':
112 case '<':
113 case '<=': {
114 value = operands[1];
115 return `${field} ${operator} ${formatValue(value)}`;
116 }
117 case '==': {
118 value = operands[1];
119 if (isNullvalue(value)) {
120 return `${field} IS NULL`;
121 }
122 return `${field} = ${formatValue(value)}`;
123 }
124 case '!=': {
125 value = operands[1];
126 if (isNullvalue(value)) {
127 return `${field} IS NOT NULL`;
128 }
129 return `${field} <> ${formatValue(value)}`;
130 }
131 case 'in': {
132 const values = operands.slice(1);
133 return `${field} IN (${values.map((v) => formatValue(v)).join(', ')})`;
134 }
135 case '!in': {
136 const values = operands.slice(1);
137 return `${field} NOT IN (${values.map((v) => formatValue(v)).join(', ')})`;
138 }
139 // TODO
140 // case 'has': {
141 // const field = operands[0];
142 // return tableFieldNames?.includes(field) ? '1=1' : '1=0';
143 // }
144 // case '!has': {
145 // const field = operands[0];
146 // return tableFieldNames?.includes(field) ? '1=0' : '1=1';
147 // }
148 case 'all': {
149 return operands
150 .map((item) => mapboxFilterToCqlFilter(item, dataType))
151 .filter(Boolean)
152 .map((item) => `${item}`)
153 .join(' AND ');
154 }
155 case 'any': {
156 return operands
157 .map((item) => mapboxFilterToCqlFilter(item, dataType))
158 .filter(Boolean)
159 .map((item) => `(${item})`)

Callers 1

Calls 5

isSimpleComparisonFunction · 0.85
formatValueFunction · 0.85
isNullvalueFunction · 0.85
mapMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected