Documentation
¶
Overview ¶
Package etler provides a framework for building ETL (Extract, Transform, Load) pipelines.
Example ¶
Demonstrates a complete typed CSV-to-pipeline flow.
package main
import (
"context"
"fmt"
"log"
"strings"
"github.com/thalesfsp/etler/v4/converter"
loadercsv "github.com/thalesfsp/etler/v4/loaders/csv"
"github.com/thalesfsp/etler/v4/pipeline"
"github.com/thalesfsp/etler/v4/processor"
"github.com/thalesfsp/etler/v4/stage"
)
func main() {
type record struct {
Name string
Points int
Active bool
}
type summary struct {
Name string
Points int
Active bool
}
source, err := loadercsv.New[record]()
if err != nil {
log.Fatalln(err)
}
records, err := source.Run(
context.Background(),
strings.NewReader("Name,Points,Active\nalice,2,true\nbob,3,false\n"),
)
if err != nil {
log.Fatalln(err)
}
uppercase, err := processor.New(
"example-root-uppercase",
"uppercases names",
func(_ context.Context, in []record) ([]record, error) {
out := make([]record, len(in))
for i, value := range in {
out[i] = value
out[i].Name = strings.ToUpper(value.Name)
}
return out, nil
},
)
if err != nil {
log.Fatalln(err)
}
double, err := processor.New(
"example-root-double",
"doubles points",
func(_ context.Context, in []record) ([]record, error) {
out := make([]record, len(in))
for i, value := range in {
out[i] = value
out[i].Points = value.Points * 2
}
return out, nil
},
)
if err != nil {
log.Fatalln(err)
}
summarize, err := converter.New(
"example-root-summary",
"converts records to summaries",
func(_ context.Context, in record) (summary, error) {
return summary(in), nil
},
)
if err != nil {
log.Fatalln(err)
}
first, err := stage.New(
"example-root-first",
"normalizes names",
summarize,
uppercase,
)
if err != nil {
log.Fatalln(err)
}
second, err := stage.New(
"example-root-second",
"scores records",
summarize,
double,
)
if err != nil {
log.Fatalln(err)
}
flow, err := pipeline.New(
"example-root-pipeline",
"normalizes and scores CSV records",
false,
first,
second,
)
if err != nil {
log.Fatalln(err)
}
tasks, err := flow.Run(context.Background(), records)
if err != nil {
log.Fatalln(err)
}
for _, value := range tasks[len(tasks)-1].ConvertedData {
fmt.Printf("%s: points=%d active=%t\n", value.Name, value.Points, value.Active)
}
}
Output: ALICE: points=4 active=true BOB: points=6 active=false
Directories
¶
| Path | Synopsis |
|---|---|
|
Package converter wraps value conversions with lifecycle metrics, tracing, logging, and completion callbacks.
|
Package converter wraps value conversions with lifecycle metrics, tracing, logging, and completion callbacks. |
|
converters
|
|
|
csv
Package csv converts slices of values into CSV text.
|
Package csv converts slices of values into CSV text. |
|
passthru
Package passthru provides a converter that returns its input unchanged.
|
Package passthru provides a converter that returns its input unchanged. |
|
storage
Package storage provides a converter that creates items in a storage backend and returns their storage keys.
|
Package storage provides a converter that creates items in a storage backend and returns their storage keys. |
|
internal
|
|
|
csvshape
Package csvshape validates row types before gocsv walks them.
|
Package csvshape validates row types before gocsv walks them. |
|
customapm
Package customapm provides tracing and error-reporting helpers for Elastic APM.
|
Package customapm provides tracing and error-reporting helpers for Elastic APM. |
|
logging
Package logging provides the process-wide application logger and APM correlation helpers.
|
Package logging provides the process-wide application logger and APM correlation helpers. |
|
metrics
Package metrics provides a set of metrics for the application.
|
Package metrics provides a set of metrics for the application. |
|
shared
Package shared provides everything shared between entities.
|
Package shared provides everything shared between entities. |
|
Package loader wraps data-loading functions with lifecycle metrics, tracing, logging, and completion callbacks.
|
Package loader wraps data-loading functions with lifecycle metrics, tracing, logging, and completion callbacks. |
|
loaders
|
|
|
csv
Package csv loads CSV data from an io.Reader into a slice of structs.
|
Package csv loads CSV data from an io.Reader into a slice of structs. |
|
Package pipeline composes stages into an observable ETL pipeline.
|
Package pipeline composes stages into an observable ETL pipeline. |
|
Package processor wraps slice transforms with lifecycle metrics, tracing, logging, pause handling, and completion callbacks.
|
Package processor wraps slice transforms with lifecycle metrics, tracing, logging, pause handling, and completion callbacks. |
|
processors
|
|
|
storage
Package storage provides a processor that concurrently creates input items in a storage backend without changing the processor output.
|
Package storage provides a processor that concurrently creates input items in a storage backend without changing the processor output. |
|
Package stage groups processors with a converter.
|
Package stage groups processors with a converter. |
|
Package task defines the data and metadata passed between pipeline stages.
|
Package task defines the data and metadata passed between pipeline stages. |
Click to show internal directories.
Click to hide internal directories.