Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
module github.com/cockroachdb/cockroachdb-parser

go 1.23.8
go 1.24

require (
github.com/bazelbuild/rules_go v0.46.0
github.com/biogo/store v0.0.0-20201120204734-aad293a2328f
github.com/blevesearch/snowballstem v0.9.0
github.com/cockroachdb/apd/v3 v3.1.0
github.com/cockroachdb/crlib v0.0.0-20251122031428-fe658a2dbda1
github.com/cockroachdb/errors v1.11.3
github.com/cockroachdb/gostdlib v1.19.0
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506
github.com/cockroachdb/redact v1.1.5
github.com/cockroachdb/version v0.0.0-20250314144055-3860cd14adf2
github.com/cockroachdb/version v0.0.0-20250509181251-54dac3003410
github.com/dave/dst v0.27.2
github.com/dustin/go-humanize v1.0.0
github.com/gogo/protobuf v1.3.2
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cockroachdb/apd/v3 v3.1.0 h1:MK3Ow7LH0W8zkd5GMKA1PvS9qG3bWFI95WaVNfyZJ/w=
github.com/cockroachdb/apd/v3 v3.1.0/go.mod h1:6qgPBMXjATAdD/VefbRP9NoSLKjbB4LCoA7gN4LpHs4=
github.com/cockroachdb/crlib v0.0.0-20251122031428-fe658a2dbda1 h1:iX0YCYC5Jbt2/g7zNTP/QxhrV8Syp5kkzNiERKeN1uE=
github.com/cockroachdb/crlib v0.0.0-20251122031428-fe658a2dbda1/go.mod h1:NjNuToN/FbhwH1cCyM9G4Rhtxx+ZaOgtoqFR+thng7w=
github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I=
github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8=
github.com/cockroachdb/gostdlib v1.19.0 h1:cSISxkVnTlWhTkyple/T6NXzOi5659FkhxvUgZv+Eb0=
Expand All @@ -68,8 +70,8 @@ github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 h1:ASDL+UJcILM
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506/go.mod h1:Mw7HqKr2kdtu6aYGn3tPmAftiP3QPX63LdK/zcariIo=
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/cockroachdb/version v0.0.0-20250314144055-3860cd14adf2 h1:8Vfw2iNEpYIV6aLtMwT5UOGuPmp9MKlEKWKFTuB+MPU=
github.com/cockroachdb/version v0.0.0-20250314144055-3860cd14adf2/go.mod h1:P9WiZOdQ1R/ZZDL0WzF5wlyRvrjtfhNOwMZymFpBwjE=
github.com/cockroachdb/version v0.0.0-20250509181251-54dac3003410 h1:GuIAxxl30gmd9m7ct6fgYb49GUv8GAxICU5VfU9GRvc=
github.com/cockroachdb/version v0.0.0-20250509181251-54dac3003410/go.mod h1:P9WiZOdQ1R/ZZDL0WzF5wlyRvrjtfhNOwMZymFpBwjE=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
Expand Down
20 changes: 10 additions & 10 deletions patches/0007-update-functions-parser.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ index 4f7bc03..5b31fd0 100644
@@ -51,6 +51,13 @@ const (
// as Oracle is case insensitive if object name is not quoted.
EncAlwaysQuoted

+ // EncSkipEscapeString indicates that the string should not be escaped,
+ // and non-ASCII characters are allowed.
+ // More specifically, it means that the tree.DString won't be wrapped
Expand All @@ -27,7 +27,7 @@ index 4f7bc03..5b31fd0 100644
@@ -165,7 +173,13 @@ func EncodeSQLStringWithFlags(buf *bytes.Buffer, in string, flags EncodeFlags) {
}
}

- if !escapedString {
+ // If non-ASCII characters are allowed,
+ // skip escaping and write the original UTF-8 character.
Expand All @@ -48,7 +48,7 @@ index 4f7bc03..5b31fd0 100644
+ // quote char, so we will write the quote char directly.
+ stringencoding.EncodeEscapedChar(buf, in, r, ch, i, '\'', !skipEscape)
}

- quote := !escapedString && !bareStrings
+ quote := !escapedString && !bareStrings && !skipEscape
if quote {
Expand All @@ -69,7 +69,7 @@ index 05d64e1..dabff21 100644
@@ -1364,6 +1364,19 @@ const (
OrderedSetAgg
)

+// onlyNameFunc is the list of function who can be compiled with only the
+// name. This is for PG compatibility, where examples such as `CURRENT_TIMESTAMP()`
+// is not allowed, but `CURRENT_TIMESTAMP` is allowed.
Expand All @@ -89,7 +89,7 @@ index 05d64e1..dabff21 100644
@@ -1385,41 +1398,43 @@ func (node *FuncExpr) Format(ctx *FmtCtx) {
ctx.FormatNode(&node.Func)
})

- ctx.WriteByte('(')
- ctx.WriteString(typ)
- ctx.FormatNode(&node.Exprs)
Expand Down Expand Up @@ -168,22 +168,22 @@ index 6832c7e..df15c15 100644
--- a/pkg/sql/sem/tree/format.go
+++ b/pkg/sql/sem/tree/format.go
@@ -195,6 +195,10 @@ const (
// FmtSkipAsOfSystemTimeClauses prevents the formatter from printing AS OF
// SYSTEM TIME clauses.
FmtSkipAsOfSystemTimeClauses
// FmtPLpgSQLParen will wrap some expressions in parenthesis when in PLpgSQL
// context. This should only be used in tests.
FmtPLpgSQLParen
+
+ // FmtFuncOnlyName instructs the formating for a function only print
+ // its name, without printing the body of the function nor with the brackets.
+ FmtFuncOnlyName
)

const genericArityIndicator = "__more__"
diff --git a/pkg/util/stringencoding/string_encoding.go b/pkg/util/stringencoding/string_encoding.go
index fcb7fac..afa0090 100644
--- a/pkg/util/stringencoding/string_encoding.go
+++ b/pkg/util/stringencoding/string_encoding.go
@@ -73,6 +73,7 @@ func init() {

// EncodeEscapedChar is used internally to write out a character from a larger
// string that needs to be escaped to a buffer.
+// If slashedQuoteChar is true, it will write a backslash before the quoteChar.
Expand Down
40 changes: 31 additions & 9 deletions pkg/build/bazel/util/tinystringer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (s tinyStringer) computeConstantValues(
if genDecl.Tok != token.CONST {
continue
}
var inferAppropriateType, inIota bool
var inferAppropriateType, inIota, inShift bool
var iotaVal int
for _, spec := range genDecl.Specs {
valueSpec, ok := spec.(*ast.ValueSpec)
Expand Down Expand Up @@ -360,7 +360,11 @@ func (s tinyStringer) computeConstantValues(
if valueSpec.Values == nil {
if inIota {
nameToInt[constName] = iotaVal
iotaVal += 1
if inShift {
iotaVal <<= 1
} else {
iotaVal += 1
}
} else {
nameToInt[constName] = 0
}
Expand Down Expand Up @@ -401,37 +405,55 @@ func (s tinyStringer) computeConstantValues(
inIota = false
}
} else if binExpr, ok := valueSpec.Values[0].(*ast.BinaryExpr); ok {
// Handle iota + N or iota - N.
iotaIdent, ok := binExpr.X.(*ast.Ident)
inShift = false
xArg, yArg := binExpr.X, binExpr.Y
if binExpr.Op == token.SHL {
// Handle 1 << iota - the order of arguments is switched.
inShift = true
xArg, yArg = yArg, xArg
}
// Handle iota + N, iota - N, 1 << iota.
iotaIdent, ok := xArg.(*ast.Ident)
if !ok || iotaIdent.Name != "iota" {
err = fmt.Errorf("expected 'iota' in binary expression %+v; found %+v", binExpr, binExpr.X)
err = fmt.Errorf("expected 'iota' in binary expression %+v; found %+v", binExpr, xArg)
return
}
var otherNumParsed int64
if otherNum, ok := binExpr.Y.(*ast.BasicLit); ok && otherNum.Kind == token.INT {
if otherNum, ok := yArg.(*ast.BasicLit); ok && otherNum.Kind == token.INT {
otherNumParsed, err = strconv.ParseInt(otherNum.Value, 0, 0)
if err != nil {
return
}
} else if otherRef, ok := binExpr.Y.(*ast.Ident); ok {
} else if otherRef, ok := yArg.(*ast.Ident); ok {
otherNum, ok := nameToInt[otherRef.Name]
if !ok {
err = fmt.Errorf("could not find value of %s", otherRef.Name)
return
}
otherNumParsed = int64(otherNum)
} else {
err = fmt.Errorf("couldn't parse second argument of binary expression %+v; found %+v", binExpr, binExpr.Y)
err = fmt.Errorf("couldn't parse second argument of binary expression %+v; found %+v", binExpr, yArg)
return
}
if binExpr.Op == token.ADD {
iotaVal = iotaVal + int(otherNumParsed)
} else if binExpr.Op == token.SUB {
iotaVal = iotaVal - int(otherNumParsed)
} else if binExpr.Op == token.SHL {
// We currently assume 1 << iota and not N << iota.
if otherNumParsed != 1 {
err = fmt.Errorf("only 1 << iota is supported; found %d << iota", otherNumParsed)
return
}
iotaVal = int(otherNumParsed)
}
inIota = true
nameToInt[constName] = iotaVal
iotaVal += 1
if inShift {
iotaVal <<= 1
} else {
iotaVal += 1
}
} else {
err = fmt.Errorf("don't know how to process %+v", valueSpec.Values[0])
return
Expand Down
18 changes: 12 additions & 6 deletions pkg/build/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package build

import (
"bytes"
"crypto/fips140"
_ "embed"
"fmt"
"runtime"
Expand Down Expand Up @@ -35,8 +36,9 @@ var (
channel string
)

// Distribution is changed by the CCL init-time hook in non-APL builds.
var Distribution = "OSS"
// Distribution is a historical artifact from when we had OSS and non-OSS (CCL)
// builds.
const Distribution = "CCL"

var (
cgoCompiler = cgoVersion()
Expand Down Expand Up @@ -107,16 +109,16 @@ func BinaryVersion() string {
// It returns "vX.Y" for all release versions, and all prerelease versions >= "alpha.1".
// X and Y are the major and minor, respectively, of the version specified in version.txt.
// For all other prerelease versions, it returns "dev".
// N.B. new public-facing doc URLs are expected to be up beginning with the "alpha.1" prerelease. Otherwise, "dev" will
// N.B. new public-facing doc URLs are expected to be up once the "alpha.1" prerelease is shipped. Otherwise, "dev" will
// cause the url mapper to redirect to the latest stable release.
func VersionForURLs() string {
if parsedVersionTxt.IsPrerelease() {
phaseAndOrdinal := parsedVersionTxt.Format("%P.%o")
// builds prior to "alpha.1" use 'dev' in their URLs
if phaseAndOrdinal < "alpha.1" {
// builds use 'dev' in their URLs until "alpha.1" is shipped
if phaseAndOrdinal <= "alpha.1" {
return "dev"
}
} else if parsedVersionTxt.IsCustomOrNightlyBuild() {
} else if parsedVersionTxt.IsCustomOrAdhocBuild() {
return "dev"
}
return parsedVersionTxt.Major().String()
Expand Down Expand Up @@ -168,6 +170,10 @@ func (b Info) Long() string {
fmt.Fprintf(tw, "C Compiler: %s\n", b.CgoCompiler)
fmt.Fprintf(tw, "Build Commit ID: %s\n", b.Revision)
fmt.Fprintf(tw, "Build Type: %s\n", b.Type)
if fips140.Enabled() {
fmt.Fprintf(tw, "FIPS enabled: true\n")
}

fmt.Fprintf(tw, "Enabled Assertions: %t", b.EnabledAssertions) // No final newline: cobra prints one for us.
_ = tw.Flush()
return buf.String()
Expand Down
37 changes: 33 additions & 4 deletions pkg/col/coldata/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ import (

// JSONs is a representation of columnar JSON data. It's simply a wrapper around
// the flat Bytes structure. To pull a JSON out of the structure, we construct
// a new "encodedJSON" object from scratch on demand.
// a new JSONEncoded object from scratch on demand.
type JSONs struct {
Bytes
// jsonScratch batches allocations of JSONEncoded objects (under the
// assumption that the vector doesn't have NULLs).
jsonScratch []json.JSONEncoded
// scratch is a scratch space for encoding a JSON object on demand.
scratch []byte
}

// NewJSONs returns a new JSONs presized to n elements.
func NewJSONs(n int) *JSONs {
return &JSONs{
Bytes: *NewBytes(n),
Bytes: *NewBytes(n),
jsonScratch: make([]json.JSONEncoded, n),
}
}

Expand All @@ -38,11 +42,12 @@ func (js *JSONs) Get(i int) json.JSON {
if len(bytes) == 0 {
return json.NullJSONValue
}
ret, err := json.FromEncoding(bytes)
j := &js.jsonScratch[i]
err := json.FromEncodingInto(bytes, j)
if err != nil {
colexecerror.ExpectedError(err)
}
return ret
return j
}

// Set sets the ith JSON in JSONs.
Expand All @@ -62,6 +67,13 @@ func (js *JSONs) Set(i int, j json.JSON) {
func (js *JSONs) Window(start, end int) *JSONs {
return &JSONs{
Bytes: *js.Bytes.Window(start, end),
// TODO(yuzefovich): in the general case, if we simply reused
// js.jsonScratch here, it could lead to problems down the line (because
// Get calls on js and on the window into js would be reusing the same
// JSONEncoded object). However, in practice the windowed batch should
// be consumed soon after it's created, without the overlap with Gets on
// the original batch. Think through this.
jsonScratch: make([]json.JSONEncoded, end-start),
}
}

Expand All @@ -81,12 +93,14 @@ func (js *JSONs) CopySlice(src *JSONs, destIdx, srcStartIdx, srcEndIdx int) {
// values from src into the receiver starting at destIdx.
func (js *JSONs) AppendSlice(src *JSONs, destIdx, srcStartIdx, srcEndIdx int) {
js.Bytes.AppendSlice(&src.Bytes, destIdx, srcStartIdx, srcEndIdx)
js.ensureJSONScratch()
}

// appendSliceWithSel appends all values specified in sel from the source into
// the receiver starting at position destIdx.
func (js *JSONs) appendSliceWithSel(src *JSONs, destIdx int, sel []int) {
js.Bytes.appendSliceWithSel(&src.Bytes, destIdx, sel)
js.ensureJSONScratch()
}

// String is used for debugging purposes.
Expand All @@ -99,3 +113,18 @@ func (js *JSONs) String() string {
}
return builder.String()
}

// Deserialize updates b according to the "arrow-like" format that was produced
// by Serialize.
func (js *JSONs) Deserialize(data []byte, offsets []int32) {
js.Bytes.Deserialize(data, offsets)
js.ensureJSONScratch()
}

func (js *JSONs) ensureJSONScratch() {
if cap(js.jsonScratch) < js.Bytes.Len() {
js.jsonScratch = make([]json.JSONEncoded, js.Bytes.Len())
} else {
js.jsonScratch = js.jsonScratch[:js.Bytes.Len()]
}
}
4 changes: 4 additions & 0 deletions pkg/col/coldata/vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/cockroachdb/cockroachdb-parser/pkg/col/typeconv"
"github.com/cockroachdb/cockroachdb-parser/pkg/sql/types"
"github.com/cockroachdb/cockroachdb-parser/pkg/util/json"
)

// Column is an interface that represents a raw array of a Go native type.
Expand Down Expand Up @@ -160,11 +161,14 @@ func (cf *defaultColumnFactory) MakeColumns(columns []Column, t *types.T, length
}
case types.JsonFamily:
alloc := make([]element, allocLength)
jsonScratchAlloc := make([]json.JSONEncoded, allocLength)
wrapperAlloc := make([]JSONs, len(columns))
for i := range columns {
wrapperAlloc[i].elements = alloc[:length:length]
wrapperAlloc[i].jsonScratch = jsonScratchAlloc[:length:length]
columns[i] = &wrapperAlloc[i]
alloc = alloc[length:]
jsonScratchAlloc = jsonScratchAlloc[length:]
}
default:
panic(fmt.Sprintf("StandardColumnFactory doesn't support %s", t))
Expand Down
8 changes: 4 additions & 4 deletions pkg/geo/geomfn/distance.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func distanceInternal(
aIt := geo.NewGeomTIterator(aGeomT, emptyBehavior)
aGeom, aNext, aErr := aIt.Next()
if aErr != nil {
return 0, err
return 0, aErr
}
for aNext {
aGeodist, err := geomToGeodist(aGeom)
Expand All @@ -231,7 +231,7 @@ func distanceInternal(
bIt := geo.NewGeomTIterator(bGeomT, emptyBehavior)
bGeom, bNext, bErr := bIt.Next()
if bErr != nil {
return 0, err
return 0, bErr
}
for bNext {
bGeodist, err := geomToGeodist(bGeom)
Expand All @@ -248,13 +248,13 @@ func distanceInternal(

bGeom, bNext, bErr = bIt.Next()
if bErr != nil {
return 0, err
return 0, bErr
}
}

aGeom, aNext, aErr = aIt.Next()
if aErr != nil {
return 0, err
return 0, aErr
}
}
return c.DistanceUpdater().Distance(), nil
Expand Down
Loading
Loading