Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Sheet9// File : Packages/SheetData/Tests/SheetDataTests/ImportTests.swift10// Module : SheetDataTests11// Repository : https://git.spboucher.ai/orix-sheet12// Created : 2026-11-2113// Last Modified : 2026-11-2114//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author : Simon-Pierre Boucher20// Position : Professor of Finance21// Institution : Université du Québec en Outaouais (UQO)22// Department : Département des sciences administratives23// Organization : SP Boucher24//25// Website : https://spboucher.ai26// Git : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General : info@spboucher.ai33// Professional : contact@spboucher.ai34// Direct : simon@spboucher.ai35// Research : research@spboucher.ai36// Development : dev@spboucher.ai37// Support : support@spboucher.ai38// Security/Admin : admin@spboucher.ai39// Notifications : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification : Public66// Distribution : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License : None specified (no license file in this repository)80// Maintainer : Simon-Pierre Boucher81// Technical Contact: dev@spboucher.ai82//83// =============================================================================84// END OF SP BOUCHER SOURCE HEADER85// =============================================================================8687import Foundation88import Testing89import SheetCore90@testable import SheetData9192@Suite struct ImportTests {93 private func basic(_ e: DataEngine, _ dataset: String) throws {94 let want = Fixtures.expected["sales_basic"] as! [String: Any]95 func n(_ k: String) -> Double { (want[k] as! NSNumber).doubleValue }96 let t = try e.query("""97 SELECT count(*), sum(quantity), avg(unit_price), count(*) - count(quantity), count(*) - count(note), count(*) - count(region),98 count(DISTINCT customer_id), count(*) FILTER (WHERE is_online), CAST(min(order_date) AS DATE), CAST(max(order_date) AS DATE)99 FROM \(SQL.ident(dataset))100 """)101 let r = t.row(0)102 #expect(r[0].doubleValue == n("rows"))103 #expect(r[1].doubleValue == n("sum_quantity"))104 #expect(close(r[2].doubleValue!, n("mean_unit_price")))105 #expect(r[3].doubleValue == n("null_quantity"))106 #expect(r[4].doubleValue == n("null_note"))107 #expect(r[5].doubleValue == n("null_region"))108 #expect(r[6].doubleValue == n("distinct_customers"))109 #expect(r[7].doubleValue == n("online"))110 #expect(r[8].text == want["min_date"] as! String)111 #expect(r[9].text == want["max_date"] as! String)112 // a filtered aggregation against pandas113 let agg = try e.query("""114 SELECT category, count(order_id) AS n, sum(quantity) AS qty, sum(quantity * unit_price * (1 - coalesce(discount, 0))) AS rev115 FROM \(SQL.ident(dataset)) WHERE region = 'North' AND unit_price > 100 GROUP BY category116 """)117 expectTable(agg, matches: "filtered_agg")118 }119120 @Test func csvImportInfersTypesAndMatchesPandas() throws {121 let e = try DataEngine()122 let box = ProgressBox()123 let info = try e.importFile(Fixtures.url("sales.csv"), as: "sales", progress: { box.add($0) })124 #expect(info.kind == .table && info.rowCount == 2000 && info.format == .csv)125 #expect(info.sourceURL?.lastPathComponent == "sales.csv")126 #expect(info.sourceBytes == (try FileManager.default.attributesOfItem(atPath: Fixtures.url("sales.csv").path)[.size] as? NSNumber)?.int64Value)127 #expect(info.columns.map(\.name) == ["order_id", "region", "category", "product", "order_date", "quantity", "unit_price", "discount", "customer_id", "is_online", "note"])128 #expect(info.columns.map(\.type) == [.integer, .string, .string, .string, .date, .integer, .double, .double, .integer, .boolean, .string])129 #expect(box.values.last == 1)130 try basic(e, "sales")131 // quoted commas, quotes and line breaks survive132 let notes = try e.query("SELECT DISTINCT note FROM sales WHERE note IS NOT NULL ORDER BY 1")133 #expect(Set(notes.rows.map { $0[0].text }) == ["ok", "rush, fragile", "said \"thanks\"", "multi\nline", "späť"])134 // the staged copy is removed after an eager import135 #expect((try FileManager.default.contentsOfDirectory(atPath: e.stagingDirectory.path)).isEmpty)136 }137138 @Test func parquetJsonAndSQLiteAgreeWithCSV() throws {139 let e = try DataEngine()140 let pq = try e.importFile(Fixtures.url("sales.parquet"), as: "pq")141 #expect(pq.rowCount == 2000 && pq.format == .parquet)142 #expect(pq.columns.first { $0.name == "order_date" }?.type == .date)143 try basic(e, "pq")144 let js = try e.importFile(Fixtures.url("sales.jsonl"), as: "js")145 #expect(js.rowCount == 2000 && js.format == .jsonLines)146 #expect(js.columns.first { $0.name == "is_online" }?.type == .boolean)147 try basic(e, "js")148 let sq = try e.importFile(Fixtures.url("sales.sqlite"), as: "sq", options: ImportOptions(sourceTable: "sales"))149 #expect(sq.rowCount == 2000 && sq.format == .sqlite)150 #expect(sq.columns.map(\.type) == [.integer, .string, .string, .string, .date, .integer, .double, .double, .integer, .boolean, .string])151 try basic(e, "sq")152 // the four copies are identical row for row153 for other in ["pq", "js", "sq"] {154 let diff = try e.query("""155 SELECT count(*) FROM (156 (SELECT order_id, region, product, CAST(order_date AS DATE), quantity, unit_price, discount, is_online, note FROM pq157 EXCEPT SELECT order_id, region, product, CAST(order_date AS DATE), quantity, unit_price, discount, is_online, note FROM \(other))158 UNION ALL159 (SELECT order_id, region, product, CAST(order_date AS DATE), quantity, unit_price, discount, is_online, note FROM \(other)160 EXCEPT SELECT order_id, region, product, CAST(order_date AS DATE), quantity, unit_price, discount, is_online, note FROM pq))161 """)162 #expect(diff.value(row: 0, column: 0) == .int(0), "\(other)")163 }164 }165166 @Test func sqliteTablesTypesAndAmbiguity() throws {167 let e = try DataEngine()168 #expect(try e.tables(inSQLiteFile: Fixtures.url("sales.sqlite")) == ["customers", "mixed", "sales"])169 do { _ = try e.importFile(Fixtures.url("sales.sqlite"), as: "x"); Issue.record("expected ambiguity") } catch DataError.ambiguousSource(let tables) {170 #expect(tables == ["customers", "mixed", "sales"])171 }172 #expect(throws: DataError.self) { _ = try e.importFile(Fixtures.url("sales.sqlite"), as: "x", options: ImportOptions(sourceTable: "nope")) }173 #expect(try e.datasets().isEmpty) // failed imports leave nothing behind174 // dynamic typing: a column holding integers, reals and text becomes VARCHAR; BLOBs stay BLOBs; NULLs stay NULL175 let mixed = try e.importFile(Fixtures.url("sales.sqlite"), as: "mixed", options: ImportOptions(sourceTable: "mixed"))176 #expect(mixed.columns.map(\.type) == [.integer, .string, .blob])177 let rows = try e.query("SELECT k, v, payload FROM mixed ORDER BY k").rows178 #expect(rows[0] == [.int(1), .string("10"), .blob(Data([0, 1]))])179 #expect(rows[1] == [.int(2), .string("2.5"), .null])180 #expect(rows[2] == [.int(3), .string("text"), .blob(Data([0xff]))])181 #expect(rows[3] == [.int(4), .null, .null])182 let customers = try e.importFile(Fixtures.url("sales.sqlite"), as: "c", options: ImportOptions(sourceTable: "customers"))183 #expect(customers.rowCount == 131)184 }185186 @Test func duckdbFileImportIsReadOnlyAndSelective() throws {187 let dir = Fixtures.temporaryDirectory()188 defer { try? FileManager.default.removeItem(at: dir) }189 let path = dir.appendingPathComponent("source.duckdb")190 do {191 let src = try DataEngine(path: path)192 try src.execute("CREATE TABLE a AS SELECT i, i * 2 AS d FROM range(1000) t(i); CREATE TABLE b AS SELECT 'x' AS s;")193 }194 let before = try Data(contentsOf: path)195 let e = try DataEngine()196 #expect(try e.tables(inDuckDBFile: path).sorted() == ["a", "b"])197 do { _ = try e.importFile(path, as: "x"); Issue.record("expected ambiguity") } catch DataError.ambiguousSource(let tables) { #expect(tables.sorted() == ["a", "b"]) }198 let info = try e.importFile(path, as: "copy", options: ImportOptions(sourceTable: "a"))199 #expect(info.rowCount == 1000 && info.format == .duckdb)200 #expect(try e.query("SELECT sum(d) FROM copy").value(row: 0, column: 0) == .int(999_000))201 #expect(try Data(contentsOf: path) == before) // the user's file is never written202 #expect(try e.query("SELECT count(*) FROM duckdb_databases() WHERE database_name LIKE 'orix_src_%'").value(row: 0, column: 0) == .int(0))203 }204205 @Test func arrowIPCIsReportedUnsupported() throws {206 let e = try DataEngine()207 #expect(DataFileFormat.detect(Fixtures.url("sales.arrow")) == .arrowIPC)208 do { _ = try e.importFile(Fixtures.url("sales.arrow"), as: "a"); Issue.record("expected unsupported") } catch DataError.unsupportedFormat(let m) {209 #expect(m.contains("Parquet"))210 }211 #expect(throws: DataError.self) { _ = try e.registerView(Fixtures.url("sales.sqlite"), as: "v") }212 #expect(throws: DataError.self) { _ = try e.importFile(URL(fileURLWithPath: "/nonexistent/file.csv"), as: "x") }213 }214215 @Test func csvDialects() throws {216 let e = try DataEngine()217 // semicolon + decimal comma + dd/mm/yyyy, with quoted separators and line breaks218 let semi = try e.importFile(Fixtures.url("dialect_semicolon.csv"), as: "semicolon",219 options: ImportOptions(delimiter: ";", dateFormat: "%d/%m/%Y", decimalSeparator: ","))220 #expect(semi.columns.map(\.type) == [.integer, .string, .double, .date])221 expectTable(try e.query("SELECT id, montant FROM semicolon"), matches: "dialect_semicolon")222 let s = try e.query("SELECT \"libellé\", \"date\" FROM semicolon ORDER BY id")223 #expect(s.rows.map { $0[0].text } == ["Été; chaud", "Hiver", "Dit \"bonjour\"", "Ligne\nbrisée", "Fin"])224 #expect(s.rows.map { $0[1].text } == ["2024-12-31", "2025-02-01", "2023-08-15", "2024-02-28", ""])225 // sniffed without options: the delimiter is detected, numbers with a decimal comma stay text226 let sniffed = try e.importFile(Fixtures.url("dialect_semicolon.csv"), as: "sniffed")227 #expect(sniffed.columns.count == 4 && sniffed.columns[2].type == .string)228 // TSV by extension229 let tsv = try e.importFile(Fixtures.url("dialect_tab.tsv"), as: "tsv")230 #expect(tsv.format == .tsv)231 #expect(try e.query("SELECT name, score FROM tsv ORDER BY id").rows == [["a b", 1.5], ["c,d", .null], ["e|f", 3.25]])232 // pipe-delimited, no header, single-quote quoting233 let pipe = try e.importFile(Fixtures.url("dialect_pipe_noheader.txt"), as: "pipe", format: .csv,234 options: ImportOptions(delimiter: "|", hasHeader: false, quote: "'"))235 #expect(pipe.columns.map(\.name) == ["column0", "column1", "column2", "column3"])236 #expect(pipe.columns.map(\.type) == [.integer, .string, .date, .double])237 #expect(try e.query("SELECT column1, column3 FROM pipe ORDER BY column0").rows == [["alpha", 10.5], ["beta", .null], ["gamma|x", 30.0]])238 }239240 @Test func csvTypeInferenceAndOverrides() throws {241 let e = try DataEngine()242 let t = try e.importFile(Fixtures.url("types.csv"), as: "types")243 let types = Dictionary(uniqueKeysWithValues: t.columns.map { ($0.name, $0.type) })244 #expect(types["i"] == .integer)245 #expect(types["big"] == .integer)246 #expect(types["f"] == .double)247 #expect(types["b"] == .boolean)248 #expect(types["d"] == .date)249 #expect(types["ts"] == .timestamp)250 #expect(types["t"] == .time)251 #expect(types["txt"] == .string)252 let rows = try e.query("SELECT big, f, ts, t, txt, empty, b FROM types ORDER BY i").rows253 // rows are ordered by i: -2, 1, 3254 #expect(rows[1][0] == .int(9007199254740993)) // beyond 2^53: exact as an integer255 #expect(rows[0][1] == .double(2000))256 #expect(rows[1][2].text == "2024-01-31 13:45:10")257 #expect(rows[1][3].text == "08:30:00")258 #expect(rows[2][4] == .string("x,y"))259 #expect(rows.allSatisfy { $0[5] == .null })260 #expect(rows[2][6] == .null && rows[2][0] == .null)261 // NULL/missing semantics: empty fields are NULL, the literal text NULL stays text unless declared262 #expect(rows[0][4] == .string("NULL"))263 let declared = try e.importFile(Fixtures.url("types.csv"), as: "types_null", options: ImportOptions(nullStrings: ["", "NULL"]))264 #expect(declared.rowCount == 3)265 #expect(try e.query("SELECT count(txt) FROM types_null").value(row: 0, column: 0) == .int(2))266 // leading zeros: DuckDB's sniffer keeps ZIP codes as text; explicit types override the inference267 #expect(types["zip"] == .string)268 let typed = try e.importFile(Fixtures.url("types.csv"), as: "typed", options: ImportOptions(columnTypes: ["zip": .string, "i": .double, "f": .decimal(precision: 12, scale: 2)]))269 let typedTypes = Dictionary(uniqueKeysWithValues: typed.columns.map { ($0.name, $0.declaredType) })270 #expect(typedTypes["zip"] == "VARCHAR" && typedTypes["i"] == "DOUBLE" && typedTypes["f"] == "DECIMAL(12,2)")271 #expect(try e.query("SELECT zip FROM typed ORDER BY zip").rows.map { $0[0].text } == ["00501", "01234", "90210"])272 let allText = try e.importFile(Fixtures.url("types.csv"), as: "alltext", options: ImportOptions(allText: true))273 #expect(allText.columns.allSatisfy { $0.type == .string })274 // replaceExisting = false refuses to overwrite275 #expect(throws: DataError.self) { _ = try e.importFile(Fixtures.url("types.csv"), as: "typed", options: ImportOptions(replaceExisting: false)) }276 }277278 @Test func lazyViewsScanWithPushdown() throws {279 let e = try DataEngine()280 let view = try e.registerView(Fixtures.url("sales.parquet"), as: "sales_pq")281 #expect(view.kind == .view && view.rowCount == 2000 && view.format == .parquet)282 try basic(e, "sales_pq")283 let csv = try e.registerView(Fixtures.url("sales.csv"), as: "sales_csv")284 #expect(csv.kind == .view)285 try basic(e, "sales_csv")286 // nothing was copied into the engine287 #expect(try e.query("SELECT count(*) FROM duckdb_tables() WHERE schema_name = 'main'").value(row: 0, column: 0) == .int(0))288 // the plan shows the filter and the projection inside the Parquet scan289 let plan = try e.query("EXPLAIN SELECT sum(quantity) FROM sales_pq WHERE order_id > 1900").rows.map { $0.map(\.text).joined(separator: "\n") }.joined(separator: "\n")290 #expect(plan.contains("PARQUET_SCAN") || plan.contains("READ_PARQUET"))291 #expect(plan.contains("order_id>1900") || plan.contains("order_id > 1900"))292 #expect(!plan.contains("unit_price"))293 // listed without a row count unless asked294 let listed = try e.datasets()295 #expect(listed.map(\.name) == ["sales_csv", "sales_pq"] && listed.allSatisfy { $0.rowCount == nil })296 #expect(try e.datasets(countViewRows: true).allSatisfy { $0.rowCount == 2000 })297 // dropping a view removes its staged file298 try e.dropDataset("sales_pq")299 try e.dropDataset("sales_csv")300 #expect((try FileManager.default.contentsOfDirectory(atPath: e.stagingDirectory.path)).isEmpty)301 #expect(throws: DataError.self) { try e.dropDataset("sales_pq") }302 }303304 @Test func previewPagingIsStableUnderOrderBy() throws {305 let e = try Fixtures.engine()306 // region has many ties and NULLs: consecutive windows must partition the rows exactly307 let order = [SortSpec("region"), SortSpec("unit_price")]308 var seen = [Double]()309 var offset = 0310 while true {311 let page = try e.preview("sales", offset: offset, limit: 137, orderBy: order, columns: ["order_id", "region"])312 if page.rowCount == 0 { break }313 seen += (0..<page.rowCount).map { page.columns[0].double($0)! }314 offset += 137315 }316 #expect(seen.count == 2000 && Set(seen).count == 2000)317 #expect(seen == Fixtures.numbers("preview_sorted")) // pandas: sort by region, unit_price, then order_id; NaN last318 // ties only (one sort key with 4 values): still a partition, and repeatable319 var a = [Double](), b = [Double]()320 for off in stride(from: 0, to: 2000, by: 250) {321 let p1 = try e.preview("sales", offset: off, limit: 250, orderBy: [SortSpec("category", ascending: false)], columns: ["order_id"])322 let p2 = try e.preview("sales", offset: off, limit: 250, orderBy: [SortSpec("category", ascending: false)], columns: ["order_id"])323 a += (0..<p1.rowCount).map { p1.columns[0].double($0)! }324 b += (0..<p2.rowCount).map { p2.columns[0].double($0)! }325 }326 #expect(a == b && Set(a).count == 2000)327 // views have no rowid: ties are broken by the remaining columns328 try e.registerView(Fixtures.url("sales.parquet"), as: "v")329 var v = [Double]()330 for off in stride(from: 0, to: 2000, by: 333) {331 let p = try e.preview("v", offset: off, limit: 333, orderBy: [SortSpec("is_online")])332 v += (0..<p.rowCount).map { p.column("order_id")!.double($0)! }333 }334 #expect(v.count == 2000 && Set(v).count == 2000)335 // no ORDER BY: insertion order, windows are contiguous336 let w = try e.preview("sales", offset: 1500, limit: 3)337 #expect((0..<3).map { w.column("order_id")!.double($0)! } == [1501, 1502, 1503])338 // filters339 let f = FilterGroup(.all, [FilterCondition("region", .equal, "West"), FilterCondition("quantity", .isNull)])340 let filtered = try e.preview("sales", offset: 0, limit: 5000, filter: f)341 #expect(filtered.rowCount == (try e.rowCount(of: "sales", filter: f)))342 #expect(filtered.rowCount == Int(try e.query("SELECT count(*) FROM sales WHERE region = 'West' AND quantity IS NULL").value(row: 0, column: 0).doubleValue!))343 #expect(try e.preview("sales", offset: 5000, limit: 10).rowCount == 0)344 #expect(throws: DataError.self) { _ = try e.preview("nope", offset: 0, limit: 1) }345 }346347 @Test func profileMatchesPandas() throws {348 let e = try Fixtures.engine()349 let profile = try e.profile("sales")350 #expect(profile.map(\.name).count == 11)351 let want = Fixtures.expected["profile"] as! [String: [String: Any]]352 for name in ["quantity", "unit_price", "discount", "customer_id"] {353 let p = profile.first { $0.name == name }!354 let w = want[name]!355 func n(_ k: String) -> Double { (w[k] as! NSNumber).doubleValue }356 #expect(p.count == 2000)357 #expect(Double(p.nullCount) == n("nulls"), "\(name)")358 #expect(close(p.min.doubleValue!, n("min")) && close(p.max.doubleValue!, n("max")), "\(name)")359 #expect(close(p.mean!, n("mean")) && close(p.stddev!, n("std")), "\(name)")360 #expect(close(p.q25!, n("q25")) && close(p.median!, n("median")) && close(p.q75!, n("q75")), "\(name)")361 // HyperLogLog estimate: within 5 % of the exact count362 #expect(abs(Double(p.distinctApprox) - n("distinct")) <= max(1, 0.05 * n("distinct")), "\(name)")363 }364 let region = profile.first { $0.name == "region" }!365 let w = want["region"]!366 #expect(region.type == .string && region.mean == nil)367 #expect(Double(region.nullCount) == (w["nulls"] as! NSNumber).doubleValue)368 #expect(region.min.text == w["min"] as! String && region.max.text == w["max"] as! String)369 let top = (w["top"] as! [[Any]]).map { ($0[0] as! String, ($0[1] as! NSNumber).intValue) }370 #expect(region.topValues.map(\.value.text) == top.map(\.0))371 #expect(region.topValues.map(\.count) == top.map(\.1))372 let date = profile.first { $0.name == "order_date" }!373 #expect(date.min.text == (Fixtures.expected["sales_basic"] as! [String: Any])["min_date"] as! String)374 #expect(try e.profile("sales", columns: ["note"], topValues: 0).first?.topValues.isEmpty == true)375 }376377 @Test func exportRoundTrips() throws {378 let e = try Fixtures.engine()379 let dir = Fixtures.temporaryDirectory()380 defer { try? FileManager.default.removeItem(at: dir) }381 let sql = "SELECT order_id, region, quantity, unit_price, order_date, note FROM sales WHERE category = 'Toys'"382 let want = try e.query(sql + " ORDER BY order_id")383 for (format, name) in [(ExportFormat.csv, "out.csv"), (.parquet, "out.parquet"), (.json, "out.json")] {384 let url = dir.appendingPathComponent(name)385 let rows = try e.exportQuery(sql, to: url, format: format)386 #expect(rows == want.rowCount)387 let back = try e.importFile(url, as: "back")388 #expect(back.rowCount == want.rowCount)389 let got = try e.query("SELECT order_id, region, quantity, unit_price, CAST(order_date AS DATE) AS order_date, note FROM back ORDER BY order_id")390 #expect(got.rows.map { $0.map(Canon.init) } == want.rows.map { $0.map(Canon.init) }, "\(format)")391 }392 // options and overwrite393 let tsv = dir.appendingPathComponent("out.csv")394 try e.exportQuery("SELECT 1 AS a, 'x;y' AS b", to: tsv, format: .csv, options: ExportOptions(delimiter: ";", header: false))395 #expect(try String(contentsOf: tsv, encoding: .utf8) == "1;\"x;y\"\n")396 let lines = dir.appendingPathComponent("lines.json")397 try e.exportQuery("SELECT i FROM range(3) t(i)", to: lines, format: .json, options: ExportOptions(jsonArray: false))398 #expect(try String(contentsOf: lines, encoding: .utf8).split(separator: "\n").count == 3)399 #expect(try e.exportDataset("customers", to: dir.appendingPathComponent("c.parquet"), format: .parquet) == 131)400 // nothing is left in the staging area401 #expect((try FileManager.default.contentsOfDirectory(atPath: e.stagingDirectory.path)).isEmpty)402 }403404 @Test func datasetsCatalog() throws {405 let e = try Fixtures.engine()406 let all = try e.datasets()407 #expect(all.map(\.name) == ["customers", "messy", "sales", "sales_extra", "sales_r"])408 #expect(all.first { $0.name == "sales_r" }?.sourceURL == nil)409 #expect(all.first { $0.name == "sales" }?.rowCount == 2000)410 #expect(all.first { $0.name == "sales" }?.importedAt != nil)411 // tables created by plain SQL are datasets too412 try e.execute("CREATE TABLE adhoc AS SELECT 1 AS x")413 #expect(try e.dataset("adhoc").rowCount == 1)414 #expect(try e.schema(of: "customers").map(\.name) == ["customer_id", "name", "segment", "region"])415 #expect(throws: DataError.self) { _ = try e.dataset("missing") }416 }417}418