Skip to content

Commit

Permalink
Add jq and try_jq function. (matrixorigin#17217)
Browse files Browse the repository at this point in the history
Added jq and try_jq function.

Approved by: @m-schen, @zhangxu19830126, @heni02, @XuPeng-SH
  • Loading branch information
fengttt authored Jul 8, 2024
1 parent 0b4a2fe commit 850b992
Show file tree
Hide file tree
Showing 11 changed files with 1,024 additions and 33 deletions.
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.6.0
github.com/hashicorp/memberlist v0.3.1
github.com/itchyny/gojq v0.12.16
github.com/jhump/protoreflect v1.15.2
github.com/lni/dragonboat/v4 v4.0.0-20220815145555-6f622e8bcbef
github.com/lni/goutils v1.3.1-0.20220604063047-388d67b4dbc4
Expand Down Expand Up @@ -68,7 +69,7 @@ require (
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/sync v0.6.0
golang.org/x/sys v0.18.0
golang.org/x/sys v0.20.0
gonum.org/v1/gonum v0.14.0
google.golang.org/grpc v1.62.1
google.golang.org/protobuf v1.33.0
Expand All @@ -87,6 +88,7 @@ require (
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/gosimple/slug v1.13.1 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/itchyny/timefmt-go v0.1.6 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
Expand All @@ -98,7 +100,7 @@ require (
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/segmentio/encoding v0.3.6 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
Expand Down
15 changes: 10 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ github.com/iris-contrib/i18n v0.0.0-20171121225848-987a633949d0/go.mod h1:pMCz62
github.com/iris-contrib/jade v1.1.3/go.mod h1:H/geBymxJhShH5kecoiOCSssPX7QWYH7UaeZTSWddIk=
github.com/iris-contrib/pongo2 v0.0.1/go.mod h1:Ssh+00+3GAZqSQb30AvBRNxBx7rf0GqwkjqxNd0u65g=
github.com/iris-contrib/schema v0.0.1/go.mod h1:urYA3uvUNG1TIIjOSCzHr9/LmbQo8LrOcOqfqxa4hXw=
github.com/itchyny/gojq v0.12.16 h1:yLfgLxhIr/6sJNVmYfQjTIv0jGctu6/DgDoivmxTr7g=
github.com/itchyny/gojq v0.12.16/go.mod h1:6abHbdC2uB9ogMS38XsErnfqJ94UlngIJGlRAIj4jTM=
github.com/itchyny/timefmt-go v0.1.6 h1:ia3s54iciXDdzWzwaVKXZPbiXzxxnv1SPGFfM/myJ5Q=
github.com/itchyny/timefmt-go v0.1.6/go.mod h1:RRDZYC5s9ErkjQvTvvU7keJjxUYzIISJGxm9/mAERQg=
github.com/jhump/protoreflect v1.15.2 h1:7YppbATX94jEt9KLAc5hICx4h6Yt3SaavhQRsIUEHP0=
github.com/jhump/protoreflect v1.15.2/go.mod h1:4ORHmSBmlCW8fh3xHmJMGyul1zNqZK4Elxc8qKP+p1k=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down Expand Up @@ -489,8 +493,8 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
Expand Down Expand Up @@ -628,8 +632,9 @@ github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdO
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.0.1-alpha.1/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down Expand Up @@ -956,8 +961,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
15 changes: 4 additions & 11 deletions pkg/container/nulls/nulls.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,11 @@ func (nsp *Nulls) ReadNoCopy(data []byte) error {
return nil
}

// XXX This API is foundementally broken. Depends on empty or not
// this shit may or may not modify nsp.
func (nsp *Nulls) Or(m *Nulls) *Nulls {
if m.np.EmptyByFlag() {
return nsp
}
if nsp.np.EmptyByFlag() {
return m
// Or the m Nulls into nsp.
func (nsp *Nulls) Or(m *Nulls) {
if !m.np.EmptyByFlag() {
nsp.np.Or(&m.np)
}

nsp.np.Or(&m.np)
return nsp
}

func (nsp *Nulls) IsSame(m *Nulls) bool {
Expand Down
17 changes: 17 additions & 0 deletions pkg/container/vector/functionTools.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/matrixorigin/matrixone/pkg/common/bitmap"
"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
)

Expand Down Expand Up @@ -457,6 +458,22 @@ func (fr *FunctionResult[T]) AppendMustNullForBytesResult() error {
return appendOneFixed(fr.vec, v, true, fr.mp)
}

func (fr *FunctionResult[T]) AddNullRange(start, end uint64) {
fr.vec.nsp.AddRange(start, end)
}

func (fr *FunctionResult[T]) AddNullAt(idx uint64) {
fr.vec.nsp.Add(idx)
}

func (fr *FunctionResult[T]) AddNulls(ns *nulls.Nulls) {
fr.vec.nsp.Or(ns)
}

func (fr *FunctionResult[T]) GetNullAt(idx uint64) bool {
return fr.vec.nsp.Contains(idx)
}

func (fr *FunctionResult[T]) GetType() types.Type {
return *fr.vec.GetType()
}
Expand Down
29 changes: 14 additions & 15 deletions pkg/sql/plan/function/baseTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2353,33 +2353,32 @@ func opBinaryStrStrToFixedWithErrorCheck[Tr types.FixedSizeTExceptStrType](
p1 := vector.GenerateFunctionStrParameter(parameters[0])
p2 := vector.GenerateFunctionStrParameter(parameters[1])
rs := vector.MustFunctionResult[Tr](result)
rsVec := rs.GetResultVector()
rss := vector.MustFixedCol[Tr](rsVec)
rss := vector.MustFixedCol[Tr](rs.GetResultVector())

c1, c2 := parameters[0].IsConst(), parameters[1].IsConst()
rsNull := rsVec.GetNulls()
rsAnyNull := false

if selectList != nil {
if selectList.IgnoreAllRow() {
nulls.AddRange(rsNull, 0, uint64(length))
rs.AddNullRange(0, uint64(length))
return nil
}
if !selectList.ShouldEvalAllRow() {
rsAnyNull = true
for i := range selectList.SelectList {
if selectList.Contains(uint64(i)) {
rsNull.Add(uint64(i))
rs.AddNullAt(uint64(i))
}
}
}
}

if c1 && c2 {
v1, null1 := p1.GetStrValue(0)
v2, null2 := p2.GetStrValue(0)
ifNull := null1 || null2
if ifNull {
nulls.AddRange(rsNull, 0, uint64(length))
rs.AddNullRange(0, uint64(length))
} else {
r, err := fn(functionUtil.QuickBytesToStr(v1), functionUtil.QuickBytesToStr(v2))
if err != nil {
Expand All @@ -2397,14 +2396,14 @@ func opBinaryStrStrToFixedWithErrorCheck[Tr types.FixedSizeTExceptStrType](
if c1 {
v1, null1 := p1.GetStrValue(0)
if null1 {
nulls.AddRange(rsNull, 0, uint64(length))
rs.AddNullRange(0, uint64(length))
} else {
x := functionUtil.QuickBytesToStr(v1)
if p2.WithAnyNullValue() || rsAnyNull {
nulls.Or(rsNull, parameters[1].GetNulls(), rsNull)
rs.AddNulls(parameters[1].GetNulls())
rowCount := uint64(length)
for i := uint64(0); i < rowCount; i++ {
if rsNull.Contains(i) {
if rs.GetNullAt(i) {
continue
}
v2, _ := p2.GetStrValue(i)
Expand All @@ -2430,14 +2429,14 @@ func opBinaryStrStrToFixedWithErrorCheck[Tr types.FixedSizeTExceptStrType](
if c2 {
v2, null2 := p2.GetStrValue(0)
if null2 {
nulls.AddRange(rsNull, 0, uint64(length))
rs.AddNullRange(0, uint64(length))
} else {
y := functionUtil.QuickBytesToStr(v2)
if p1.WithAnyNullValue() || rsAnyNull {
nulls.Or(rsNull, parameters[0].GetNulls(), rsNull)
rs.AddNulls(parameters[0].GetNulls())
rowCount := uint64(length)
for i := uint64(0); i < rowCount; i++ {
if rsNull.Contains(i) {
if rs.GetNullAt(i) {
continue
}
v1, _ := p1.GetStrValue(i)
Expand All @@ -2462,11 +2461,11 @@ func opBinaryStrStrToFixedWithErrorCheck[Tr types.FixedSizeTExceptStrType](

// basic case.
if p1.WithAnyNullValue() || p2.WithAnyNullValue() || rsAnyNull {
nulls.Or(rsNull, parameters[0].GetNulls(), rsNull)
nulls.Or(rsNull, parameters[1].GetNulls(), rsNull)
rs.AddNulls(parameters[0].GetNulls())
rs.AddNulls(parameters[1].GetNulls())
rowCount := uint64(length)
for i := uint64(0); i < rowCount; i++ {
if rsNull.Contains(i) {
if rs.GetNullAt(i) {
continue
}
v1, _ := p1.GetStrValue(i)
Expand Down
Loading

0 comments on commit 850b992

Please sign in to comment.