@uwdata/mosaic-core
Advanced tools
Comparing version 0.6.1 to 0.7.0
{ | ||
"name": "@uwdata/mosaic-core", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "Scalable and extensible linked data views.", | ||
@@ -31,7 +31,7 @@ "keywords": [ | ||
"dependencies": { | ||
"@duckdb/duckdb-wasm": "^1.28.1-dev106.0", | ||
"@uwdata/mosaic-sql": "^0.6.0", | ||
"@duckdb/duckdb-wasm": "^1.28.1-dev109.0", | ||
"@uwdata/mosaic-sql": "^0.7.0", | ||
"apache-arrow": "^15.0.0" | ||
}, | ||
"gitHead": "9e788e6dc5241fa1c54967a25fd9599f97da1a41" | ||
"gitHead": "4680b922f15579b7b527f31507ed71a12230ec35" | ||
} |
import { socketConnector } from './connectors/socket.js'; | ||
import { Catalog } from './Catalog.js'; | ||
import { FilterGroup } from './FilterGroup.js'; | ||
import { QueryManager, Priority } from './QueryManager.js'; | ||
import { queryFieldInfo } from './util/field-info.js'; | ||
import { voidLogger } from './util/void-logger.js'; | ||
@@ -30,3 +30,2 @@ | ||
} = options; | ||
this.catalog = new Catalog(this); | ||
this.manager = manager; | ||
@@ -53,3 +52,3 @@ this.logger(logger); | ||
clear({ clients = true, cache = true, catalog = false } = {}) { | ||
clear({ clients = true, cache = true } = {}) { | ||
this.manager.clear(); | ||
@@ -63,3 +62,2 @@ if (clients) { | ||
if (cache) this.manager.cache().clear(); | ||
if (catalog) this.catalog.clear(); | ||
} | ||
@@ -128,3 +126,3 @@ | ||
async connect(client) { | ||
const { catalog, clients, filterGroups, indexes } = this; | ||
const { clients, filterGroups, indexes } = this; | ||
@@ -140,3 +138,3 @@ if (clients.has(client)) { | ||
if (fields?.length) { | ||
client.fieldInfo(await catalog.queryFields(fields)); | ||
client.fieldInfo(await queryFieldInfo(this, fields)); | ||
} | ||
@@ -143,0 +141,0 @@ |
@@ -11,4 +11,10 @@ export { MosaicClient } from './MosaicClient.js'; | ||
export { | ||
isArrowTable, | ||
convertArrowArrayType, | ||
convertArrowValue, | ||
convertArrowColumn | ||
} from './util/convert-arrow.js' | ||
export { distinct } from './util/distinct.js'; | ||
export { synchronizer } from './util/synchronizer.js'; | ||
export { throttle } from './util/throttle.js'; |
@@ -1,2 +0,2 @@ | ||
import { Query, Ref } from '@uwdata/mosaic-sql'; | ||
import { Query, Ref, isDescribeQuery } from '@uwdata/mosaic-sql'; | ||
import { queryResult } from './util/query-result.js'; | ||
@@ -128,3 +128,3 @@ | ||
record: false, | ||
query: consolidatedQuery(group, record) | ||
query: (group.query = consolidatedQuery(group, record)) | ||
}, | ||
@@ -196,3 +196,3 @@ result: (group.result = queryResult()) | ||
// update select statemenet and return | ||
// update select statement and return | ||
return query.$select(Array.from(fields.values())); | ||
@@ -207,5 +207,9 @@ } | ||
async function processResults(group, cache) { | ||
const { maps, result } = group; | ||
if (!maps) return; // no consolidation performed | ||
const { maps, query, result } = group; | ||
// exit early if no consolidation performed | ||
// in this case results are passed directly | ||
if (!maps) return; | ||
// await consolidated query result, pass errors if needed | ||
let data; | ||
@@ -222,9 +226,15 @@ try { | ||
// extract result for each query in the consolidation group | ||
// update cache and pass extract to original issuer | ||
const describe = isDescribeQuery(query); | ||
group.forEach(({ entry }, index) => { | ||
const { request, result } = entry; | ||
const projected = projectResult(data, maps[index]); | ||
const map = maps[index]; | ||
const extract = describe && map ? filterResult(data, map) | ||
: map ? projectResult(data, map) | ||
: data; | ||
if (request.cache) { | ||
cache.set(String(request.query), projected); | ||
cache.set(String(request.query), extract); | ||
} | ||
result.fulfill(projected); | ||
result.fulfill(extract); | ||
}); | ||
@@ -240,11 +250,24 @@ } | ||
function projectResult(data, map) { | ||
if (map) { | ||
const cols = {}; | ||
for (const [name, as] of map) { | ||
cols[as] = data.getChild(name); | ||
const cols = {}; | ||
for (const [name, as] of map) { | ||
cols[as] = data.getChild(name); | ||
} | ||
return new data.constructor(cols); | ||
} | ||
/** | ||
* Filter a consolidated describe query result to a client result | ||
* @param {*} data Consolidated query result | ||
* @param {*} map Column name map as [source, target] pairs | ||
* @returns the filtered table data | ||
*/ | ||
function filterResult(data, map) { | ||
const lookup = new Map(map); | ||
const result = []; | ||
for (const d of data) { | ||
if (lookup.has(d.column_name)) { | ||
result.push({ ...d, column_name: lookup.get(d.column_name) }) | ||
} | ||
return new data.constructor(cols); | ||
} else { | ||
return data; | ||
} | ||
return result; | ||
} |
@@ -15,3 +15,2 @@ export function jsType(type) { | ||
case 'REAL': | ||
case 'DECIMAL': | ||
return 'number'; | ||
@@ -30,2 +29,3 @@ case 'DATE': | ||
return 'string'; | ||
case 'ARRAY': | ||
case 'LIST': | ||
@@ -36,6 +36,14 @@ return 'array'; | ||
case 'MAP': | ||
case 'GEOMETRY': | ||
return 'object'; | ||
default: | ||
if (type.startsWith('DECIMAL')) { | ||
return 'number'; | ||
} else if (type.startsWith('STRUCT') || type.startsWith('MAP')) { | ||
return 'object'; | ||
} else if (type.endsWith(']')) { | ||
return 'array'; | ||
} | ||
throw new Error(`Unsupported type: ${type}`); | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
1378766
29358
1
+ Added@uwdata/mosaic-sql@0.7.0(transitive)
- Removed@uwdata/mosaic-sql@0.6.0(transitive)
Updated@uwdata/mosaic-sql@^0.7.0