-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: start whats'new #287
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fvm install sdf-beta3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,172 +91,10 @@ The sections are as follows: | |
* `functions` - defines functions in the package | ||
* `dev` - defines substitutions used during development and test | ||
|
||
|
||
#### Build and Test a Package | ||
|
||
We'll use the [SDF] command line tool with the package definition file to generate the WebAssembly glue code and the placeholder for the custom logic. | ||
|
||
```bash copy="fl" | ||
$ sdf -h | ||
Stateful Dataflow Command Line Interface | ||
|
||
Usage: sdf <COMMAND> | ||
|
||
Commands: | ||
clean Clean generated artifacts such as state and internal objects | ||
build Build package (requires: sdf-package.yaml) | ||
generate Generate package (requires: sdf-package.yaml) | ||
update Update package (requires: sdf-package.yaml) | ||
test Test command shell (requires sdf-package.yaml) | ||
run Run dataflow (requires: dataflow.yaml) | ||
setup Setup pre-requisites for Stateful Dataflows | ||
version Prints binary version | ||
log Print dataflow logs | ||
``` | ||
|
||
Let's start with an example. Create a package that split sentences into words and counts the number of characters in each word. | ||
|
||
##### 1. Create the Package file | ||
|
||
Create a fresh project directory `split-sentence` with two subdirectories: `packages` and `sentence`: | ||
|
||
```bash | ||
$ mkdir -p split-sentence/packages/sentence | ||
$ cd split-sentence/packages/sentence | ||
``` | ||
|
||
Inside the `sentence` directory and create the `sdf-package.yaml` and add the following content: | ||
|
||
```yaml | ||
#sdf-package.yaml | ||
apiVersion: 0.5.0 | ||
|
||
meta: | ||
name: sentence-pkg | ||
version: 0.1.0 | ||
namespace: example | ||
|
||
functions: | ||
|
||
sentence-to-words: | ||
operator: flat-map | ||
inputs: | ||
- name: sentence | ||
type: string | ||
output: | ||
type: string | ||
|
||
augment-count: | ||
operator: map | ||
inputs: | ||
- name: word | ||
type: string | ||
output: | ||
type: string | ||
|
||
dev: | ||
converter: raw | ||
``` | ||
|
||
##### 2. Generate the Package Project | ||
|
||
Use SDF generate command to build the project: | ||
|
||
```bash copy="fl" | ||
$ sdf generate | ||
``` | ||
|
||
The generator created several directories and files that we'll edit next. | ||
|
||
|
||
##### 3. Add the Custom Code | ||
|
||
First, let's update the first function, `sentence-to-words`. Open `rust/sentence-to-words/src/lib.rs` and update the function body with the following code: | ||
|
||
```rust | ||
pub(crate) fn sentence_to_words(sentence: String) -> Result<Vec<String>> { | ||
Ok(sentence.split_whitespace().map(String::from).collect()) | ||
} | ||
``` | ||
|
||
Next update `augment_count`. Open `rust/augment-count/src/lib.rs` and replace the function body: | ||
|
||
```rust | ||
pub(crate) fn augment_count(word: String) -> Result<String> { | ||
Ok(format!("{}({})", word, word.chars().count())) | ||
} | ||
``` | ||
|
||
Let's add some tests as well: | ||
|
||
```rust | ||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_augment_count() { | ||
let input = "Hello".to_string(); | ||
let output = augment_count(input); | ||
assert_eq!(output.unwrap(), "Hello(5)"); | ||
} | ||
} | ||
``` | ||
|
||
We've implemented both functions; it's time to compile and test our work. | ||
|
||
|
||
##### 4. Build and Test the Package | ||
|
||
To build the package, run: | ||
|
||
```bash | ||
$ sdf build | ||
``` | ||
|
||
Use `sdf test` interactive shell to test the code: | ||
|
||
```bash | ||
$ sdf test | ||
``` | ||
|
||
In the test shell, you can view the functions available for testing: | ||
|
||
```bash copy="fl" | ||
>> show functions | ||
sentence-to-words | ||
augment-count | ||
``` | ||
|
||
Let's test `sentence-to-words` first: | ||
|
||
```bash copy="fl" | ||
>> test function sentence-to-words --input "Hello World" | ||
Hello | ||
World | ||
``` | ||
|
||
Next, test `augment-count`: | ||
|
||
```bash copy="fl" | ||
>> test function augment-count --input "Hello" | ||
Hello(5) | ||
``` | ||
|
||
You may also test the `rust` code via Cargo: | ||
|
||
```bash | ||
$ cd rust | ||
$ cargo test | ||
``` | ||
|
||
The tests passed, and the package is now ready to use in the dataflow file. | ||
|
||
## The Dataflow | ||
|
||
The **dataflow** imports functions, types, and states from one more package. Packages may also import components from others; however, dataflow maintains the final composition. | ||
|
||
|
||
#### `dataflow.yaml` | ||
|
||
The [SDF] command line tool uses the dataflow definition file `dataflow.yaml` to assemble the data application, and it has the following hierarchy: | ||
|
@@ -326,144 +164,16 @@ The sections are as follows: | |
|
||
The dataflow file has other variants such as `window` and `partitions`, which are omitted for simplicity. For additional details check the [Dataflow file] section. | ||
|
||
# Getting started | ||
|
||
#### Create a Dataflow | ||
|
||
We'll import the package built in the [previous](#build-and-test-a-package) section to create the `split-sentence` dataflow. | ||
|
||
##### 1. Create the Dataflow file | ||
|
||
Create a dataflow file in the directory `split-sentence` directory: | ||
|
||
```bash | ||
$ cd split-sentence | ||
``` | ||
|
||
Create the `dataflow.yaml` and add the following content: | ||
|
||
```yaml name="dataflow.yaml" | ||
apiVersion: 0.5.0 | ||
|
||
meta: | ||
name: split-sentence | ||
version: 0.1.0 | ||
namespace: example | ||
|
||
imports: | ||
- pkg: example/[email protected] | ||
functions: | ||
- name: sentence-to-words | ||
- name: augment-count | ||
|
||
config: | ||
converter: raw | ||
|
||
topics: | ||
sentence: | ||
schema: | ||
value: | ||
type: string | ||
converter: raw | ||
words: | ||
schema: | ||
value: | ||
type: string | ||
converter: raw | ||
|
||
services: | ||
sentence-words: | ||
sources: | ||
- type: topic | ||
id: sentence | ||
|
||
transforms: | ||
- operator: flat-map | ||
uses: sentence-to-words | ||
- operator: map | ||
uses: augment-count | ||
|
||
sinks: | ||
- type: topic | ||
id: words | ||
|
||
dev: | ||
imports: | ||
- pkg: example/[email protected] | ||
path: ./packages/sentence | ||
``` | ||
|
||
##### 2. Run the Dataflow | ||
|
||
Use `sdf` command line tool to run the dataflow: | ||
|
||
```bash copy="fl" | ||
$ sdf run --dev | ||
``` | ||
|
||
Use `--dev` to ask the engine to change the path to the local package. Without this flag, the engine will look for the package in `InfinyOn Hub`. | ||
|
||
|
||
##### 3. Test the Dataflow | ||
|
||
1. Produce sentences to in `sentence` topic: | ||
|
||
```bash copy="fl" | ||
$ fluvio produce sentence | ||
``` | ||
|
||
```bash | ||
Hello world | ||
Hi there | ||
``` | ||
|
||
Consume from `words` to retrieve the result: | ||
|
||
```bash | ||
$ fluvio consume words -Bd | ||
``` | ||
See [next section] for a quickstart. | ||
|
||
```bash | ||
Hello(5) | ||
world(5) | ||
Hi(2) | ||
there(5) | ||
``` | ||
|
||
##### 4. Show State | ||
|
||
The dataflow collects runtime metrics that you can inspect in the runtime terminal. | ||
|
||
Check the `sentence-to-words` counters: | ||
|
||
```bash copy="fl" | ||
>> show state sentence-words/sentence-to-words/metrics --table | ||
Key Window succeeded failed | ||
stats * 2 0 | ||
``` | ||
|
||
Check the `augment-count` counters: | ||
|
||
```bash copy="fl" | ||
>> show state sentence-words/augment-count/metrics --table | ||
Key Window succeeded failed | ||
stats * 4 0 | ||
``` | ||
|
||
Congratulations! You've successfully built and run a composable dataflow! The project is available for download in [github]. | ||
|
||
##### 5. Clean-up | ||
|
||
Exit the `sdf` terminal and remove the topics: | ||
|
||
```bash | ||
fluvio topic delete sentence | ||
fluvio topic delete words | ||
``` | ||
|
||
### References | ||
|
||
* [Example Workflows in github] | ||
|
||
[next section]: quickstart.mdx | ||
[Inline Dataflows]: sdf/quickstart.mdx | ||
[Dataflow file]: sdf/concepts/dataflow-yaml.mdx | ||
[SDF]: sdf/cli/index.mdx | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is "Build and Test a Package" removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is duplicated in Quickstart
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep in package and remove in Quickstart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to follow the current docs.
First did https://www.fluvio.io/sdf/composition/overview and then https://www.fluvio.io/sdf/composition/quickstart
When I was in quickstart I got annoyed because it was exactly the same of the last part of overview. Are you suggesting to remove quickstart and only keep all in overview?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see. Yes, the Overview should be concepts and no code (no step-by-step). I didn't realize that part was duplicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is the quickstart for composition, not the quickstart for sdf, Should I remove it? since in composition, inline is not allowed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated my comment above ☝️