Spaces:
Running
Running
Refactor to avoid code duplication
Browse files- index.html +24 -39
index.html
CHANGED
|
@@ -119,28 +119,34 @@
|
|
| 119 |
return textTypes.some(t => type.toUpperCase().startsWith(t));
|
| 120 |
}
|
| 121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
// Detect columns and their types from the dataset
|
| 123 |
async function detectColumns(url) {
|
| 124 |
try {
|
| 125 |
setStatus('Detecting column types...', 'info');
|
| 126 |
|
| 127 |
-
//
|
| 128 |
-
|
| 129 |
-
await initDuckDB();
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
// Drop existing file registration if it exists
|
| 133 |
-
try {
|
| 134 |
-
await db.dropFile('data.parquet');
|
| 135 |
-
} catch {}
|
| 136 |
-
|
| 137 |
-
// Register the parquet file
|
| 138 |
-
await db.registerFileURL(
|
| 139 |
-
'data.parquet',
|
| 140 |
-
url,
|
| 141 |
-
duckdb.DuckDBDataProtocol.HTTP,
|
| 142 |
-
false
|
| 143 |
-
);
|
| 144 |
|
| 145 |
// Query to get column information
|
| 146 |
const result = await conn.query("DESCRIBE 'data.parquet'");
|
|
@@ -341,29 +347,8 @@
|
|
| 341 |
try {
|
| 342 |
submitBtn.disabled = true;
|
| 343 |
submitBtn.textContent = 'Loading...';
|
| 344 |
-
setStatus('Initializing DuckDB...', 'info');
|
| 345 |
-
|
| 346 |
-
// Initialize DuckDB if not already done
|
| 347 |
-
if (!db) {
|
| 348 |
-
await initDuckDB();
|
| 349 |
-
}
|
| 350 |
-
|
| 351 |
-
setStatus('Loading parquet file...', 'info');
|
| 352 |
-
|
| 353 |
-
// Drop existing file registration if it exists
|
| 354 |
-
try {
|
| 355 |
-
await db.dropFile('data.parquet');
|
| 356 |
-
} catch {}
|
| 357 |
-
|
| 358 |
-
// Register the parquet file from URL
|
| 359 |
-
await db.registerFileURL(
|
| 360 |
-
'data.parquet',
|
| 361 |
-
parquetUrl,
|
| 362 |
-
duckdb.DuckDBDataProtocol.HTTP,
|
| 363 |
-
false
|
| 364 |
-
);
|
| 365 |
|
| 366 |
-
//
|
| 367 |
currentDatasetUrl = parquetUrl;
|
| 368 |
await detectColumns(parquetUrl);
|
| 369 |
|
|
|
|
| 119 |
return textTypes.some(t => type.toUpperCase().startsWith(t));
|
| 120 |
}
|
| 121 |
|
| 122 |
+
// Load dataset: initialize DuckDB, drop old file, and register new parquet file
|
| 123 |
+
async function loadDataset(url) {
|
| 124 |
+
// Initialize DuckDB if not already done
|
| 125 |
+
if (!db) {
|
| 126 |
+
await initDuckDB();
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// Drop existing file registration if it exists
|
| 130 |
+
try {
|
| 131 |
+
await db.dropFile('data.parquet');
|
| 132 |
+
} catch {}
|
| 133 |
+
|
| 134 |
+
// Register the parquet file from URL
|
| 135 |
+
await db.registerFileURL(
|
| 136 |
+
'data.parquet',
|
| 137 |
+
url,
|
| 138 |
+
duckdb.DuckDBDataProtocol.HTTP,
|
| 139 |
+
false
|
| 140 |
+
);
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
// Detect columns and their types from the dataset
|
| 144 |
async function detectColumns(url) {
|
| 145 |
try {
|
| 146 |
setStatus('Detecting column types...', 'info');
|
| 147 |
|
| 148 |
+
// Load the dataset
|
| 149 |
+
await loadDataset(url);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
// Query to get column information
|
| 152 |
const result = await conn.query("DESCRIBE 'data.parquet'");
|
|
|
|
| 347 |
try {
|
| 348 |
submitBtn.disabled = true;
|
| 349 |
submitBtn.textContent = 'Loading...';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
|
| 351 |
+
// Load dataset and detect columns
|
| 352 |
currentDatasetUrl = parquetUrl;
|
| 353 |
await detectColumns(parquetUrl);
|
| 354 |
|