@lix-js/sdk 0.6.0-preview.4 → 0.6.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 (223) hide show
  1. package/README.md +76 -4
  2. package/dist/errors.d.ts +7 -0
  3. package/dist/errors.js +19 -0
  4. package/dist/index.d.ts +4 -5
  5. package/dist/index.js +3 -3
  6. package/dist/native.d.ts +1 -0
  7. package/dist/native.js +47 -0
  8. package/dist/open-lix.d.ts +39 -201
  9. package/dist/open-lix.js +59 -284
  10. package/dist/result.d.ts +18 -0
  11. package/dist/result.js +48 -0
  12. package/dist/types.d.ts +114 -1
  13. package/dist/value.d.ts +28 -0
  14. package/dist/value.js +245 -0
  15. package/package.json +20 -50
  16. package/SKILL.md +0 -506
  17. package/dist/builtin-schemas.d.ts +0 -1
  18. package/dist/builtin-schemas.js +0 -1
  19. package/dist/engine-wasm/index.d.ts +0 -87
  20. package/dist/engine-wasm/index.js +0 -339
  21. package/dist/engine-wasm/wasm/lix_engine.d.ts +0 -79
  22. package/dist/engine-wasm/wasm/lix_engine.js +0 -821
  23. package/dist/engine-wasm/wasm/lix_engine.wasm +0 -0
  24. package/dist/engine-wasm/wasm/lix_engine.wasm.d.ts +0 -26
  25. package/dist/generated/builtin-schemas.d.ts +0 -427
  26. package/dist/generated/builtin-schemas.js +0 -643
  27. package/dist/sqlite/index.d.ts +0 -12
  28. package/dist/sqlite/index.js +0 -303
  29. package/dist-engine-src/README.md +0 -18
  30. package/dist-engine-src/src/backend/kv.rs +0 -358
  31. package/dist-engine-src/src/backend/mod.rs +0 -12
  32. package/dist-engine-src/src/backend/testing.rs +0 -658
  33. package/dist-engine-src/src/backend/types.rs +0 -96
  34. package/dist-engine-src/src/binary_cas/chunking.rs +0 -31
  35. package/dist-engine-src/src/binary_cas/codec.rs +0 -346
  36. package/dist-engine-src/src/binary_cas/context.rs +0 -139
  37. package/dist-engine-src/src/binary_cas/kv.rs +0 -1063
  38. package/dist-engine-src/src/binary_cas/mod.rs +0 -11
  39. package/dist-engine-src/src/binary_cas/types.rs +0 -121
  40. package/dist-engine-src/src/catalog/context.rs +0 -412
  41. package/dist-engine-src/src/catalog/mod.rs +0 -10
  42. package/dist-engine-src/src/catalog/schema.rs +0 -4
  43. package/dist-engine-src/src/catalog/snapshot.rs +0 -1114
  44. package/dist-engine-src/src/cel/context.rs +0 -86
  45. package/dist-engine-src/src/cel/error.rs +0 -19
  46. package/dist-engine-src/src/cel/mod.rs +0 -8
  47. package/dist-engine-src/src/cel/provider.rs +0 -9
  48. package/dist-engine-src/src/cel/runtime.rs +0 -167
  49. package/dist-engine-src/src/cel/value.rs +0 -50
  50. package/dist-engine-src/src/commit_graph/context.rs +0 -901
  51. package/dist-engine-src/src/commit_graph/mod.rs +0 -11
  52. package/dist-engine-src/src/commit_graph/types.rs +0 -109
  53. package/dist-engine-src/src/commit_graph/walker.rs +0 -756
  54. package/dist-engine-src/src/commit_store/codec.rs +0 -887
  55. package/dist-engine-src/src/commit_store/context.rs +0 -944
  56. package/dist-engine-src/src/commit_store/materialization.rs +0 -84
  57. package/dist-engine-src/src/commit_store/mod.rs +0 -16
  58. package/dist-engine-src/src/commit_store/storage.rs +0 -600
  59. package/dist-engine-src/src/commit_store/types.rs +0 -215
  60. package/dist-engine-src/src/common/error.rs +0 -313
  61. package/dist-engine-src/src/common/fingerprint.rs +0 -3
  62. package/dist-engine-src/src/common/fs_path.rs +0 -1336
  63. package/dist-engine-src/src/common/identity.rs +0 -145
  64. package/dist-engine-src/src/common/json_pointer.rs +0 -67
  65. package/dist-engine-src/src/common/metadata.rs +0 -40
  66. package/dist-engine-src/src/common/mod.rs +0 -23
  67. package/dist-engine-src/src/common/types.rs +0 -105
  68. package/dist-engine-src/src/common/wire.rs +0 -222
  69. package/dist-engine-src/src/domain.rs +0 -324
  70. package/dist-engine-src/src/engine.rs +0 -225
  71. package/dist-engine-src/src/entity_identity.rs +0 -405
  72. package/dist-engine-src/src/functions/context.rs +0 -292
  73. package/dist-engine-src/src/functions/deterministic.rs +0 -113
  74. package/dist-engine-src/src/functions/mod.rs +0 -18
  75. package/dist-engine-src/src/functions/provider.rs +0 -130
  76. package/dist-engine-src/src/functions/state.rs +0 -336
  77. package/dist-engine-src/src/functions/types.rs +0 -37
  78. package/dist-engine-src/src/init.rs +0 -558
  79. package/dist-engine-src/src/json_store/compression.rs +0 -77
  80. package/dist-engine-src/src/json_store/context.rs +0 -423
  81. package/dist-engine-src/src/json_store/encoded.rs +0 -15
  82. package/dist-engine-src/src/json_store/mod.rs +0 -12
  83. package/dist-engine-src/src/json_store/store.rs +0 -1109
  84. package/dist-engine-src/src/json_store/types.rs +0 -217
  85. package/dist-engine-src/src/lib.rs +0 -62
  86. package/dist-engine-src/src/live_state/context.rs +0 -2019
  87. package/dist-engine-src/src/live_state/mod.rs +0 -15
  88. package/dist-engine-src/src/live_state/overlay.rs +0 -75
  89. package/dist-engine-src/src/live_state/reader.rs +0 -23
  90. package/dist-engine-src/src/live_state/types.rs +0 -222
  91. package/dist-engine-src/src/live_state/visibility.rs +0 -223
  92. package/dist-engine-src/src/plugin/archive.rs +0 -438
  93. package/dist-engine-src/src/plugin/component.rs +0 -183
  94. package/dist-engine-src/src/plugin/install.rs +0 -619
  95. package/dist-engine-src/src/plugin/manifest.rs +0 -516
  96. package/dist-engine-src/src/plugin/materializer.rs +0 -477
  97. package/dist-engine-src/src/plugin/mod.rs +0 -33
  98. package/dist-engine-src/src/plugin/plugin_manifest.json +0 -118
  99. package/dist-engine-src/src/plugin/storage.rs +0 -74
  100. package/dist-engine-src/src/schema/annotations/defaults.rs +0 -275
  101. package/dist-engine-src/src/schema/annotations/mod.rs +0 -1
  102. package/dist-engine-src/src/schema/builtin/lix_account.json +0 -21
  103. package/dist-engine-src/src/schema/builtin/lix_active_account.json +0 -29
  104. package/dist-engine-src/src/schema/builtin/lix_binary_blob_ref.json +0 -29
  105. package/dist-engine-src/src/schema/builtin/lix_change.json +0 -63
  106. package/dist-engine-src/src/schema/builtin/lix_change_author.json +0 -45
  107. package/dist-engine-src/src/schema/builtin/lix_commit.json +0 -24
  108. package/dist-engine-src/src/schema/builtin/lix_commit_edge.json +0 -53
  109. package/dist-engine-src/src/schema/builtin/lix_directory_descriptor.json +0 -52
  110. package/dist-engine-src/src/schema/builtin/lix_file_descriptor.json +0 -52
  111. package/dist-engine-src/src/schema/builtin/lix_key_value.json +0 -40
  112. package/dist-engine-src/src/schema/builtin/lix_label.json +0 -29
  113. package/dist-engine-src/src/schema/builtin/lix_label_assignment.json +0 -74
  114. package/dist-engine-src/src/schema/builtin/lix_registered_schema.json +0 -25
  115. package/dist-engine-src/src/schema/builtin/lix_version_descriptor.json +0 -34
  116. package/dist-engine-src/src/schema/builtin/lix_version_ref.json +0 -48
  117. package/dist-engine-src/src/schema/builtin/mod.rs +0 -222
  118. package/dist-engine-src/src/schema/compatibility.rs +0 -787
  119. package/dist-engine-src/src/schema/definition.json +0 -187
  120. package/dist-engine-src/src/schema/definition.rs +0 -742
  121. package/dist-engine-src/src/schema/key.rs +0 -138
  122. package/dist-engine-src/src/schema/mod.rs +0 -20
  123. package/dist-engine-src/src/schema/seed.rs +0 -14
  124. package/dist-engine-src/src/schema/tests.rs +0 -780
  125. package/dist-engine-src/src/session/context.rs +0 -404
  126. package/dist-engine-src/src/session/create_version.rs +0 -88
  127. package/dist-engine-src/src/session/execute.rs +0 -541
  128. package/dist-engine-src/src/session/merge/analysis.rs +0 -102
  129. package/dist-engine-src/src/session/merge/apply.rs +0 -23
  130. package/dist-engine-src/src/session/merge/conflicts.rs +0 -63
  131. package/dist-engine-src/src/session/merge/mod.rs +0 -11
  132. package/dist-engine-src/src/session/merge/stats.rs +0 -65
  133. package/dist-engine-src/src/session/merge/version.rs +0 -427
  134. package/dist-engine-src/src/session/mod.rs +0 -27
  135. package/dist-engine-src/src/session/optimization9_sql2_bench.rs +0 -100
  136. package/dist-engine-src/src/session/switch_version.rs +0 -110
  137. package/dist-engine-src/src/session/transaction.rs +0 -76
  138. package/dist-engine-src/src/sql2/change_provider.rs +0 -331
  139. package/dist-engine-src/src/sql2/classify.rs +0 -174
  140. package/dist-engine-src/src/sql2/context.rs +0 -311
  141. package/dist-engine-src/src/sql2/directory_history_provider.rs +0 -631
  142. package/dist-engine-src/src/sql2/directory_provider.rs +0 -2453
  143. package/dist-engine-src/src/sql2/dml.rs +0 -148
  144. package/dist-engine-src/src/sql2/entity_history_provider.rs +0 -440
  145. package/dist-engine-src/src/sql2/entity_provider.rs +0 -3211
  146. package/dist-engine-src/src/sql2/error.rs +0 -215
  147. package/dist-engine-src/src/sql2/execute.rs +0 -3533
  148. package/dist-engine-src/src/sql2/file_history_provider.rs +0 -910
  149. package/dist-engine-src/src/sql2/file_provider.rs +0 -3679
  150. package/dist-engine-src/src/sql2/filesystem_planner.rs +0 -1490
  151. package/dist-engine-src/src/sql2/filesystem_predicates.rs +0 -159
  152. package/dist-engine-src/src/sql2/filesystem_visibility.rs +0 -383
  153. package/dist-engine-src/src/sql2/history_projection.rs +0 -56
  154. package/dist-engine-src/src/sql2/history_provider.rs +0 -412
  155. package/dist-engine-src/src/sql2/history_route.rs +0 -657
  156. package/dist-engine-src/src/sql2/lix_state_provider.rs +0 -2512
  157. package/dist-engine-src/src/sql2/mod.rs +0 -47
  158. package/dist-engine-src/src/sql2/predicate_typecheck.rs +0 -246
  159. package/dist-engine-src/src/sql2/public_bind/assignment.rs +0 -46
  160. package/dist-engine-src/src/sql2/public_bind/capability.rs +0 -41
  161. package/dist-engine-src/src/sql2/public_bind/dml.rs +0 -172
  162. package/dist-engine-src/src/sql2/public_bind/mod.rs +0 -26
  163. package/dist-engine-src/src/sql2/public_bind/table.rs +0 -168
  164. package/dist-engine-src/src/sql2/read_only.rs +0 -63
  165. package/dist-engine-src/src/sql2/record_batch.rs +0 -17
  166. package/dist-engine-src/src/sql2/result_metadata.rs +0 -29
  167. package/dist-engine-src/src/sql2/runtime.rs +0 -60
  168. package/dist-engine-src/src/sql2/session.rs +0 -132
  169. package/dist-engine-src/src/sql2/udfs/common.rs +0 -295
  170. package/dist-engine-src/src/sql2/udfs/lix_active_version_commit_id.rs +0 -53
  171. package/dist-engine-src/src/sql2/udfs/lix_empty_blob.rs +0 -47
  172. package/dist-engine-src/src/sql2/udfs/lix_json.rs +0 -100
  173. package/dist-engine-src/src/sql2/udfs/lix_json_get.rs +0 -99
  174. package/dist-engine-src/src/sql2/udfs/lix_json_get_text.rs +0 -99
  175. package/dist-engine-src/src/sql2/udfs/lix_text_decode.rs +0 -82
  176. package/dist-engine-src/src/sql2/udfs/lix_text_encode.rs +0 -85
  177. package/dist-engine-src/src/sql2/udfs/lix_timestamp.rs +0 -76
  178. package/dist-engine-src/src/sql2/udfs/lix_uuid_v7.rs +0 -76
  179. package/dist-engine-src/src/sql2/udfs/mod.rs +0 -89
  180. package/dist-engine-src/src/sql2/udfs/public_call.rs +0 -238
  181. package/dist-engine-src/src/sql2/version_provider.rs +0 -1202
  182. package/dist-engine-src/src/sql2/version_scope.rs +0 -394
  183. package/dist-engine-src/src/sql2/write_normalization.rs +0 -345
  184. package/dist-engine-src/src/storage/context.rs +0 -356
  185. package/dist-engine-src/src/storage/mod.rs +0 -14
  186. package/dist-engine-src/src/storage/read_scope.rs +0 -88
  187. package/dist-engine-src/src/storage/types.rs +0 -501
  188. package/dist-engine-src/src/storage_bench.rs +0 -4863
  189. package/dist-engine-src/src/test_support.rs +0 -228
  190. package/dist-engine-src/src/tracked_state/by_file_index.rs +0 -98
  191. package/dist-engine-src/src/tracked_state/codec.rs +0 -2085
  192. package/dist-engine-src/src/tracked_state/context.rs +0 -1867
  193. package/dist-engine-src/src/tracked_state/diff.rs +0 -686
  194. package/dist-engine-src/src/tracked_state/materialization.rs +0 -403
  195. package/dist-engine-src/src/tracked_state/materializer.rs +0 -488
  196. package/dist-engine-src/src/tracked_state/merge.rs +0 -492
  197. package/dist-engine-src/src/tracked_state/mod.rs +0 -32
  198. package/dist-engine-src/src/tracked_state/storage.rs +0 -375
  199. package/dist-engine-src/src/tracked_state/tree.rs +0 -3187
  200. package/dist-engine-src/src/tracked_state/types.rs +0 -231
  201. package/dist-engine-src/src/transaction/commit.rs +0 -1484
  202. package/dist-engine-src/src/transaction/context.rs +0 -1548
  203. package/dist-engine-src/src/transaction/live_state_overlay.rs +0 -35
  204. package/dist-engine-src/src/transaction/mod.rs +0 -13
  205. package/dist-engine-src/src/transaction/normalization.rs +0 -890
  206. package/dist-engine-src/src/transaction/prep.rs +0 -37
  207. package/dist-engine-src/src/transaction/schema_resolver.rs +0 -149
  208. package/dist-engine-src/src/transaction/staging.rs +0 -1731
  209. package/dist-engine-src/src/transaction/types.rs +0 -460
  210. package/dist-engine-src/src/transaction/validation.rs +0 -5830
  211. package/dist-engine-src/src/untracked_state/codec.rs +0 -307
  212. package/dist-engine-src/src/untracked_state/context.rs +0 -98
  213. package/dist-engine-src/src/untracked_state/materialization.rs +0 -63
  214. package/dist-engine-src/src/untracked_state/mod.rs +0 -15
  215. package/dist-engine-src/src/untracked_state/storage.rs +0 -396
  216. package/dist-engine-src/src/untracked_state/types.rs +0 -146
  217. package/dist-engine-src/src/version/context.rs +0 -40
  218. package/dist-engine-src/src/version/lifecycle.rs +0 -221
  219. package/dist-engine-src/src/version/mod.rs +0 -13
  220. package/dist-engine-src/src/version/refs.rs +0 -330
  221. package/dist-engine-src/src/version/stage_rows.rs +0 -67
  222. package/dist-engine-src/src/version/types.rs +0 -21
  223. package/dist-engine-src/src/wasm/mod.rs +0 -60
@@ -1,82 +0,0 @@
1
- use std::any::Any;
2
- use std::sync::Arc;
3
-
4
- use datafusion::arrow::array::StringArray;
5
- use datafusion::arrow::datatypes::DataType;
6
- use datafusion::common::{plan_err, Result, ScalarValue};
7
- use datafusion::logical_expr::{
8
- ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility,
9
- };
10
-
11
- use super::common::{decode_utf8_value, scalar_inputs, validate_utf8_encoding_arg};
12
-
13
- #[derive(Debug, Clone, PartialEq, Eq, Hash)]
14
- pub(super) struct LixTextDecode {
15
- signature: Signature,
16
- }
17
-
18
- impl LixTextDecode {
19
- pub(super) fn new() -> Self {
20
- Self {
21
- signature: Signature::one_of(
22
- vec![Signature::any(1, Volatility::Immutable).type_signature],
23
- Volatility::Immutable,
24
- ),
25
- }
26
- }
27
- }
28
-
29
- impl ScalarUDFImpl for LixTextDecode {
30
- fn as_any(&self) -> &dyn Any {
31
- self
32
- }
33
-
34
- fn name(&self) -> &str {
35
- "lix_text_decode"
36
- }
37
-
38
- fn signature(&self) -> &Signature {
39
- &self.signature
40
- }
41
-
42
- fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
43
- Ok(DataType::Utf8)
44
- }
45
-
46
- fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
47
- if !(1..=2).contains(&args.args.len()) {
48
- return plan_err!("lix_text_decode requires 1 or 2 arguments");
49
- }
50
- validate_utf8_encoding_arg(self.name(), args.args.get(1))?;
51
-
52
- let scalar_inputs = scalar_inputs(&args.args);
53
- let arrays = ColumnarValue::values_to_arrays(&args.args)?;
54
- let input = &arrays[0];
55
- let len = input.len();
56
-
57
- let mut values = Vec::with_capacity(len);
58
- for row in 0..len {
59
- values.push(decode_utf8_value(input.as_ref(), row)?);
60
- }
61
- if scalar_inputs {
62
- Ok(ColumnarValue::Scalar(ScalarValue::Utf8(
63
- values.into_iter().next().flatten(),
64
- )))
65
- } else {
66
- Ok(ColumnarValue::Array(Arc::new(StringArray::from(values))))
67
- }
68
- }
69
- }
70
-
71
- #[cfg(test)]
72
- mod tests {
73
- use super::super::test_support::single_text;
74
-
75
- #[tokio::test]
76
- async fn decodes_utf8_binary_to_text() {
77
- assert_eq!(
78
- single_text("SELECT lix_text_decode(X'416461')").await,
79
- Some("Ada".to_string())
80
- );
81
- }
82
- }
@@ -1,85 +0,0 @@
1
- use std::any::Any;
2
-
3
- use datafusion::arrow::datatypes::DataType;
4
- use datafusion::common::{plan_err, Result, ScalarValue};
5
- use datafusion::logical_expr::{
6
- ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility,
7
- };
8
-
9
- use super::common::{
10
- array_ref, binary_array_from_owned, encode_utf8_value, scalar_inputs,
11
- validate_utf8_encoding_arg,
12
- };
13
-
14
- #[derive(Debug, Clone, PartialEq, Eq, Hash)]
15
- pub(super) struct LixTextEncode {
16
- signature: Signature,
17
- }
18
-
19
- impl LixTextEncode {
20
- pub(super) fn new() -> Self {
21
- Self {
22
- signature: Signature::one_of(
23
- vec![Signature::any(1, Volatility::Immutable).type_signature],
24
- Volatility::Immutable,
25
- ),
26
- }
27
- }
28
- }
29
-
30
- impl ScalarUDFImpl for LixTextEncode {
31
- fn as_any(&self) -> &dyn Any {
32
- self
33
- }
34
-
35
- fn name(&self) -> &str {
36
- "lix_text_encode"
37
- }
38
-
39
- fn signature(&self) -> &Signature {
40
- &self.signature
41
- }
42
-
43
- fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
44
- Ok(DataType::Binary)
45
- }
46
-
47
- fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
48
- if !(1..=2).contains(&args.args.len()) {
49
- return plan_err!("lix_text_encode requires 1 or 2 arguments");
50
- }
51
- validate_utf8_encoding_arg(self.name(), args.args.get(1))?;
52
-
53
- let scalar_inputs = scalar_inputs(&args.args);
54
- let arrays = ColumnarValue::values_to_arrays(&args.args)?;
55
- let input = &arrays[0];
56
- let len = input.len();
57
-
58
- let mut values = Vec::with_capacity(len);
59
- for row in 0..len {
60
- values.push(encode_utf8_value(input.as_ref(), row)?);
61
- }
62
- if scalar_inputs {
63
- Ok(ColumnarValue::Scalar(ScalarValue::Binary(
64
- values.into_iter().next().flatten(),
65
- )))
66
- } else {
67
- Ok(ColumnarValue::Array(array_ref(binary_array_from_owned(
68
- &values,
69
- ))))
70
- }
71
- }
72
- }
73
-
74
- #[cfg(test)]
75
- mod tests {
76
- use super::super::test_support::single_binary;
77
-
78
- #[tokio::test]
79
- async fn encodes_utf8_text_to_binary() {
80
- assert_eq!(
81
- single_binary("SELECT lix_text_encode('Ada')").await,
82
- Some(b"Ada".to_vec())
83
- );
84
- }
85
- }
@@ -1,76 +0,0 @@
1
- use std::any::Any;
2
-
3
- use datafusion::arrow::datatypes::DataType;
4
- use datafusion::common::{plan_err, Result, ScalarValue};
5
- use datafusion::logical_expr::{
6
- ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility,
7
- };
8
-
9
- use crate::functions::FunctionProviderHandle;
10
-
11
- #[derive(Clone)]
12
- pub(super) struct LixTimestamp {
13
- pub(super) functions: FunctionProviderHandle,
14
- }
15
-
16
- impl PartialEq for LixTimestamp {
17
- fn eq(&self, _other: &Self) -> bool {
18
- true
19
- }
20
- }
21
-
22
- impl Eq for LixTimestamp {}
23
-
24
- impl std::hash::Hash for LixTimestamp {
25
- fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
26
- self.name().hash(state);
27
- }
28
- }
29
-
30
- impl std::fmt::Debug for LixTimestamp {
31
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32
- f.debug_struct("LixTimestamp").finish()
33
- }
34
- }
35
-
36
- impl ScalarUDFImpl for LixTimestamp {
37
- fn as_any(&self) -> &dyn Any {
38
- self
39
- }
40
-
41
- fn name(&self) -> &str {
42
- "lix_timestamp"
43
- }
44
-
45
- fn signature(&self) -> &Signature {
46
- static SIGNATURE: std::sync::LazyLock<Signature> =
47
- std::sync::LazyLock::new(|| Signature::nullary(Volatility::Volatile));
48
- &SIGNATURE
49
- }
50
-
51
- fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
52
- Ok(DataType::Utf8)
53
- }
54
-
55
- fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
56
- if !args.args.is_empty() {
57
- return plan_err!("lix_timestamp requires no arguments");
58
- }
59
- Ok(ColumnarValue::Scalar(ScalarValue::Utf8(Some(
60
- self.functions.call_timestamp(),
61
- ))))
62
- }
63
- }
64
-
65
- #[cfg(test)]
66
- mod tests {
67
- use super::super::test_support::single_text;
68
-
69
- #[tokio::test]
70
- async fn returns_timestamp_text() {
71
- let value = single_text("SELECT lix_timestamp()")
72
- .await
73
- .expect("timestamp should not be null");
74
- assert!(!value.is_empty());
75
- }
76
- }
@@ -1,76 +0,0 @@
1
- use std::any::Any;
2
-
3
- use datafusion::arrow::datatypes::DataType;
4
- use datafusion::common::{plan_err, Result, ScalarValue};
5
- use datafusion::logical_expr::{
6
- ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility,
7
- };
8
-
9
- use crate::functions::FunctionProviderHandle;
10
-
11
- #[derive(Clone)]
12
- pub(super) struct LixUuidV7 {
13
- pub(super) functions: FunctionProviderHandle,
14
- }
15
-
16
- impl PartialEq for LixUuidV7 {
17
- fn eq(&self, _other: &Self) -> bool {
18
- true
19
- }
20
- }
21
-
22
- impl Eq for LixUuidV7 {}
23
-
24
- impl std::hash::Hash for LixUuidV7 {
25
- fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
26
- self.name().hash(state);
27
- }
28
- }
29
-
30
- impl std::fmt::Debug for LixUuidV7 {
31
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32
- f.debug_struct("LixUuidV7").finish()
33
- }
34
- }
35
-
36
- impl ScalarUDFImpl for LixUuidV7 {
37
- fn as_any(&self) -> &dyn Any {
38
- self
39
- }
40
-
41
- fn name(&self) -> &str {
42
- "lix_uuid_v7"
43
- }
44
-
45
- fn signature(&self) -> &Signature {
46
- static SIGNATURE: std::sync::LazyLock<Signature> =
47
- std::sync::LazyLock::new(|| Signature::nullary(Volatility::Volatile));
48
- &SIGNATURE
49
- }
50
-
51
- fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
52
- Ok(DataType::Utf8)
53
- }
54
-
55
- fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
56
- if !args.args.is_empty() {
57
- return plan_err!("lix_uuid_v7 requires no arguments");
58
- }
59
- Ok(ColumnarValue::Scalar(ScalarValue::Utf8(Some(
60
- self.functions.call_uuid_v7(),
61
- ))))
62
- }
63
- }
64
-
65
- #[cfg(test)]
66
- mod tests {
67
- use super::super::test_support::single_text;
68
-
69
- #[tokio::test]
70
- async fn returns_uuid_text() {
71
- let value = single_text("SELECT lix_uuid_v7()")
72
- .await
73
- .expect("uuid should not be null");
74
- assert!(!value.is_empty());
75
- }
76
- }
@@ -1,89 +0,0 @@
1
- mod common;
2
- mod lix_active_version_commit_id;
3
- mod lix_empty_blob;
4
- mod lix_json;
5
- mod lix_json_get;
6
- mod lix_json_get_text;
7
- mod lix_text_decode;
8
- mod lix_text_encode;
9
- mod lix_timestamp;
10
- mod lix_uuid_v7;
11
- mod public_call;
12
-
13
- use datafusion::execution::context::SessionContext;
14
- use datafusion::logical_expr::ScalarUDF;
15
-
16
- use crate::functions::FunctionProviderHandle;
17
-
18
- pub(crate) use public_call::validate_public_udf_calls_in_datafusion_statement;
19
-
20
- #[cfg(test)]
21
- pub(crate) fn system_sql2_function_provider() -> FunctionProviderHandle {
22
- use crate::functions::{FunctionProvider, SharedFunctionProvider, SystemFunctionProvider};
23
-
24
- SharedFunctionProvider::new(Box::new(SystemFunctionProvider) as Box<dyn FunctionProvider + Send>)
25
- }
26
-
27
- pub(crate) fn register_sql2_functions(
28
- ctx: &SessionContext,
29
- functions: FunctionProviderHandle,
30
- active_version_commit_id: Option<String>,
31
- ) {
32
- ctx.register_udf(ScalarUDF::from(
33
- lix_active_version_commit_id::LixActiveVersionCommitId::new(active_version_commit_id),
34
- ));
35
- ctx.register_udf(ScalarUDF::from(lix_json_get::LixJsonGet::new()));
36
- ctx.register_udf(ScalarUDF::from(lix_json_get_text::LixJsonGetText::new()));
37
- ctx.register_udf(ScalarUDF::from(lix_text_decode::LixTextDecode::new()));
38
- ctx.register_udf(ScalarUDF::from(lix_text_encode::LixTextEncode::new()));
39
- ctx.register_udf(ScalarUDF::from(lix_json::LixJson));
40
- ctx.register_udf(ScalarUDF::from(lix_empty_blob::LixEmptyBlob));
41
- ctx.register_udf(ScalarUDF::from(lix_uuid_v7::LixUuidV7 {
42
- functions: functions.clone(),
43
- }));
44
- ctx.register_udf(ScalarUDF::from(lix_timestamp::LixTimestamp { functions }));
45
- }
46
-
47
- #[cfg(test)]
48
- pub(super) mod test_support {
49
- use datafusion::arrow::array::{Array, BinaryArray, StringArray};
50
- use datafusion::prelude::SessionContext;
51
-
52
- use super::{register_sql2_functions, system_sql2_function_provider};
53
-
54
- pub(super) async fn single_text(sql: &str) -> Option<String> {
55
- let ctx = SessionContext::new();
56
- register_sql2_functions(&ctx, system_sql2_function_provider(), None);
57
- let batches = ctx
58
- .sql(sql)
59
- .await
60
- .expect("query should plan")
61
- .collect()
62
- .await
63
- .expect("query should execute");
64
- let array = batches[0]
65
- .column(0)
66
- .as_any()
67
- .downcast_ref::<StringArray>()
68
- .expect("first column should be utf8");
69
- (!array.is_null(0)).then(|| array.value(0).to_string())
70
- }
71
-
72
- pub(super) async fn single_binary(sql: &str) -> Option<Vec<u8>> {
73
- let ctx = SessionContext::new();
74
- register_sql2_functions(&ctx, system_sql2_function_provider(), None);
75
- let batches = ctx
76
- .sql(sql)
77
- .await
78
- .expect("query should plan")
79
- .collect()
80
- .await
81
- .expect("query should execute");
82
- let array = batches[0]
83
- .column(0)
84
- .as_any()
85
- .downcast_ref::<BinaryArray>()
86
- .expect("first column should be binary");
87
- (!array.is_null(0)).then(|| array.value(0).to_vec())
88
- }
89
- }
@@ -1,238 +0,0 @@
1
- use std::ops::ControlFlow;
2
-
3
- use datafusion::sql::parser::Statement as DataFusionStatement;
4
- use datafusion::sql::sqlparser::ast::{
5
- Expr, Function, FunctionArg, FunctionArgExpr, FunctionArguments, ObjectNamePart, Statement,
6
- Value, Visit, Visitor,
7
- };
8
- #[cfg(test)]
9
- use datafusion::sql::sqlparser::dialect::GenericDialect;
10
- #[cfg(test)]
11
- use datafusion::sql::sqlparser::parser::Parser;
12
-
13
- use crate::LixError;
14
-
15
- #[cfg(test)]
16
- pub(crate) fn validate_public_udf_calls(sql: &str) -> Result<(), LixError> {
17
- let statements = Parser::parse_sql(&GenericDialect {}, sql).map_err(|error| {
18
- LixError::new(
19
- LixError::CODE_PARSE_ERROR,
20
- format!("sql2 SQL parse error: {error}"),
21
- )
22
- })?;
23
-
24
- let mut visitor = PublicUdfCallVisitor;
25
- match statements.visit(&mut visitor) {
26
- ControlFlow::Continue(()) => Ok(()),
27
- ControlFlow::Break(error) => Err(*error),
28
- }
29
- }
30
-
31
- struct PublicUdfCallVisitor;
32
-
33
- impl Visitor for PublicUdfCallVisitor {
34
- type Break = Box<LixError>;
35
-
36
- fn pre_visit_expr(&mut self, expr: &Expr) -> ControlFlow<Self::Break> {
37
- let Expr::Function(function) = expr else {
38
- return ControlFlow::Continue(());
39
- };
40
-
41
- match validate_public_function_call(function) {
42
- Ok(()) => ControlFlow::Continue(()),
43
- Err(error) => ControlFlow::Break(Box::new(error)),
44
- }
45
- }
46
-
47
- fn pre_visit_statement(&mut self, statement: &Statement) -> ControlFlow<Self::Break> {
48
- match statement {
49
- Statement::CreateFunction(_) | Statement::DropFunction(_) => ControlFlow::Continue(()),
50
- _ => ControlFlow::Continue(()),
51
- }
52
- }
53
- }
54
-
55
- fn validate_public_function_call(function: &Function) -> Result<(), LixError> {
56
- let Some(name) = public_lix_function_name(function) else {
57
- return Ok(());
58
- };
59
- let arity = function_arity(&function.args);
60
-
61
- match name {
62
- "lix_json" => expect_exact_arity(name, arity, 1),
63
- "lix_empty_blob" => expect_exact_arity(name, arity, 0),
64
- "lix_timestamp" => expect_exact_arity(name, arity, 0),
65
- "lix_uuid_v7" => expect_exact_arity(name, arity, 0),
66
- "lix_active_version_commit_id" => expect_exact_arity(name, arity, 0),
67
- "lix_text_encode" | "lix_text_decode" => {
68
- expect_arity_range(name, arity, 1, 2)?;
69
- validate_literal_utf8_encoding(name, &function.args)
70
- }
71
- _ => Ok(()),
72
- }
73
- }
74
-
75
- pub(crate) fn validate_public_udf_calls_in_datafusion_statement(
76
- statement: &DataFusionStatement,
77
- ) -> Result<(), LixError> {
78
- let mut visitor = PublicUdfCallVisitor;
79
- visit_datafusion_statement(statement, &mut visitor)
80
- }
81
-
82
- fn visit_datafusion_statement(
83
- statement: &DataFusionStatement,
84
- visitor: &mut PublicUdfCallVisitor,
85
- ) -> Result<(), LixError> {
86
- match statement {
87
- DataFusionStatement::Statement(statement) => match statement.visit(visitor) {
88
- ControlFlow::Continue(()) => Ok(()),
89
- ControlFlow::Break(error) => Err(*error),
90
- },
91
- DataFusionStatement::Explain(explain) => {
92
- visit_datafusion_statement(explain.statement.as_ref(), visitor)
93
- }
94
- _ => Ok(()),
95
- }
96
- }
97
-
98
- fn public_lix_function_name(function: &Function) -> Option<&'static str> {
99
- let part = function.name.0.last()?;
100
- let ident = match part {
101
- ObjectNamePart::Identifier(ident) => ident.value.as_str(),
102
- ObjectNamePart::Function(_) => return None,
103
- };
104
- match ident.to_ascii_lowercase().as_str() {
105
- "lix_json" => Some("lix_json"),
106
- "lix_empty_blob" => Some("lix_empty_blob"),
107
- "lix_timestamp" => Some("lix_timestamp"),
108
- "lix_uuid_v7" => Some("lix_uuid_v7"),
109
- "lix_active_version_commit_id" => Some("lix_active_version_commit_id"),
110
- "lix_text_encode" => Some("lix_text_encode"),
111
- "lix_text_decode" => Some("lix_text_decode"),
112
- _ => None,
113
- }
114
- }
115
-
116
- fn function_arity(args: &FunctionArguments) -> usize {
117
- match args {
118
- FunctionArguments::None => 0,
119
- FunctionArguments::Subquery(_) => 1,
120
- FunctionArguments::List(list) => list.args.len(),
121
- }
122
- }
123
-
124
- fn expect_exact_arity(name: &str, actual: usize, expected: usize) -> Result<(), LixError> {
125
- if actual == expected {
126
- return Ok(());
127
- }
128
-
129
- let expectation = if expected == 0 {
130
- "no arguments".to_string()
131
- } else if expected == 1 {
132
- "exactly 1 argument".to_string()
133
- } else {
134
- format!("exactly {expected} arguments")
135
- };
136
- Err(invalid_param(format!("{name} requires {expectation}")))
137
- }
138
-
139
- fn expect_arity_range(name: &str, actual: usize, min: usize, max: usize) -> Result<(), LixError> {
140
- if (min..=max).contains(&actual) {
141
- return Ok(());
142
- }
143
- Err(invalid_param(format!(
144
- "{name} requires {min} or {max} arguments"
145
- )))
146
- }
147
-
148
- fn validate_literal_utf8_encoding(name: &str, args: &FunctionArguments) -> Result<(), LixError> {
149
- let Some(encoding) = function_arg(args, 1) else {
150
- return Ok(());
151
- };
152
- let Some(value) = string_literal_arg(encoding) else {
153
- return Ok(());
154
- };
155
- let normalized = value.trim().to_ascii_uppercase().replace('-', "");
156
- if normalized == "UTF8" {
157
- Ok(())
158
- } else {
159
- Err(invalid_param(format!(
160
- "{name}() only supports UTF8 encoding, got '{value}'"
161
- )))
162
- }
163
- }
164
-
165
- fn function_arg(args: &FunctionArguments, index: usize) -> Option<&FunctionArg> {
166
- match args {
167
- FunctionArguments::List(list) => list.args.get(index),
168
- _ => None,
169
- }
170
- }
171
-
172
- fn string_literal_arg(arg: &FunctionArg) -> Option<&str> {
173
- let expr = match arg {
174
- FunctionArg::Unnamed(FunctionArgExpr::Expr(expr))
175
- | FunctionArg::Named {
176
- arg: FunctionArgExpr::Expr(expr),
177
- ..
178
- }
179
- | FunctionArg::ExprNamed {
180
- arg: FunctionArgExpr::Expr(expr),
181
- ..
182
- } => expr,
183
- _ => return None,
184
- };
185
- let Expr::Value(value) = expr else {
186
- return None;
187
- };
188
- match &value.value {
189
- Value::SingleQuotedString(value)
190
- | Value::DoubleQuotedString(value)
191
- | Value::TripleSingleQuotedString(value)
192
- | Value::TripleDoubleQuotedString(value)
193
- | Value::EscapedStringLiteral(value)
194
- | Value::UnicodeStringLiteral(value)
195
- | Value::NationalStringLiteral(value)
196
- | Value::SingleQuotedRawStringLiteral(value)
197
- | Value::DoubleQuotedRawStringLiteral(value)
198
- | Value::TripleSingleQuotedRawStringLiteral(value)
199
- | Value::TripleDoubleQuotedRawStringLiteral(value) => Some(value.as_str()),
200
- Value::DollarQuotedString(value) => Some(value.value.as_str()),
201
- _ => None,
202
- }
203
- }
204
-
205
- fn invalid_param(message: impl Into<String>) -> LixError {
206
- LixError::new(LixError::CODE_INVALID_PARAM, message)
207
- }
208
-
209
- #[cfg(test)]
210
- mod tests {
211
- use super::validate_public_udf_calls;
212
-
213
- #[test]
214
- fn rejects_lix_udf_wrong_arity_as_public_invalid_param() {
215
- let error = validate_public_udf_calls("SELECT lix_uuid_v7('extra')")
216
- .expect_err("wrong arity should be rejected");
217
- assert_eq!(error.code, "LIX_INVALID_PARAM");
218
- assert!(error.message.contains("lix_uuid_v7 requires no arguments"));
219
- }
220
-
221
- #[test]
222
- fn rejects_unsupported_literal_encoding_as_public_invalid_param() {
223
- let error = validate_public_udf_calls("SELECT lix_text_encode('Ada', 'base64')")
224
- .expect_err("unsupported encoding should be rejected");
225
- assert_eq!(error.code, "LIX_INVALID_PARAM");
226
- assert!(error
227
- .message
228
- .contains("lix_text_encode() only supports UTF8 encoding"));
229
- }
230
-
231
- #[test]
232
- fn accepts_valid_public_lix_udf_calls() {
233
- validate_public_udf_calls(
234
- "SELECT lix_json('{\"x\":1}'), lix_text_decode(X'416461', 'utf-8')",
235
- )
236
- .expect("valid calls should pass public validation");
237
- }
238
- }