Skip to content

Commit

Permalink
Fix outputType struct tag for VirtualColumn expressions (#51)
Browse files Browse the repository at this point in the history
* exclude examples from build

* fix outputType on expressions

Co-authored-by: Shrivardhan Rao <[email protected]>
  • Loading branch information
cosmic-chichu and Shrivardhan Rao authored Sep 14, 2021
1 parent e4e47db commit f9a9537
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
17 changes: 5 additions & 12 deletions builder/virtualcolumn/expression.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package virtualcolumn

type OutputType string

const (
Long OutputType = "LONG"
Float = "FLOAT"
Double = "DOUBLE"
String = "STRING"
)
import "github.com/grafadruid/go-druid/builder/types"

type Expression struct {
Base
Name string `json:"name,omitempty"`
Expression string `json:"expression,omitempty"`
OutputType OutputType
Name string `json:"name,omitempty"`
Expression string `json:"expression,omitempty"`
OutputType types.OutputType `json:"outputType,omitempty"`
}

func NewExpression() *Expression {
Expand All @@ -32,7 +25,7 @@ func (e *Expression) SetExpression(expression string) *Expression {
return e
}

func (e *Expression) SetOutputType(outputType OutputType) *Expression {
func (e *Expression) SetOutputType(outputType types.OutputType) *Expression {
e.OutputType = outputType
return e
}
19 changes: 19 additions & 0 deletions builder/virtualcolumn/expression_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package virtualcolumn

import (
"encoding/json"
"github.com/grafadruid/go-druid/builder/types"
"github.com/stretchr/testify/assert"
"testing"
)

func TestNewExpression(t *testing.T) {
expression := NewExpression()
expression.SetName("dim1").SetExpression("lower(\"dim1\")").SetOutputType(types.String)

expected := `{"type":"expression", "name":"dim1", "expression": "lower(\"dim1\")", "outputType":"STRING"}`

expressionJSON, err := json.Marshal(expression)
assert.Nil(t, err)
assert.JSONEq(t, expected, string(expressionJSON))
}
2 changes: 2 additions & 0 deletions examples/fromjson/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//+build mage

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions examples/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//+build mage

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions examples/tdigestExample.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//+build mage

package main

import (
Expand Down

0 comments on commit f9a9537

Please sign in to comment.