Skip to content

Commit aa236b9

Browse files
committed
Use view for read_paruqt
1 parent 1c21473 commit aa236b9

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

tutorials/parquet.qmd

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,28 @@ Let's query Eric's parquet file using duckdb+parquet
99
//| output: false
1010
//
1111
12-
// Create a DuckDB instance
13-
db = DuckDBClient.of()
12+
parquet_path = 'https://storage.googleapis.com/opencontext-parquet/oc_isamples_pqg.parquet';
1413
15-
// Set the Parquet file path
16-
parquet_path = 'https://storage.googleapis.com/opencontext-parquet/oc_isamples_pqg.parquet'
14+
// Create a DuckDB instance
15+
db = {
16+
const instance = await DuckDBClient.of();
17+
await instance.query(`create view nodes as select * from read_parquet('${parquet_path}')`)
18+
return instance;
19+
}
1720
1821
row_count = {
19-
const result = await db.queryRow(`select count(*) as n from read_parquet('${parquet_path}');`);
22+
const result = await db.queryRow(`select count(*) as n from nodes;`);
2023
return result.n;
2124
}
2225
2326
results = {
24-
const data = await db.query(`SELECT COUNT(*) as count, otype FROM read_parquet('${parquet_path}') GROUP BY otype ORDER BY count DESC`);
27+
const data = await db.query(`SELECT COUNT(*) as count, otype FROM nodes GROUP BY otype ORDER BY count DESC`);
2528
document.getElementById("loading_1").hidden = true;
2629
return Inputs.table(data);
2730
}
2831
2932
rows1k = {
30-
const data = await db.query(`SELECT row_id, pid, otype, label FROM read_parquet('${parquet_path}') limit 1000`);
33+
const data = await db.query(`SELECT row_id, pid, otype, label FROM nodes limit 1000`);
3134
document.getElementById("loading_2").hidden = true;
3235
return Inputs.table(data);
3336
}

tutorials/parquet_cesium.qmd

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,22 @@ This page renders points from an iSamples parquet file on cesium using point pri
2424
```{ojs}
2525
//| output: false
2626
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIwNzk3NjkyMy1iNGI1LTRkN2UtODRiMy04OTYwYWE0N2M3ZTkiLCJpZCI6Njk1MTcsImlhdCI6MTYzMzU0MTQ3N30.e70dpNzOCDRLDGxRguQCC-tRzGzA-23Xgno5lNgCeB4';
27+
```
2728

29+
```{ojs}
30+
//| echo: false
2831
viewof parquet_path = Inputs.text({label:"Source", value:"https://storage.googleapis.com/opencontext-parquet/oc_isamples_pqg.parquet", width:"100%", submit:true});
2932
```
3033

3134
```{ojs}
3235
//| code-fold: true
33-
// Import Observable's libraries
34-
import {DuckDBClient} from "@observablehq/duckdb"
3536
3637
// Create a DuckDB instance
37-
db = DuckDBClient.of();
38+
db = {
39+
const instance = await DuckDBClient.of();
40+
await instance.query(`create view nodes as select * from read_parquet('${parquet_path}')`)
41+
return instance;
42+
}
3843
3944
4045
async function loadData(query, params=[], waiting_id=null) {
@@ -62,9 +67,13 @@ async function loadData(query, params=[], waiting_id=null) {
6267
6368
locations = {
6469
// get the content form the parquet file
65-
const query = `SELECT row_id, pid, latitude, longitude FROM read_parquet('${parquet_path}') WHERE otype='GeospatialCoordLocation'`;
70+
const query = `SELECT pid, latitude, longitude FROM nodes WHERE otype='GeospatialCoordLocation'`;
6671
const data = await loadData(query, [], "loading_1");
6772
73+
// Clear the existing PointPrimitiveCollection
74+
content.points.removeAll();
75+
//content.points = new Cesium.PointPrimitiveCollection();
76+
6877
// create point primitives for cesium display
6978
const scalar = new Cesium.NearFarScalar(1.5e2, 2, 8.0e6, 0.2);
7079
const color = Cesium.Color.PINK;
@@ -78,7 +87,6 @@ locations = {
7887
row.latitude, //latitude
7988
0,//randomCoordinateJitter(10.0, 10.0), //elevation, m
8089
),
81-
row_id: row.row_id,
8290
pixelSize: point_size,
8391
color: color,
8492
scaleByDistance: scalar,
@@ -109,7 +117,7 @@ function createShowPrimitive(viewer) {
109117
// If selectPoint is valid and no currently selected point
110118
if (Cesium.defined(selectPoint) && selectPoint.hasOwnProperty("primitive")) {
111119
//console.log(`showPrimitiveId ${selectPoint.id}`);
112-
const carto = Cesium.Cartographic.fromCartesian(selectPoint.primitive.position)
120+
//const carto = Cesium.Cartographic.fromCartesian(selectPoint.primitive.position)
113121
viewer.pointLabel.position = selectPoint.primitive.position;
114122
viewer.pointLabel.label.show = true;
115123
//viewer.pointLabel.label.text = `id:${selectPoint.id}, ${carto}`;
@@ -180,11 +188,19 @@ async function getGeoRecord(pid) {
180188
if (pid === null || pid ==="" || pid == "unset") {
181189
return "unset";
182190
}
183-
const q = `SELECT row_id, pid, otype, latitude, longitude FROM read_parquet('${parquet_path}') WHERE otype='GeospatialCoordLocation' AND pid=?`;
191+
const q = `SELECT row_id, pid, otype, latitude, longitude FROM nodes WHERE otype='GeospatialCoordLocation' AND pid=?`;
184192
const result = await db.queryRow(q, [pid]);
185193
return result;
186194
}
187195
196+
async function locationUsedBy(rowid){
197+
if (rowid === undefined || rowid === null) {
198+
return [];
199+
}
200+
const q = `select pid, otype from nodes where row_id in (select nodes.s from nodes where list_contains(nodes.o, ?));`;
201+
return db.query(q, [rowid]);
202+
}
203+
188204
mutable clickedPointId = "unset";
189205
selectedGeoRecord = await getGeoRecord(clickedPointId);
190206
@@ -229,3 +245,4 @@ ${JSON.stringify(selectedGeoRecord, null, 2)}
229245
`
230246
```
231247

248+

0 commit comments

Comments
 (0)