The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Database, Table } from "@alchemy.run/aws/Glue"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as glue from "@distilled.cloud/aws/glue"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | const getTable = (databaseName: string, name: string) => |
| 11 | glue.getTable({ DatabaseName: databaseName, Name: name }).pipe( |
| 12 | Effect.map((r) => r.Table), |
| 13 | Effect.catchTag("EntityNotFoundException", () => Effect.succeed(undefined)), |
| 14 | ); |
| 15 | |
| 16 | test.provider( |
| 17 | "create, update, delete Glue table over a database", |
| 18 | (stack) => |
| 19 | Effect.gen(function* () { |
| 20 | yield* stack.destroy(); |
| 21 | |
| 22 | // create database + parquet table |
| 23 | const created = yield* stack.deploy( |
| 24 | Effect.gen(function* () { |
| 25 | const database = yield* Database("AnalyticsDb", {}); |
| 26 | const table = yield* Table("Events", { |
| 27 | databaseName: database.databaseName, |
| 28 | tableType: "EXTERNAL_TABLE", |
| 29 | storageDescriptor: { |
| 30 | location: "s3://example-bucket/events/", |
| 31 | inputFormat: "org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat", |
| 32 | outputFormat: "org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat", |
| 33 | serdeInfo: { |
| 34 | serializationLibrary: "org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe", |
| 35 | }, |
| 36 | columns: [ |
| 37 | { name: "id", type: "string" }, |
| 38 | { name: "amount", type: "double" }, |
| 39 | ], |
| 40 | }, |
| 41 | partitionKeys: [{ name: "dt", type: "string" }], |
| 42 | parameters: { classification: "parquet" }, |
| 43 | }); |
| 44 | return { database, table }; |
| 45 | }), |
| 46 | ); |
| 47 | |
| 48 | expect(created.table.tableName).toBeDefined(); |
| 49 | expect(created.table.databaseName).toEqual(created.database.databaseName); |
| 50 | expect(created.table.tableArn).toContain( |
| 51 | `:table/${created.database.databaseName}/${created.table.tableName}`, |
| 52 | ); |
| 53 | |
| 54 | // out-of-band verification |
| 55 | const observed = yield* getTable(created.database.databaseName, created.table.tableName); |
| 56 | expect(observed?.Name).toEqual(created.table.tableName); |
| 57 | expect(observed?.TableType).toEqual("EXTERNAL_TABLE"); |
| 58 | expect(observed?.StorageDescriptor?.Location).toEqual("s3://example-bucket/events/"); |
| 59 | expect(observed?.StorageDescriptor?.Columns?.map((c) => c.Name)).toEqual(["id", "amount"]); |
| 60 | expect(observed?.PartitionKeys?.map((c) => c.Name)).toEqual(["dt"]); |
| 61 | expect(observed?.Parameters?.classification).toEqual("parquet"); |
| 62 | expect(observed?.Parameters?.["alchemy::id"]).toBeDefined(); |
| 63 | |
| 64 | // update: add a column + change a parameter |
| 65 | const updated = yield* stack.deploy( |
| 66 | Effect.gen(function* () { |
| 67 | const database = yield* Database("AnalyticsDb", {}); |
| 68 | const table = yield* Table("Events", { |
| 69 | databaseName: database.databaseName, |
| 70 | tableType: "EXTERNAL_TABLE", |
| 71 | storageDescriptor: { |
| 72 | location: "s3://example-bucket/events-v2/", |
| 73 | inputFormat: "org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat", |
| 74 | outputFormat: "org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat", |
| 75 | serdeInfo: { |
| 76 | serializationLibrary: "org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe", |
| 77 | }, |
| 78 | columns: [ |
| 79 | { name: "id", type: "string" }, |
| 80 | { name: "amount", type: "double" }, |
| 81 | { name: "currency", type: "string" }, |
| 82 | ], |
| 83 | }, |
| 84 | partitionKeys: [{ name: "dt", type: "string" }], |
| 85 | parameters: { classification: "parquet", owner: "analytics" }, |
| 86 | }); |
| 87 | return { database, table }; |
| 88 | }), |
| 89 | ); |
| 90 | |
| 91 | expect(updated.table.tableName).toEqual(created.table.tableName); |
| 92 | const reobserved = yield* getTable(created.database.databaseName, created.table.tableName); |
| 93 | expect(reobserved?.StorageDescriptor?.Location).toEqual("s3://example-bucket/events-v2/"); |
| 94 | expect(reobserved?.StorageDescriptor?.Columns?.map((c) => c.Name)).toEqual([ |
| 95 | "id", |
| 96 | "amount", |
| 97 | "currency", |
| 98 | ]); |
| 99 | expect(reobserved?.Parameters?.owner).toEqual("analytics"); |
| 100 | |
| 101 | // delete |
| 102 | yield* stack.destroy(); |
| 103 | const gone = yield* getTable(created.database.databaseName, created.table.tableName); |
| 104 | expect(gone).toBeUndefined(); |
| 105 | }), |
| 106 | { tags: ["provider:aws", "provider:aws:glue", "live"] }, |
| 107 | ); |