Skip to content

Commit

Permalink
fix(build/config): Self-Referential Jsonnet Function (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshlbrd authored Aug 5, 2024
1 parent 351fc0e commit f58665a
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 3 deletions.
4 changes: 2 additions & 2 deletions build/config/substation.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@
iget: $.transform.enrich.kv_store.item.get,
iset: $.transform.enrich.kv_store.item.set,
item: {
get: $.transform.enrich.kv_store.item.get,
set: $.transform.enrich.kv_store.item.set,
get: $.transform.enrich.kv_store.get,
set: $.transform.enrich.kv_store.set,
},
// In future releases this will also be `set.add`.
sadd(settings={}): {
Expand Down
22 changes: 22 additions & 0 deletions examples/config/transform/enrich/kvstore_csv/config.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This example shows how to use the `enrich_kv_store_item_get` transform
// to lookup data in a KV store backed by a CSV file.
local sub = import '../../../../../build/config/substation.libsonnet';

// This CSV file must be local to the Substation app. Absolute paths are
// recommended. Files accessible over HTTPS and hosted in AWS S3 also work.
//
// The `column` parameter is required and specifies the column in the CSV file
// that will be used to lookup the key in the KV store.
local kv = sub.kv_store.csv_file({ file: 'kv.csv', column: 'product' });

{
transforms: [
// The CSV file KV store returns the entire row minus the key column.
// For example, this returns {"price":"9.99","calories":"500"} for "churro".
sub.tf.enrich.kv_store.item.get({
object: { source_key: 'product', target_key: 'info'},
kv_store: kv,
}),
sub.tf.send.stdout(),
],
}
1 change: 1 addition & 0 deletions examples/config/transform/enrich/kvstore_csv/data.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"product":"churro"}
4 changes: 4 additions & 0 deletions examples/config/transform/enrich/kvstore_csv/kv.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
product,price,calories
churro,9.99,500
donut,1.99,300
eclair,2.99,400
17 changes: 17 additions & 0 deletions examples/config/transform/enrich/kvstore_json/config.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This example shows how to use the `enrich_kv_store_item_get` transform
// to lookup data in a KV store backed by a JSON file.
local sub = import '../../../../../build/config/substation.libsonnet';

// This JSON file must be local to the Substation app. Absolute paths are
// recommended. Files accessible over HTTPS and hosted in AWS S3 also work.
local kv = sub.kv_store.json_file({ file: 'kv.json' });

{
transforms: [
sub.tf.enrich.kv_store.item.get({
object: { source_key: 'product', target_key: 'price'},
kv_store: kv,
}),
sub.tf.send.stdout(),
],
}
1 change: 1 addition & 0 deletions examples/config/transform/enrich/kvstore_json/data.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"product":"churro"}
1 change: 1 addition & 0 deletions examples/config/transform/enrich/kvstore_json/kv.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"churro":9.99}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local mem = sub.kv_store.memory();
transforms: [
// Each order is stored in memory indexed by the customer's email
// address and printed to stdout. Only unique orders are stored.
sub.tf.enrich.kv_store.set.add({
sub.tf.enrich.kv_store.sadd({
object: { source_key: 'customer', target_key: 'order'},
kv_store: mem,
ttl_offset: '10s',
Expand Down

0 comments on commit f58665a

Please sign in to comment.