Skip to content
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

Add example flows (top-level) / (metacrate) #24

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

AlexSanches1
Copy link
Contributor

No description provided.

@AlexSanches1 AlexSanches1 self-assigned this Nov 26, 2024
@AlexSanches1 AlexSanches1 requested a review from artob as a code owner November 26, 2024 05:31
@AlexSanches1 AlexSanches1 changed the title Add example flows (top-level) Add example flows (top-level)/(metacrate) Nov 29, 2024
@AlexSanches1 AlexSanches1 changed the title Add example flows (top-level)/(metacrate) Add example flows (top-level) / (metacrate) Nov 29, 2024
@AlexSanches1 AlexSanches1 assigned artob and unassigned AlexSanches1 Nov 29, 2024
Copy link
Contributor

@SamuelSarle SamuelSarle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM although for some reason I'm unable to run these:

  • examples/csv_roundtrip.rs
  • examples/hash_content.rs
  • examples/log_directories.rs

Were you able to run those? They give import errors that I haven't been able to solve for TextBlocks::concat_strings_by, TextBlocks::decode_csv, TextBlocks::encode_csv, and HashBlocks::hash_sha2.
Specifically that would be the implementations missing for protoflow_blocks::System but of course all of those are present in the repo (lib/protoflow-blocks/src/system.rs)

Examples:

error[E0599]: no method named `encode_csv` found for mutable reference `&mut protoflow::protoflow_blocks::System` in the current scope
error[E0599]: no method named `decode_csv` found for mutable reference `&mut protoflow::protoflow_blocks::System` in the current scope
error[E0599]: no method named `hash_sha2` found for mutable reference `&mut protoflow::protoflow_blocks::System` in the current scope
error[E0599]: no method named `concat_strings_by` found for mutable reference `&mut protoflow::protoflow_blocks::System` in the current scope

lib/protoflow/examples/process_env_var/main.rs Outdated Show resolved Hide resolved
Comment on lines +7 to +10
let json = s.const_string(r#"{"Name": "Alice","Age": 25,"Score": 90}"#);

let line_encoder = s.encode_lines();
s.connect(&json.output, &line_encoder.input);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we should probably implement a Const helper which can output Bytes from a string. This behaves correctly but the line_encoder looks a bit funny here :)

Comment on lines +7 to +10
let input_string = s.const_string("The quick brown fox jumps over the lazy dog");

let encoder = s.encode_lines();
s.connect(&input_string.output, &encoder.input);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise for here as hex("$string\n") != hex("$string")

Comment on lines +7 to +13
let input_string = s.const_string("54686520717569636b2062726f776e20666f78206a756d7073206f76657220746865206c617a7920646f670a");

let encoder = s.encode_lines();
s.connect(&input_string.output, &encoder.input);

let hex_decoder = s.decode_hex();
s.connect(&encoder.output, &hex_decoder.input);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same problem, with interesting behaviour with DecodeHex! This appends a newline at the end before sending it to DecodeHex which should result in an error. But DecodeHex uses Bytes::chunks_exact(2) which leaves the newline character alone as it's one byte:

The chunks are slices and do not overlap. If chunk_size does not divide the length of the
slice, then the last up to chunk_size-1 elements will be omitted and can be retrieved
from the remainder function of the iterator.

I think that DecodeHex shouldn't accept and ignore the last byte silently so we should make a PR so that it checks the content length is divisible by two.

Comment on lines +13 to +15
let content = s.const_string("Hello, World!");
let line_encoder = s.encode_lines();
let hash_content = s.hash_sha2();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not able to run this file directly but copying the code to somewhere else you get

$ echo "Hello, World!" | sha256sum
c98c24b677eff44860afea6f493bbaec5bb1c4cbb209c6fc2bbb47f66ff2ad31

instead of the correct

$ echo -n "Hello, World!" | sha256sum
dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f

due to the s.encode_lines() adding a newline that also gets hashed.

Co-authored-by: Samuel Sarle <[email protected]>
Signed-off-by: Oleksandr Yakovenko <[email protected]>
Co-authored-by: Samuel Sarle <[email protected]>
Signed-off-by: Oleksandr Yakovenko <[email protected]>
@AlexSanches1 AlexSanches1 assigned AlexSanches1 and unassigned artob Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants