morebeam

package module
v0.0.0-...-3c68a24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

README

More Beam Build Status Coverage Report card GoDoc Libraries.io

Go package which provides additional functions useful when building Apache Beam pipelines in Go.

Documentation available here

How to use

Install:

go get bramp.net/morebeam/...

Example:

import (
    "context"
    "flag"
    "reflect"

    "github.com/apache/beam/sdks/go/pkg/beam"
    "github.com/apache/beam/sdks/go/pkg/beam/x/beamx"
    "github.com/apache/beam/sdks/go/pkg/beam/x/debug"

    "bramp.net/morebeam"
    "bramp.net/morebeam/csvio"
)

// Painting represents a single record in the csv file.
type Painting struct {
    Artist  string `csv:"artist"`
    Title   string `csv:"title"`
    Year    int    `csv:"year"`
    NotUsed string `csv:"-"` // Ignored field
}

func Example() {
    flag.Parse()
    beam.Init()

    p, s := beam.NewPipelineWithRoot()

    // Read the CSV file as a PCollection<Painting>.
    paintings := csvio.Read(s, "paintings.csv", reflect.TypeOf(Painting{}))

    // Reshuffle the CSV output to improve parallelism.
    paintings = morebeam.Reshuffle(s, paintings)

    // Return a new PCollection<KV<string, Painting>> where the key is the artist.
    paintingsByArtist := morebeam.AddKey(s, func(painting Painting) string {
        return painting.Artist
    }, paintings)

    debug.Print(s, paintingsByArtist)

    beamx.Run(context.Background(), p)
}

Licence (Apache 2)

This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.

Copyright 2018 Google LLC

Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Overview

Package morebeam provides additional functions useful for building Apache Beam pipelines.

Example
package main

import (
	"context"
	"flag"
	"reflect"

	"bramp.net/morebeam"
	"bramp.net/morebeam/csvio"
	"github.com/apache/beam/sdks/go/pkg/beam"
	"github.com/apache/beam/sdks/go/pkg/beam/x/beamx"
	"github.com/apache/beam/sdks/go/pkg/beam/x/debug"
)

// Painting represents a single record in the csv file.
type Painting struct {
	Artist  string `csv:"artist"`
	Title   string `csv:"title"`
	Year    int    `csv:"year"`
	NotUsed string `csv:"-"` // Ignored field
}

func main() {
	flag.Parse()
	beam.Init()

	p, s := beam.NewPipelineWithRoot()

	// Read the CSV file as a PCollection<Painting>.
	paintings := csvio.Read(s, "paintings.csv", reflect.TypeOf(Painting{}))

	// Reshuffle the CSV output to improve parallelism.
	paintings = morebeam.Reshuffle(s, paintings)

	// Return a new PCollection<KV<string, Painting>> where the key is the artist.
	paintingsByArtist := morebeam.AddKey(s, func(painting Painting) string {
		return painting.Artist
	}, paintings)

	debug.Print(s, paintingsByArtist)

	beamx.Run(context.Background(), p)

}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddKey

func AddKey(s beam.Scope, keyFn interface{}, col beam.PCollection) beam.PCollection

AddKey takes a PCollection<V> and returns a PCollection<KV<K, V>> where the key is calculated from keyFn.

func Join

func Join(elem ...string) string

Join is similar to path.Join but safe to use on URLs or filepaths.

func Reshuffle

func Reshuffle(s beam.Scope, col beam.PCollection) beam.PCollection

Reshuffle takes a PCollection<A> and shuffles the data to help increase parallelism.

Types

This section is empty.

Directories

Path Synopsis
Package csvio contains Apache Beam transforms for reading CSV files with https://github.com/gocarina/gocsv.
Package csvio contains Apache Beam transforms for reading CSV files with https://github.com/gocarina/gocsv.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL