isaacbrodsky / h3-duckdb

Bindings for H3 to DuckDB
Apache License 2.0
173 stars 9 forks source link

Cannot install extension using `install 'h3ext' from '...';` syntax #95

Closed isaacbrodsky closed 5 months ago

isaacbrodsky commented 8 months ago
D install 'h3ext' from 'http://pub-cc26a6fd5d8240078bd0c2e0623393a5.r2.dev';
HTTP Error: Failed to download extension "h3ext" at URL "http://pub-cc26a6fd5d8240078bd0c2e0623393a5.r2.dev/v0.10.1/linux_amd64/h3ext.duckdb_extension.gz"

Candidate extensions: "s3", "http", "inet"

Perhaps this is because Cloudflare always redirects to HTTPS, and DuckDB does not support HTTPS? Trying to download from the same URL with scheme https gets misdetected as a local file path.

I think what is happening here is that DuckDB has an assumption that extensions are distributed via S3 and that S3 does not enforce HTTPS.

Depends on https://github.com/duckdb/duckdb/issues/9835

jcolot commented 7 months ago

@isaacbrodsky It seems to work now, I tried from a build of latest source of duckdb, replaced in the examples esbuild-browser with this index.html:

` // @ts-nocheck import as duckdb from '@duckdb/duckdb-wasm'; import as arrow from 'apache-arrow';

(async () => { try { const DUCKDB_CONFIG = await duckdb.selectBundle({ mvp: { mainModule: './duckdb-mvp.wasm', mainWorker: './duckdb-browser-mvp.worker.js', }, eh: { mainModule: './duckdb-eh.wasm', mainWorker: './duckdb-browser-eh.worker.js', }, coi: { mainModule: './duckdb-coi.wasm', mainWorker: './duckdb-browser-coi.worker.js', pthreadWorker: './duckdb-browser-coi.pthread.worker.js', }, });

    const logger = new duckdb.ConsoleLogger();
    const worker = new Worker(DUCKDB_CONFIG.mainWorker!);
    const db = new duckdb.AsyncDuckDB(logger, worker);
    await db.instantiate(DUCKDB_CONFIG.mainModule, DUCKDB_CONFIG.pthreadWorker);
    await db.open({allowUnsignedExtensions: true});
    const conn = await db.connect();
    window.conn = conn;
    await conn.query(`SET custom_extension_repository='https://storage.googleapis.com/duckdb-extensions';`);
    await conn.query(`LOAD h3ext;`);
    await conn.query(`INSTALL h3ext;`);
    const result = await conn.query(`SELECT h3_cell_to_latlng('85283473fffffff') as lat_lng`);
    const latLng = result.toArray()[0].toJSON().lat_lng;
    var div = document.createElement('div');
    div.innerHTML = latLng;
    document.body.appendChild(div); // Append the div to the body
} catch (e) {
    var div = document.createElement('div');
    div.innerHTML = JSON.stringify(e); // Assuming you want the same message in the catch block
    document.body.appendChild(div); // Append the error div to the body
    console.error(e);
}

})(); `

srstsavage commented 5 months ago

I can confirm this works with h3-duckdb 1.0.0 using the python client:

import duckdb

duckdb.sql("INSTALL h3ext FROM 'https://pub-cc26a6fd5d8240078bd0c2e0623393a5.r2.dev'")

con = duckdb.connect(config = {"allow_unsigned_extensions": "true"})
con.load_extension("h3ext")
con.sql("SELECT h3_cell_to_latlng(cast(586265647244115967 as ubigint));").show()

output:

┌────────────────────────────────────────────────────────┐
│ h3_cell_to_latlng(CAST(586265647244115967 AS UBIGINT)) │
│                        double[]                        │
├────────────────────────────────────────────────────────┤
│ [44.104731208541175, 41.04892671698865]                │
└────────────────────────────────────────────────────────┘

Also thanks so much, this project is awesome!

isaacbrodsky commented 5 months ago

Thanks for confirming @srstsavage !