@nshiab/simple-data-analysis-core 0.0.26 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/esm/class/SimpleDB.d.ts +3 -8
  2. package/esm/class/SimpleDB.d.ts.map +1 -1
  3. package/esm/class/SimpleDB.js +8 -10
  4. package/esm/class/SimpleTable.d.ts +61 -51
  5. package/esm/class/SimpleTable.d.ts.map +1 -1
  6. package/esm/class/SimpleTable.js +132 -188
  7. package/esm/helpers/convertForJS.js +1 -1
  8. package/esm/helpers/findGeoColumn.js +2 -2
  9. package/esm/helpers/hasGeometryColumn.js +1 -1
  10. package/esm/helpers/logData.d.ts.map +1 -1
  11. package/esm/helpers/logData.js +7 -2
  12. package/esm/helpers/parseTypes.d.ts +1 -1
  13. package/esm/helpers/parseTypes.d.ts.map +1 -1
  14. package/esm/helpers/parseTypes.js +3 -1
  15. package/esm/helpers/setDbProps.d.ts +1 -1
  16. package/esm/helpers/setDbProps.d.ts.map +1 -1
  17. package/esm/helpers/setDbProps.js +5 -9
  18. package/esm/helpers/unifyColumns.d.ts +0 -2
  19. package/esm/helpers/unifyColumns.d.ts.map +1 -1
  20. package/esm/helpers/unifyColumns.js +2 -6
  21. package/esm/helpers/writeGeoData.d.ts.map +1 -1
  22. package/esm/helpers/writeGeoData.js +11 -41
  23. package/esm/helpers/writeIndexes.d.ts +3 -0
  24. package/esm/helpers/writeIndexes.d.ts.map +1 -0
  25. package/esm/helpers/writeIndexes.js +16 -0
  26. package/esm/methods/bm25.d.ts.map +1 -1
  27. package/esm/methods/bm25.js +1 -1
  28. package/esm/methods/cache.js +1 -1
  29. package/esm/methods/distanceQuery.d.ts.map +1 -1
  30. package/esm/methods/distanceQuery.js +4 -2
  31. package/esm/methods/fuzzyJoin.d.ts.map +1 -1
  32. package/esm/methods/fuzzyJoin.js +1 -6
  33. package/esm/methods/getGeoData.d.ts.map +1 -1
  34. package/esm/methods/getGeoData.js +1 -10
  35. package/esm/methods/getNbRows.d.ts +3 -1
  36. package/esm/methods/getNbRows.d.ts.map +1 -1
  37. package/esm/methods/getNbRows.js +5 -5
  38. package/esm/methods/join.d.ts.map +1 -1
  39. package/esm/methods/join.js +1 -7
  40. package/esm/methods/joinGeo.d.ts.map +1 -1
  41. package/esm/methods/joinGeo.js +1 -14
  42. package/esm/methods/joinGeoQuery.js +1 -1
  43. package/esm/methods/randomPointQuery.d.ts.map +1 -1
  44. package/esm/methods/randomPointQuery.js +60 -22
  45. package/esm/methods/summarizeQuery.js +1 -1
  46. package/esm/methods/writeGeoDataQuery.js +2 -2
  47. package/package.json +2 -2
  48. package/script/class/SimpleDB.d.ts +3 -8
  49. package/script/class/SimpleDB.d.ts.map +1 -1
  50. package/script/class/SimpleDB.js +8 -10
  51. package/script/class/SimpleTable.d.ts +61 -51
  52. package/script/class/SimpleTable.d.ts.map +1 -1
  53. package/script/class/SimpleTable.js +132 -188
  54. package/script/helpers/convertForJS.js +1 -1
  55. package/script/helpers/findGeoColumn.js +2 -2
  56. package/script/helpers/hasGeometryColumn.js +1 -1
  57. package/script/helpers/logData.d.ts.map +1 -1
  58. package/script/helpers/logData.js +7 -2
  59. package/script/helpers/parseTypes.d.ts +1 -1
  60. package/script/helpers/parseTypes.d.ts.map +1 -1
  61. package/script/helpers/parseTypes.js +3 -1
  62. package/script/helpers/setDbProps.d.ts +1 -1
  63. package/script/helpers/setDbProps.d.ts.map +1 -1
  64. package/script/helpers/setDbProps.js +5 -9
  65. package/script/helpers/unifyColumns.d.ts +0 -2
  66. package/script/helpers/unifyColumns.d.ts.map +1 -1
  67. package/script/helpers/unifyColumns.js +2 -6
  68. package/script/helpers/writeGeoData.d.ts.map +1 -1
  69. package/script/helpers/writeGeoData.js +11 -41
  70. package/script/helpers/writeIndexes.d.ts +3 -0
  71. package/script/helpers/writeIndexes.d.ts.map +1 -0
  72. package/script/helpers/writeIndexes.js +19 -0
  73. package/script/methods/bm25.d.ts.map +1 -1
  74. package/script/methods/bm25.js +1 -1
  75. package/script/methods/cache.js +1 -1
  76. package/script/methods/distanceQuery.d.ts.map +1 -1
  77. package/script/methods/distanceQuery.js +4 -2
  78. package/script/methods/fuzzyJoin.d.ts.map +1 -1
  79. package/script/methods/fuzzyJoin.js +1 -6
  80. package/script/methods/getGeoData.d.ts.map +1 -1
  81. package/script/methods/getGeoData.js +1 -10
  82. package/script/methods/getNbRows.d.ts +3 -1
  83. package/script/methods/getNbRows.d.ts.map +1 -1
  84. package/script/methods/getNbRows.js +5 -5
  85. package/script/methods/join.d.ts.map +1 -1
  86. package/script/methods/join.js +1 -7
  87. package/script/methods/joinGeo.d.ts.map +1 -1
  88. package/script/methods/joinGeo.js +1 -14
  89. package/script/methods/joinGeoQuery.js +1 -1
  90. package/script/methods/randomPointQuery.d.ts.map +1 -1
  91. package/script/methods/randomPointQuery.js +60 -22
  92. package/script/methods/summarizeQuery.js +1 -1
  93. package/script/methods/writeGeoDataQuery.js +2 -2
  94. package/esm/helpers/getProjection.d.ts +0 -3
  95. package/esm/helpers/getProjection.d.ts.map +0 -1
  96. package/esm/helpers/getProjection.js +0 -25
  97. package/esm/helpers/getProjectionParquet.d.ts +0 -3
  98. package/esm/helpers/getProjectionParquet.d.ts.map +0 -1
  99. package/esm/helpers/getProjectionParquet.js +0 -24
  100. package/esm/helpers/shouldFlipBeforeExport.d.ts +0 -2
  101. package/esm/helpers/shouldFlipBeforeExport.d.ts.map +0 -1
  102. package/esm/helpers/shouldFlipBeforeExport.js +0 -3
  103. package/esm/helpers/writeProjectionsAndIndexes.d.ts +0 -3
  104. package/esm/helpers/writeProjectionsAndIndexes.d.ts.map +0 -1
  105. package/esm/helpers/writeProjectionsAndIndexes.js +0 -29
  106. package/script/helpers/getProjection.d.ts +0 -3
  107. package/script/helpers/getProjection.d.ts.map +0 -1
  108. package/script/helpers/getProjection.js +0 -31
  109. package/script/helpers/getProjectionParquet.d.ts +0 -3
  110. package/script/helpers/getProjectionParquet.d.ts.map +0 -1
  111. package/script/helpers/getProjectionParquet.js +0 -30
  112. package/script/helpers/shouldFlipBeforeExport.d.ts +0 -2
  113. package/script/helpers/shouldFlipBeforeExport.d.ts.map +0 -1
  114. package/script/helpers/shouldFlipBeforeExport.js +0 -6
  115. package/script/helpers/writeProjectionsAndIndexes.d.ts +0 -3
  116. package/script/helpers/writeProjectionsAndIndexes.d.ts.map +0 -1
  117. package/script/helpers/writeProjectionsAndIndexes.js +0 -32
@@ -27,7 +27,7 @@ function convertForJS(rows, types) {
27
27
  row[key] = row[key] === null ? null : Number(row[key]);
28
28
  }
29
29
  }
30
- else if (types[key] === "GEOMETRY") {
30
+ else if (types[key].toLowerCase().includes("geometry")) {
31
31
  for (const row of rows) {
32
32
  row[key] = row[key] === null ? null : "<Geometry>";
33
33
  }
@@ -4,7 +4,7 @@ exports.default = findGeoColumn;
4
4
  async function findGeoColumn(SimpleTable) {
5
5
  let column;
6
6
  const types = await SimpleTable.getTypes();
7
- const geometries = Object.values(types).filter((d) => d.toLowerCase() === "geometry");
7
+ const geometries = Object.values(types).filter((d) => d.toLowerCase().includes("geometry"));
8
8
  if (geometries.length === 0) {
9
9
  throw new Error("Table contains no geometry columns.");
10
10
  }
@@ -12,7 +12,7 @@ async function findGeoColumn(SimpleTable) {
12
12
  throw new Error("More than one column storing geometries. If the method allows to specify one, do it. Otherwise, use the selectColumns methods beforehand.");
13
13
  }
14
14
  else {
15
- column = Object.keys(types).find((d) => types[d].toLowerCase() === "geometry");
15
+ column = Object.keys(types).find((d) => types[d].toLowerCase().includes("geometry"));
16
16
  }
17
17
  if (typeof column !== "string") {
18
18
  throw new Error("No column");
@@ -20,5 +20,5 @@ exports.default = hasGeometryColumn;
20
20
  */
21
21
  async function hasGeometryColumn(table) {
22
22
  const types = await table.getTypes();
23
- return Object.values(types).some((t) => t.toLowerCase() === "geometry");
23
+ return Object.values(types).some((t) => t.toLowerCase().includes("geometry"));
24
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"logData.d.ts","sourceRoot":"","sources":["../../src/helpers/logData.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,KAAK,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,IAAI,EACvC,IAAI,EACA;IACA,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC;CACxD,EAAE,GACD,IAAI,EACR,iBAAiB,CAAC,EAAE,MAAM,QAwD3B"}
1
+ {"version":3,"file":"logData.d.ts","sourceRoot":"","sources":["../../src/helpers/logData.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,KAAK,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,IAAI,EACvC,IAAI,EACA;IACA,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC;CACxD,EAAE,GACD,IAAI,EACR,iBAAiB,CAAC,EAAE,MAAM,QA4D3B"}
@@ -35,8 +35,13 @@ function logData(types, data, nbCharactersToLog) {
35
35
  const columns = Object.keys(types);
36
36
  if (columns.length > 0) {
37
37
  for (const col of columns) {
38
- types[col] = types[col] + "/" +
39
- (data[0][col] === null ? null : typeof data[0][col]);
38
+ if (data[0][col] === "<Geometry>") {
39
+ continue;
40
+ }
41
+ else {
42
+ types[col] = types[col] + "/" +
43
+ (data[0][col] === null ? null : typeof data[0][col]);
44
+ }
40
45
  }
41
46
  // Add types as the first row
42
47
  dataToBeLogged.unshift(types);
@@ -1,2 +1,2 @@
1
- export default function parseType(type: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "geometry"): string;
1
+ export default function parseType(type: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | `geometry('${string}')` | `GEOMETRY('${string}')`): string;
2
2
  //# sourceMappingURL=parseTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseTypes.d.ts","sourceRoot":"","sources":["../../src/helpers/parseTypes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,IAAI,EACA,SAAS,GACT,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,UAAU,GACV,YAAY,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,GACX,0BAA0B,GAC1B,SAAS,GACT,UAAU,UA+Bf"}
1
+ {"version":3,"file":"parseTypes.d.ts","sourceRoot":"","sources":["../../src/helpers/parseTypes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,IAAI,EACA,SAAS,GACT,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,UAAU,GACV,YAAY,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,GACX,0BAA0B,GAC1B,SAAS,GACT,aAAa,MAAM,IAAI,GACvB,aAAa,MAAM,IAAI,UAgC5B"}
@@ -28,10 +28,12 @@ function parseType(type) {
28
28
  "timestamp",
29
29
  "timestamp with time zone",
30
30
  "boolean",
31
- "geometry",
32
31
  ].includes(typeLowerCase)) {
33
32
  return type.toUpperCase();
34
33
  }
34
+ else if (typeLowerCase.includes("geometry")) {
35
+ return type.toUpperCase();
36
+ }
35
37
  else {
36
38
  throw new Error(`Unknown type ${type}`);
37
39
  }
@@ -1,3 +1,3 @@
1
1
  import type SimpleDB from "../class/SimpleDB.js";
2
- export default function setDbProps(simpleDB: SimpleDB, file: string, extension: string, allIndexesFile: string): Promise<void>;
2
+ export default function setDbProps(simpleDB: SimpleDB, allIndexesFile: string): Promise<void>;
3
3
  //# sourceMappingURL=setDbProps.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"setDbProps.d.ts","sourceRoot":"","sources":["../../src/helpers/setDbProps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AAEjD,wBAA8B,UAAU,CACtC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,iBA8BvB"}
1
+ {"version":3,"file":"setDbProps.d.ts","sourceRoot":"","sources":["../../src/helpers/setDbProps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AAEjD,wBAA8B,UAAU,CACtC,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,MAAM,iBA2BvB"}
@@ -2,19 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = setDbProps;
4
4
  const node_fs_1 = require("node:fs");
5
- async function setDbProps(simpleDB, file, extension, allIndexesFile) {
5
+ async function setDbProps(simpleDB, allIndexesFile) {
6
6
  for (const table of await simpleDB.getTableNames()) {
7
7
  simpleDB.newTable(table);
8
8
  }
9
- const allProjectionsFile = `${file.replace(`.${extension}`, "")}_projections.json`;
10
- if ((0, node_fs_1.existsSync)(allProjectionsFile)) {
11
- const projections = JSON.parse((0, node_fs_1.readFileSync)(allProjectionsFile, "utf-8"));
12
- for (const table of simpleDB.tables) {
13
- if (projections[table.name]) {
14
- table.projections = projections[table.name];
15
- }
9
+ for (const table of await simpleDB.getTables()) {
10
+ const types = await table.getTypes();
11
+ if (Object.values(types).some((type) => type.toLowerCase().includes("geometry"))) {
12
+ await simpleDB.customQuery(`INSTALL SPATIAL; LOAD SPATIAL;`);
16
13
  }
17
- await simpleDB.customQuery(`INSTALL spatial; LOAD spatial;`);
18
14
  }
19
15
  if ((0, node_fs_1.existsSync)(allIndexesFile)) {
20
16
  const indexes = JSON.parse((0, node_fs_1.readFileSync)(allIndexesFile, "utf-8"));
@@ -1,8 +1,6 @@
1
1
  import type SimpleTable from "../class/SimpleTable.js";
2
2
  export default function unifyColumns(allTables: SimpleTable[], allTypes: {
3
3
  [key: string]: string;
4
- }, allProjections: {
5
- [key: string]: string;
6
4
  }): Promise<{
7
5
  [key: string]: string[];
8
6
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"unifyColumns.d.ts","sourceRoot":"","sources":["../../src/helpers/unifyColumns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD,wBAA8B,YAAY,CACxC,SAAS,EAAE,WAAW,EAAE,EACxB,QAAQ,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACnC,cAAc,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE;;GA4C1C"}
1
+ {"version":3,"file":"unifyColumns.d.ts","sourceRoot":"","sources":["../../src/helpers/unifyColumns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD,wBAA8B,YAAY,CACxC,SAAS,EAAE,WAAW,EAAE,EACxB,QAAQ,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE;;GAwCpC"}
@@ -1,18 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = unifyColumns;
4
- async function unifyColumns(allTables, allTypes, allProjections) {
4
+ async function unifyColumns(allTables, allTypes) {
5
5
  const columnsAdded = {};
6
6
  for (const column in allTypes) {
7
7
  for (const table of allTables) {
8
8
  if (!(await table.hasColumn(column))) {
9
9
  await table.addColumn(column,
10
10
  // Could be improved
11
- allTypes[column].toLowerCase(), `null`, {
12
- projection: allTypes[column] === "GEOMETRY"
13
- ? allProjections[column]
14
- : undefined,
15
- });
11
+ allTypes[column].toLowerCase(), `null`);
16
12
  if (!columnsAdded[table.name]) {
17
13
  columnsAdded[table.name] = [];
18
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"writeGeoData.d.ts","sourceRoot":"","sources":["../../src/helpers/writeGeoData.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD,wBAA8B,YAAY,CACxC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IACP,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;CAClB,GACL,OAAO,CAAC,IAAI,CAAC,CAqIf"}
1
+ {"version":3,"file":"writeGeoData.d.ts","sourceRoot":"","sources":["../../src/helpers/writeGeoData.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD,wBAA8B,YAAY,CACxC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IACP,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;CAClB,GACL,OAAO,CAAC,IAAI,CAAC,CAmGf"}
@@ -7,9 +7,7 @@ exports.default = writeGeoData;
7
7
  const node_fs_1 = require("node:fs");
8
8
  const createDirectory_js_1 = __importDefault(require("./createDirectory.js"));
9
9
  const getExtension_js_1 = __importDefault(require("./getExtension.js"));
10
- const findGeoColumn_js_1 = __importDefault(require("./findGeoColumn.js"));
11
10
  const hasGeometryColumn_js_1 = __importDefault(require("./hasGeometryColumn.js"));
12
- const shouldFlipBeforeExport_js_1 = __importDefault(require("./shouldFlipBeforeExport.js"));
13
11
  const queryDB_js_1 = __importDefault(require("./queryDB.js"));
14
12
  const writeGeoDataQuery_js_1 = __importDefault(require("../methods/writeGeoDataQuery.js"));
15
13
  const mergeOptions_js_1 = __importDefault(require("./mergeOptions.js"));
@@ -35,24 +33,11 @@ async function writeGeoData(table, file, options = {}) {
35
33
  if (typeof options.compression === "boolean") {
36
34
  throw new Error("The compression option is not supported for writing GeoJSON files.");
37
35
  }
38
- const geoColumn = await (0, findGeoColumn_js_1.default)(table);
39
- const flip = (0, shouldFlipBeforeExport_js_1.default)(table.projections[geoColumn]);
40
- if (flip) {
41
- await table.flipCoordinates(geoColumn);
42
- await (0, queryDB_js_1.default)(table, (0, writeGeoDataQuery_js_1.default)(table.name, file, fileExtension, options), (0, mergeOptions_js_1.default)(table, {
43
- table: table.name,
44
- method: "writeGeoData()",
45
- parameters: { file, options },
46
- }));
47
- await table.flipCoordinates(geoColumn);
48
- }
49
- else {
50
- await (0, queryDB_js_1.default)(table, (0, writeGeoDataQuery_js_1.default)(table.name, file, fileExtension, options), (0, mergeOptions_js_1.default)(table, {
51
- table: table.name,
52
- method: "writeGeoData()",
53
- parameters: { file, options },
54
- }));
55
- }
36
+ await (0, queryDB_js_1.default)(table, (0, writeGeoDataQuery_js_1.default)(table.name, file, fileExtension, options), (0, mergeOptions_js_1.default)(table, {
37
+ table: table.name,
38
+ method: "writeGeoData()",
39
+ parameters: { file, options },
40
+ }));
56
41
  if (options.metadata) {
57
42
  const fileData = JSON.parse((0, node_fs_1.readFileSync)(file, "utf-8"));
58
43
  fileData.metadata = options.metadata;
@@ -76,24 +61,11 @@ async function writeGeoData(table, file, options = {}) {
76
61
  options.formatDates === true) {
77
62
  throw new Error("The following options are not supported for writing SHAPEFILE files: precision, compression, rewind, metadata, and formatDates.");
78
63
  }
79
- const geoColumn = await (0, findGeoColumn_js_1.default)(table);
80
- const flip = (0, shouldFlipBeforeExport_js_1.default)(table.projections[geoColumn]);
81
- if (flip) {
82
- await table.flipCoordinates(geoColumn);
83
- await (0, queryDB_js_1.default)(table, (0, writeGeoDataQuery_js_1.default)(table.name, file, fileExtension, options), (0, mergeOptions_js_1.default)(table, {
84
- table: table.name,
85
- method: "writeGeoData()",
86
- parameters: { file, options },
87
- }));
88
- await table.flipCoordinates(geoColumn);
89
- }
90
- else {
91
- await (0, queryDB_js_1.default)(table, (0, writeGeoDataQuery_js_1.default)(table.name, file, fileExtension, options), (0, mergeOptions_js_1.default)(table, {
92
- table: table.name,
93
- method: "writeGeoData()",
94
- parameters: { file, options },
95
- }));
96
- }
64
+ await (0, queryDB_js_1.default)(table, (0, writeGeoDataQuery_js_1.default)(table.name, file, fileExtension, options), (0, mergeOptions_js_1.default)(table, {
65
+ table: table.name,
66
+ method: "writeGeoData()",
67
+ parameters: { file, options },
68
+ }));
97
69
  }
98
70
  else if (fileExtension === "geoparquet") {
99
71
  if (typeof options.precision === "number") {
@@ -102,9 +74,7 @@ async function writeGeoData(table, file, options = {}) {
102
74
  if (typeof options.rewind === "boolean") {
103
75
  throw new Error("The rewind option is not supported for writing PARQUET files.");
104
76
  }
105
- await (0, queryDB_js_1.default)(table, `COPY "${table.name}" TO '${(0, cleanPath_js_1.default)(file)}' WITH (FORMAT PARQUET${options.compression === true ? ", COMPRESSION 'zstd'" : ""}, KV_METADATA {
106
- projections: '${JSON.stringify(table.projections)}'
107
- });`, (0, mergeOptions_js_1.default)(table, {
77
+ await (0, queryDB_js_1.default)(table, `COPY "${table.name}" TO '${(0, cleanPath_js_1.default)(file)}' WITH (FORMAT PARQUET${options.compression === true ? ", COMPRESSION 'zstd'" : ""});`, (0, mergeOptions_js_1.default)(table, {
108
78
  table: table.name,
109
79
  method: "writeGeoData()",
110
80
  parameters: { file, options },
@@ -0,0 +1,3 @@
1
+ import type { SimpleDB } from "../index.js";
2
+ export default function writeIndexes(simpleDB: SimpleDB, extension: string, file: string): void;
3
+ //# sourceMappingURL=writeIndexes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeIndexes.d.ts","sourceRoot":"","sources":["../../src/helpers/writeIndexes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,QAeb"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = writeIndexes;
4
+ const node_fs_1 = require("node:fs");
5
+ function writeIndexes(simpleDB, extension, file) {
6
+ const allIndexes = {};
7
+ for (const table of simpleDB.tables) {
8
+ if (table.indexes.length > 0) {
9
+ allIndexes[table.name] = table.indexes;
10
+ }
11
+ }
12
+ const allIndexesFile = `${file.replace(`.${extension}`, "")}_indexes.json`;
13
+ if ((0, node_fs_1.existsSync)(allIndexesFile)) {
14
+ (0, node_fs_1.rmSync)(allIndexesFile);
15
+ }
16
+ if (Object.keys(allIndexes).length > 0) {
17
+ (0, node_fs_1.writeFileSync)(allIndexesFile, JSON.stringify(allIndexes));
18
+ }
19
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"bm25.d.ts","sourceRoot":"","sources":["../../src/methods/bm25.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAIvD,wBAA8B,IAAI,CAChC,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IACP,OAAO,CAAC,EACJ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,OAAO,GACP,SAAS,GACT,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,OAAO,GACP,WAAW,GACX,YAAY,GACZ,OAAO,GACP,SAAS,GACT,YAAY,GACZ,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,UAAU,GACV,SAAS,GACT,SAAS,GACT,SAAS,GACT,SAAS,GACT,OAAO,GACP,SAAS,GACT,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;CACd,wBAgEP"}
1
+ {"version":3,"file":"bm25.d.ts","sourceRoot":"","sources":["../../src/methods/bm25.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAIvD,wBAA8B,IAAI,CAChC,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IACP,OAAO,CAAC,EACJ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,OAAO,GACP,SAAS,GACT,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,OAAO,GACP,WAAW,GACX,YAAY,GACZ,OAAO,GACP,SAAS,GACT,YAAY,GACZ,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,UAAU,GACV,SAAS,GACT,SAAS,GACT,SAAS,GACT,SAAS,GACT,OAAO,GACP,SAAS,GACT,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;CACd,wBA+DP"}
@@ -46,7 +46,7 @@ async function bm25(simpleTable, text, columnId, columnText, nbResults, options
46
46
  },
47
47
  }));
48
48
  if (typeof options.outputTable === "string") {
49
- return simpleTable.sdb.newTable(options.outputTable, structuredClone(simpleTable.projections));
49
+ return simpleTable.sdb.newTable(options.outputTable);
50
50
  }
51
51
  else {
52
52
  return simpleTable;
@@ -97,7 +97,7 @@ async function runAndWrite(table, run, cacheSources, cacheSourcesPath, cachePath
97
97
  }
98
98
  else {
99
99
  const types = await table.getTypes();
100
- const geometriesColumns = Object.values(types).filter((d) => d === "GEOMETRY").length;
100
+ const geometriesColumns = Object.values(types).filter((d) => d.toLowerCase().includes("geometry")).length;
101
101
  if (geometriesColumns > 0) {
102
102
  const file = `${cachePath}/${id}.geoparquet`;
103
103
  const writeStart = Date.now();
@@ -1 +1 @@
1
- {"version":3,"file":"distanceQuery.d.ts","sourceRoot":"","sources":["../../src/methods/distanceQuery.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IACP,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,GAAG,UAAU,GAAG,WAAW,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACd,UAsDP"}
1
+ {"version":3,"file":"distanceQuery.d.ts","sourceRoot":"","sources":["../../src/methods/distanceQuery.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IACP,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,GAAG,UAAU,GAAG,WAAW,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACd,UAwDP"}
@@ -32,10 +32,12 @@ function distanceQuery(table, column1, column2, newColumn, options = {}) {
32
32
  }
33
33
  else if (options.method === "spheroid") {
34
34
  if (typeof options.decimals === "number") {
35
- query += `ROUND(ST_Distance_Spheroid("${column1}", "${column2}") ${options.unit === "km" ? "/ 1000" : ""}, ${options.decimals});`;
35
+ query +=
36
+ `ROUND(ST_Distance_Spheroid("${column1}"::GEOMETRY, "${column2}"::GEOMETRY) ${options.unit === "km" ? "/ 1000" : ""}, ${options.decimals});`;
36
37
  }
37
38
  else {
38
- query += `ST_Distance_Spheroid("${column1}", "${column2}") ${options.unit === "km" ? "/ 1000" : ""};`;
39
+ query +=
40
+ `ST_Distance_Spheroid("${column1}"::GEOMETRY, "${column2}"::GEOMETRY) ${options.unit === "km" ? "/ 1000" : ""};`;
39
41
  }
40
42
  }
41
43
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"fuzzyJoin.d.ts","sourceRoot":"","sources":["../../src/methods/fuzzyJoin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAMvD,wBAA8B,SAAS,CACrC,SAAS,EAAE,WAAW,EACtB,UAAU,EAAE,WAAW,EACvB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IACP,MAAM,CAAC,EACH,OAAO,GACP,eAAe,GACf,kBAAkB,GAClB,iBAAiB,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CACxB,wBAwFP"}
1
+ {"version":3,"file":"fuzzyJoin.d.ts","sourceRoot":"","sources":["../../src/methods/fuzzyJoin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAMvD,wBAA8B,SAAS,CACrC,SAAS,EAAE,WAAW,EACtB,UAAU,EAAE,WAAW,EACvB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IACP,MAAM,CAAC,EACH,OAAO,GACP,eAAe,GACf,kBAAkB,GAClB,iBAAiB,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CACxB,wBAiFP"}
@@ -44,14 +44,9 @@ async function fuzzyJoin(leftTable, rightTable, leftColumn, rightColumn, thresho
44
44
  options,
45
45
  },
46
46
  }));
47
- const allProjections = {
48
- ...leftTable.projections,
49
- ...rightTable.projections,
50
- };
51
47
  const outputTable = typeof options.outputTable === "string"
52
- ? leftTable.sdb.newTable(options.outputTable, allProjections)
48
+ ? leftTable.sdb.newTable(options.outputTable)
53
49
  : leftTable;
54
- outputTable.projections = allProjections;
55
50
  // Remove the duplicate right-column produced when leftColumn === rightColumn
56
51
  // (DuckDB suffixes it with _1 in SELECT *)
57
52
  const outputCols = await outputTable.getColumns();
@@ -1 +1 @@
1
- {"version":3,"file":"getGeoData.d.ts","sourceRoot":"","sources":["../../src/methods/getGeoData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAOvD,wBAA8B,UAAU,CACtC,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO;;;;;kBA4BtB,MAAM;yBACC,OAAO,EAAE;;;;;;GAgC7B"}
1
+ {"version":3,"file":"getGeoData.d.ts","sourceRoot":"","sources":["../../src/methods/getGeoData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAMvD,wBAA8B,UAAU,CACtC,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO;;;;;kBAuBtB,MAAM;yBACC,OAAO,EAAE;;;;;;GAgC7B"}
@@ -7,17 +7,8 @@ exports.default = getGeoData;
7
7
  const rewind_js_1 = __importDefault(require("../helpers/rewind.js"));
8
8
  const mergeOptions_js_1 = __importDefault(require("../helpers/mergeOptions.js"));
9
9
  const queryDB_js_1 = __importDefault(require("../helpers/queryDB.js"));
10
- const shouldFlipBeforeExport_js_1 = __importDefault(require("../helpers/shouldFlipBeforeExport.js"));
11
10
  async function getGeoData(SimpleTable, column, options = {}) {
12
- let query = "";
13
- if ((0, shouldFlipBeforeExport_js_1.default)(SimpleTable.projections[column])) {
14
- query =
15
- `SELECT * EXCLUDE ${column}, ST_AsGeoJSON(ST_FlipCoordinates(${column})) as geoJsonFragment from "${SimpleTable.name}";`;
16
- }
17
- else {
18
- query =
19
- `SELECT * EXCLUDE ${column}, ST_AsGeoJSON(${column}) as geoJsonFragment from "${SimpleTable.name}";`;
20
- }
11
+ const query = `SELECT * EXCLUDE ${column}, ST_AsGeoJSON(${column}) as geoJsonFragment from "${SimpleTable.name}";`;
21
12
  const queryResult = await (0, queryDB_js_1.default)(SimpleTable, query, (0, mergeOptions_js_1.default)(SimpleTable, {
22
13
  table: null,
23
14
  method: "getGeoData()",
@@ -1,3 +1,5 @@
1
1
  import type SimpleTable from "../class/SimpleTable.js";
2
- export default function getNbRows(SimpleTable: SimpleTable): Promise<number>;
2
+ export default function getNbRows(SimpleTable: SimpleTable, options?: {
3
+ conditions?: string;
4
+ }): Promise<number>;
3
5
  //# sourceMappingURL=getNbRows.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getNbRows.d.ts","sourceRoot":"","sources":["../../src/methods/getNbRows.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD,wBAA8B,SAAS,CAAC,WAAW,EAAE,WAAW,mBAkB/D"}
1
+ {"version":3,"file":"getNbRows.d.ts","sourceRoot":"","sources":["../../src/methods/getNbRows.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD,wBAA8B,SAAS,CACrC,WAAW,EAAE,WAAW,EACxB,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,mBAqBtC"}
@@ -6,16 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.default = getNbRows;
7
7
  const mergeOptions_js_1 = __importDefault(require("../helpers/mergeOptions.js"));
8
8
  const queryDB_js_1 = __importDefault(require("../helpers/queryDB.js"));
9
- async function getNbRows(SimpleTable) {
10
- const queryResult = await (0, queryDB_js_1.default)(SimpleTable, `SELECT CAST(COUNT(*) AS INTEGER) FROM "${SimpleTable.name}"`, (0, mergeOptions_js_1.default)(SimpleTable, {
9
+ async function getNbRows(SimpleTable, options = {}) {
10
+ const queryResult = await (0, queryDB_js_1.default)(SimpleTable, `SELECT CAST(COUNT(*) AS INTEGER) AS nbRows FROM "${SimpleTable.name}"${options.conditions ? ` WHERE ${options.conditions}` : ""}`, (0, mergeOptions_js_1.default)(SimpleTable, {
11
11
  table: SimpleTable.name,
12
12
  returnDataFrom: "query",
13
- method: "getLength()",
14
- parameters: {},
13
+ method: "getNbRows()",
14
+ parameters: { options },
15
15
  }));
16
16
  if (!queryResult) {
17
17
  throw new Error("No result");
18
18
  }
19
- const length = queryResult[0]["CAST(count_star() AS INTEGER)"];
19
+ const length = queryResult[0].nbRows;
20
20
  return length;
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"join.d.ts","sourceRoot":"","sources":["../../src/methods/join.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAMvD,wBAA8B,IAAI,CAChC,SAAS,EAAE,WAAW,EACtB,UAAU,EAAE,WAAW,EACvB,OAAO,GAAE;IACP,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC3C,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B,wBA4FP"}
1
+ {"version":3,"file":"join.d.ts","sourceRoot":"","sources":["../../src/methods/join.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAMvD,wBAA8B,IAAI,CAChC,SAAS,EAAE,WAAW,EACtB,UAAU,EAAE,WAAW,EACvB,OAAO,GAAE;IACP,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC3C,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B,wBAqFP"}
@@ -52,14 +52,8 @@ async function join(leftTable, rightTable, options = {}) {
52
52
  },
53
53
  }));
54
54
  const outputTable = typeof options.outputTable === "string"
55
- ? leftTable.sdb.newTable(options.outputTable, leftTable.projections) // missing projections here...
55
+ ? leftTable.sdb.newTable(options.outputTable)
56
56
  : leftTable;
57
- // So we reassign here
58
- const allProjections = {
59
- ...leftTable.projections,
60
- ...rightTable.projections,
61
- };
62
- outputTable.projections = allProjections;
63
57
  const columns = await outputTable.getColumns();
64
58
  const extraCommonColumns = columns.filter((d) => commonColumn.map((c) => `${c}_1`).includes(d));
65
59
  if (extraCommonColumns.length > 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"joinGeo.d.ts","sourceRoot":"","sources":["../../src/methods/joinGeo.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAOvD,wBAA8B,OAAO,CACnC,SAAS,EAAE,WAAW,EACtB,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,QAAQ,EACzC,UAAU,EAAE,WAAW,EACvB,OAAO,GAAE;IACP,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,KAAK,GAAG,WAAW,GAAG,UAAU,CAAC;IAClD,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B,wBAyGP"}
1
+ {"version":3,"file":"joinGeo.d.ts","sourceRoot":"","sources":["../../src/methods/joinGeo.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAOvD,wBAA8B,OAAO,CACnC,SAAS,EAAE,WAAW,EACtB,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,QAAQ,EACzC,UAAU,EAAE,WAAW,EACvB,OAAO,GAAE;IACP,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,KAAK,GAAG,WAAW,GAAG,UAAU,CAAC;IAClD,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B,wBA4FP"}
@@ -52,31 +52,18 @@ async function joinGeo(leftTable, method, rightTable, options = {}) {
52
52
  },
53
53
  }));
54
54
  // We bring back the column names for geometries
55
- let allProjections = {};
56
55
  if (leftTableColumn === rightTableColumn) {
57
56
  const leftObj = {};
58
57
  leftObj[leftTableColumnForQuery] = leftTableColumn;
59
58
  await leftTable.renameColumns(leftObj);
60
- // Before renaming columns in original tables
61
- allProjections = {
62
- ...leftTable.projections,
63
- ...rightTable.projections,
64
- };
65
59
  const rightObj = {};
66
60
  rightObj[rightTableColumnForQuery] = rightTableColumn;
67
61
  await rightTable.renameColumns(rightObj);
68
62
  }
69
- else {
70
- allProjections = {
71
- ...leftTable.projections,
72
- ...rightTable.projections,
73
- };
74
- }
75
63
  if (typeof options.outputTable === "string") {
76
- return leftTable.sdb.newTable(options.outputTable, allProjections);
64
+ return leftTable.sdb.newTable(options.outputTable);
77
65
  }
78
66
  else {
79
- leftTable.projections = allProjections;
80
67
  return leftTable;
81
68
  }
82
69
  }
@@ -41,7 +41,7 @@ function joinGeoQuery(leftTable, leftTableColumn, method, rightTable, rightTable
41
41
  else if (distanceMethod === "spheroid") {
42
42
  // Should be using ST_DWithin_Spheroid but doesn't work?
43
43
  query +=
44
- ` ON ST_Distance_Spheroid("${leftTable}"."${leftTableColumn}", "${rightTable}"."${rightTableColumn}") < ${distance}`;
44
+ ` ON ST_Distance_Spheroid("${leftTable}"."${leftTableColumn}"::GEOMETRY, "${rightTable}"."${rightTableColumn}"::GEOMETRY) < ${distance}`;
45
45
  }
46
46
  else {
47
47
  throw new Error(`Unknown ${distanceMethod}`);
@@ -1 +1 @@
1
- {"version":3,"file":"randomPointQuery.d.ts","sourceRoot":"","sources":["../../src/methods/randomPointQuery.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,UA8BtB"}
1
+ {"version":3,"file":"randomPointQuery.d.ts","sourceRoot":"","sources":["../../src/methods/randomPointQuery.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,UAmEtB"}
@@ -2,30 +2,68 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = randomPointQuery;
4
4
  function randomPointQuery(table, column, newColumn, nbPointsToTry) {
5
+ const addColumn = newColumn === column
6
+ ? ""
7
+ : `ALTER TABLE "${table}" ADD COLUMN "${newColumn}" GEOMETRY;`;
8
+ // Recursive CTE approach: each iteration only carries forward the rows that
9
+ // have NOT yet found a valid interior point, so DuckDB stops per-row as soon
10
+ // as ST_Within is satisfied — giving O(1) behaviour for easy polygons instead
11
+ // of the O(N) materialisation that occurs with LATERAL + range() + WHERE.
12
+ //
13
+ // Zero-tries contract: `WHERE 1 <= ${nbPointsToTry}` in the base case
14
+ // produces no rows when nbPointsToTry is 0, so the LEFT JOIN returns NULL for
15
+ // every row and the UPDATE sets the column to NULL — no special-case branch
16
+ // needed and the normal UPDATE code path is always exercised.
17
+ //
18
+ // Volatility guard: `CASE WHEN (rid + n) IS NOT NULL THEN random() END`
19
+ // prevents the planner from constant-folding random() across iterations while
20
+ // still evaluating to random() for every non-null row.
5
21
  return `INSTALL spatial;
6
22
  LOAD spatial;
7
- ${newColumn === column
8
- ? ""
9
- : `ALTER TABLE "${table}" ADD COLUMN "${newColumn}" GEOMETRY;`}
23
+ ${addColumn}
24
+ WITH RECURSIVE
25
+ base AS (
26
+ SELECT
27
+ rowid AS rid,
28
+ "${column}" AS geom,
29
+ ST_XMin("${column}") AS xmin,
30
+ ST_XMax("${column}") - ST_XMin("${column}") AS xdiff,
31
+ ST_YMin("${column}") AS ymin,
32
+ ST_YMax("${column}") - ST_YMin("${column}") AS ydiff
33
+ FROM "${table}"
34
+ ),
35
+ attempts(rid, geom, xmin, xdiff, ymin, ydiff, pt, n) AS (
36
+ SELECT
37
+ rid, geom, xmin, xdiff, ymin, ydiff,
38
+ ST_Point(
39
+ xmin + CASE WHEN rid IS NOT NULL THEN random() END * xdiff,
40
+ ymin + CASE WHEN rid IS NOT NULL THEN random() END * ydiff
41
+ ),
42
+ 1
43
+ FROM base
44
+ WHERE 1 <= ${nbPointsToTry}
45
+ UNION ALL
46
+ SELECT
47
+ rid, geom, xmin, xdiff, ymin, ydiff,
48
+ ST_Point(
49
+ xmin + CASE WHEN (rid + n) IS NOT NULL THEN random() END * xdiff,
50
+ ymin + CASE WHEN (rid + n) IS NOT NULL THEN random() END * ydiff
51
+ ),
52
+ n + 1
53
+ FROM attempts
54
+ WHERE NOT ST_Within(pt, geom) AND n < ${nbPointsToTry}
55
+ )
10
56
  UPDATE "${table}" AS t
11
- SET "${newColumn}" = sub.pt
57
+ SET "${newColumn}" = v.pt
12
58
  FROM (
13
- SELECT
14
- t_inner.rowid AS rid,
15
- p.pt
16
- FROM "${table}" AS t_inner
17
- CROSS JOIN LATERAL (
18
- SELECT pt
19
- FROM (
20
- SELECT ST_Point(
21
- ST_XMin(t_inner."${column}") + (CASE WHEN (t_inner.rowid + r.id) IS NOT NULL THEN random() END) * (ST_XMax(t_inner."${column}") - ST_XMin(t_inner."${column}")),
22
- ST_YMin(t_inner."${column}") + (CASE WHEN (t_inner.rowid + r.id) IS NOT NULL THEN random() END) * (ST_YMax(t_inner."${column}") - ST_YMin(t_inner."${column}"))
23
- ) AS pt
24
- FROM range(${nbPointsToTry}) AS r(id)
25
- )
26
- WHERE ST_Within(pt, t_inner."${column}")
27
- LIMIT 1
28
- ) AS p
29
- ) AS sub
30
- WHERE t.rowid = sub.rid;`;
59
+ SELECT b.rid, vp.pt
60
+ FROM (SELECT rowid AS rid FROM "${table}") b
61
+ LEFT JOIN (
62
+ SELECT rid, pt
63
+ FROM attempts
64
+ WHERE ST_Within(pt, geom)
65
+ QUALIFY ROW_NUMBER() OVER (PARTITION BY rid ORDER BY n) = 1
66
+ ) vp ON b.rid = vp.rid
67
+ ) v
68
+ WHERE t.rowid = v.rid;`;
31
69
  }
@@ -49,7 +49,7 @@ function summarizeQuery(table, types, outputTable, values, categories, summaries
49
49
  aggregates[summary] !== "count") {
50
50
  return `\nNULL as '${columns ? columns[i] : summary}'`;
51
51
  }
52
- else if (types[value] === "GEOMETRY") {
52
+ else if (types[value].toLowerCase().includes("geometry")) {
53
53
  return `\nNULL AS '${columns ? columns[i] : summary}'`;
54
54
  }
55
55
  else if (types[value] === "VARCHAR" &&
@@ -12,12 +12,12 @@ function writeGeoDataQuery(table, file, fileExtension, options = {}) {
12
12
  layerOptions.push(`COORDINATE_PRECISION=${options.precision}`);
13
13
  }
14
14
  layerOptions.push(`RFC7946=YES`);
15
- return `INSTALL spatial; LOAD spatial; COPY "${table}" to '${(0, cleanPath_js_1.default)(file)}' WITH (FORMAT GDAL, DRIVER 'GeoJSON'${layerOptions.length > 0
15
+ return `INSTALL spatial; LOAD spatial; SET geometry_always_xy = true; COPY "${table}" to '${(0, cleanPath_js_1.default)(file)}' WITH (FORMAT GDAL, DRIVER 'GeoJSON'${layerOptions.length > 0
16
16
  ? `, LAYER_CREATION_OPTIONS ('WRITE_NAME=NO', ${layerOptions.map((d) => `'${d}'`).join(", ")})`
17
17
  : ""})`;
18
18
  }
19
19
  else if (fileExtension === "shp") {
20
- return `INSTALL spatial; LOAD spatial; COPY "${table}" TO '${(0, cleanPath_js_1.default)(file)}' WITH (FORMAT GDAL, DRIVER 'ESRI Shapefile', LAYER_CREATION_OPTIONS 'ENCODING=UTF-8')`;
20
+ return `INSTALL spatial; LOAD spatial; SET geometry_always_xy = true; COPY "${table}" TO '${(0, cleanPath_js_1.default)(file)}' WITH (FORMAT GDAL, DRIVER 'ESRI Shapefile', LAYER_CREATION_OPTIONS 'ENCODING=UTF-8')`;
21
21
  }
22
22
  else {
23
23
  throw new Error(`Unknown extension ${fileExtension}`);
@@ -1,3 +0,0 @@
1
- import type SimpleDB from "../class/SimpleDB.js";
2
- export default function getProjection(simpleDB: SimpleDB, file: string): Promise<string>;
3
- //# sourceMappingURL=getProjection.d.ts.map