connect icon indicating copy to clipboard operation
connect copied to clipboard

Unrecognised method for time processing bloblang functions.

Open nathanmac opened this issue 2 years ago • 2 comments

Hi, We have been attempting to make use bloblang processing language using the API however when using some of the new time processing functions we are getting a mapping error unrecognised method 'ts_strftime': ts_st this is using the latest version. This seems to be only happening when using the API because this works when using the cli.

benthos -v
Version: 4.3.0
Date: 2022-06-23T18:32:07Z

echo "{}" | benthos blobl 'root = "2020-08-14T11:45:26.371+01:00".ts_strftime("%Y-%b-%d %H:%M:%S")'
2020-Aug-14 11:45:26

Here some sample code we have tried, and we run it with v4.2.0 and v4.3.0 but get the same error. I appreciate these functions are marked as beta but any advice to get this working would be appreciated. Thanks

package main

import (
	"encoding/json"
	"fmt"

	"github.com/benthosdev/benthos/v4/public/bloblang"
)

var (
	input = `{"timestamp": "2020-08-14T11:45:26.371+01:00"}`
)

func main() {
	env := bloblang.NewEnvironment()

	mapping := `
	root.date = this.timestamp.ts_strftime("%Y-%b-%d %H:%M:%S")
	`

	exc, err := env.Parse(mapping)
	if err != nil {
		fmt.Println(err)
		return
	}

	var jsonDocument interface{}
	jsonErr := json.Unmarshal([]byte(input), &jsonDocument)
	if jsonErr != nil {
		fmt.Println(jsonErr)
		return
	}

	mappedDocument, queryErr := exc.Query(jsonDocument)
	if queryErr != nil {
		fmt.Println(queryErr)
		return
	}

	data, _ := json.Marshal(mappedDocument)
	fmt.Println("--- MAPPED DOC ---")
	fmt.Println(string(data))
	fmt.Println("------------------")
}

nathanmac avatar Jul 08 '22 16:07 nathanmac

Hey @nathanmac you need to include standard bloblang plugins with an _ "github.com/benthosdev/benthos/v4/public/components/pure" import, looks like I need to update the docs as that's only really mentioned in the service APIs.

Jeffail avatar Jul 08 '22 18:07 Jeffail

Awesome that did it. Thanks

nathanmac avatar Jul 08 '22 19:07 nathanmac