This page describes how code patterns work internally as part of Keboola.
Code pattern is a special type of component, therefore the common interface applies to it. To integrate your own components into Keboola, use the following links:
It’s important to know that
KBC_TOKEN
environment variable.
This section shows how the code generation process works from start to end:
keboola.example-pattern
.keboola.snowflake-transformation
.keboola.example-pattern
component.exit code = 0
stdout
contains JSON in the output format.exit code = 1 or 2
There are two types of component actions:
Code patterns do not implement the run action. They only implement the generate synchronous action.
The expected behavior of the generate action:
CMD
process defined in the Dockerfile
is started in the container.stdout
.exit code = 0
(or with another return value if an error occurs).The configuration file config.json
in the KBC_DATADIR
contains:
action
key set to the generate
value as a name of the action to executestorage
key – contains the current input and output mapping from the transformation.
parameters
key – modifies the generated code.
_componentId
key contains the ID of the target transformation component.
keboola.snowflake-transformation
Note: Learn more about the KBC_DATADIR
environment variable.
An example configuration (examples of the storage
key can be found here):
{
"action": "generate",
"storage": {
"input": {
"tables": ["..."]
},
"output": {
"tables": ["..."]
}
},
"parameters": {
"_componentId": "keboola.snowflake-transformation",
"form_parameter_1": "value 1",
"form_parameter_2": "value 2"
}
}
The component must write the generated code to stdout
in the following JSON format:
storage
key contains the new transformation’s input and output mapping.
storage
key.parameters
key with the generated code
parameters
key.blocks
-> codes
-> script
must be used. See below.script
array.An example configuration (examples of the storage
key can be found here):
{
"storage": {
"input": {
"tables": ["..."]
},
"output": {
"tables": ["..."]
}
},
"parameters": {
"blocks": [
{
"name": "Generated block",
"codes": [
{
"name": "Generated code",
"script": [
"CREATE TABLE table1;",
"SELECT foo1, foo2 FROM table2 INTO bar;"
]
}
]
}
]
}
}
Each newly created component must be registered in the Keboola Developer Portal.
Start with creating a simple “Hello, World!” component. To create a code pattern component, you must take the following additional steps:
First, create a component with the Code Pattern
type.
Open the component edit page, and modify the settings described in the following sections.
Each code pattern can generate a code for one or more transformation component types.
They are specified in the configuration schema in
the root-level supported_components
key, as an array of component IDs.
When creating one of the listed transformation components, the published code pattern will be available in the select box.
The code pattern’s configuration contains
the parameters._componentId
key, so it is possible to distinguish for which transformation component the code is generated.