|
1 | 1 | import { DurableObject } from "cloudflare:workers"; |
2 | 2 | import type { ColumnMeta, DataType, Env, ExplainResult, FilterOp, Footer, Row, TableMeta, DatasetMeta, IcebergDatasetMeta, QueryResult } from "./types.js"; |
3 | | -import { queryReferencedColumns } from "./types.js"; |
| 3 | +import { queryReferencedColumns, NULL_SENTINEL } from "./types.js"; |
4 | 4 | import type { QueryDescriptor } from "./client.js"; |
5 | 5 | import { parseFooter, parseColumnMetaFromProtobuf } from "./footer.js"; |
6 | 6 | import { parseManifest, logicalTypeToDataType } from "./manifest.js"; |
@@ -677,11 +677,12 @@ export class QueryDO extends DurableObject<Env> { |
677 | 677 | if (query.groupBy) for (const g of query.groupBy) { feed(g); feed("\0"); } |
678 | 678 | if (query.distinct) for (const d of query.distinct) { feed(d); feed("\0"); } |
679 | 679 | if (query.windows) for (const w of query.windows) { |
680 | | - feed(w.fn); feed("\0"); feed(w.alias); feed("\0"); feed(w.column ?? ""); feed("\0"); |
| 680 | + feed(w.fn); feed("\0"); feed(w.alias); feed("\0"); feed(w.column ?? NULL_SENTINEL); feed("\0"); |
681 | 681 | if (w.partitionBy) for (const p of w.partitionBy) { feed(p); feed("\0"); } |
682 | 682 | if (w.orderBy) for (const o of w.orderBy) { feed(o.column); feed(o.direction); feed("\0"); } |
683 | 683 | if (w.frame) { feed(w.frame.type); feed(String(w.frame.start)); feed(String(w.frame.end)); feed("\0"); } |
684 | 684 | if (w.args?.offset !== undefined) { feed(String(w.args.offset)); feed("\0"); } |
| 685 | + if (w.args?.default_ !== undefined) { feed(String(w.args.default_)); feed("\0"); } |
685 | 686 | } |
686 | 687 | if (query.computedColumns) for (const cc of query.computedColumns) { feed(cc.alias); feed("\0"); } |
687 | 688 | if (query.setOperation) { feed(query.setOperation.mode); feed("\0"); feed(this.queryKey(query.setOperation.right)); feed("\0"); } |
@@ -1523,7 +1524,7 @@ export class QueryDO extends DurableObject<Env> { |
1523 | 1524 | const listed = await this.r2(prefix).list({ prefix: `${prefix}_versions/`, limit: 100 }); |
1524 | 1525 | const manifestKeys = listed.objects |
1525 | 1526 | .filter(o => o.key.endsWith(".manifest")) |
1526 | | - .sort((a, b) => a.key.localeCompare(b.key)); |
| 1527 | + .sort((a, b) => { const na = parseInt(a.key.split("/").pop()!); const nb = parseInt(b.key.split("/").pop()!); return na - nb; }); |
1527 | 1528 | if (manifestKeys.length === 0) continue; |
1528 | 1529 |
|
1529 | 1530 | // Read latest manifest |
@@ -1675,7 +1676,7 @@ export class QueryDO extends DurableObject<Env> { |
1675 | 1676 | const listed = await this.r2(prefix).list({ prefix: `${prefix}metadata/`, limit: 100 }); |
1676 | 1677 | const metadataKeys = listed.objects |
1677 | 1678 | .filter(o => o.key.endsWith(".metadata.json")) |
1678 | | - .sort((a, b) => a.key.localeCompare(b.key)); |
| 1679 | + .sort((a, b) => { const na = parseInt(a.key.split("/").pop()!); const nb = parseInt(b.key.split("/").pop()!); return na - nb; }); |
1679 | 1680 | if (metadataKeys.length === 0) continue; |
1680 | 1681 |
|
1681 | 1682 | const latestKey = metadataKeys[metadataKeys.length - 1].key; |
|
0 commit comments