From 4e0dd3ce1b3d8ba5bfcab7964c6685b85a1a8997 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Fri, 5 Aug 2022 10:34:56 -0700 Subject: [PATCH 1/2] colexecbase: propagate bytes.Buffer as argument in cast templates This is not used currently but will be in the following commit. Release note: None --- pkg/sql/colexec/colexecbase/cast.eg.go | 2113 +++++++++++++---- pkg/sql/colexec/colexecbase/cast_tmpl.go | 18 +- .../colexec/execgen/cmd/execgen/cast_gen.go | 4 +- .../execgen/cmd/execgen/cast_gen_util.go | 76 +- .../execgen/cmd/execgen/overloads_base.go | 2 +- 5 files changed, 1636 insertions(+), 577 deletions(-) diff --git a/pkg/sql/colexec/colexecbase/cast.eg.go b/pkg/sql/colexec/colexecbase/cast.eg.go index 7507dd6d39c3..25073f820b44 100644 --- a/pkg/sql/colexec/colexecbase/cast.eg.go +++ b/pkg/sql/colexec/colexecbase/cast.eg.go @@ -927,6 +927,7 @@ type castOpBase struct { colIdx int outputIdx int evalCtx *eval.Context + buf bytes.Buffer } func (c *castOpBase) Reset(ctx context.Context) { @@ -1164,9 +1165,13 @@ func (c *castBoolFloatOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1186,9 +1191,13 @@ func (c *castBoolFloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -1214,9 +1223,13 @@ func (c *castBoolFloatOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1236,9 +1249,13 @@ func (c *castBoolFloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -1296,9 +1313,13 @@ func (c *castBoolInt2Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1318,9 +1339,13 @@ func (c *castBoolInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -1346,9 +1371,13 @@ func (c *castBoolInt2Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1368,9 +1397,13 @@ func (c *castBoolInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -1428,9 +1461,13 @@ func (c *castBoolInt4Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1450,9 +1487,13 @@ func (c *castBoolInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -1478,9 +1519,13 @@ func (c *castBoolInt4Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1500,9 +1545,13 @@ func (c *castBoolInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -1560,9 +1609,13 @@ func (c *castBoolIntOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1582,9 +1635,13 @@ func (c *castBoolIntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -1610,9 +1667,13 @@ func (c *castBoolIntOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1632,9 +1693,13 @@ func (c *castBoolIntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -1692,9 +1757,13 @@ func (c *castBytesUuidOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1715,9 +1784,13 @@ func (c *castBytesUuidOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -1740,9 +1813,13 @@ func (c *castBytesUuidOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1763,9 +1840,13 @@ func (c *castBytesUuidOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -1820,9 +1901,13 @@ func (c *castDateDecimalOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1843,9 +1928,13 @@ func (c *castDateDecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -1872,9 +1961,13 @@ func (c *castDateDecimalOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1895,9 +1988,13 @@ func (c *castDateDecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -1956,9 +2053,13 @@ func (c *castDateFloatOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -1975,9 +2076,13 @@ func (c *castDateFloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2000,9 +2105,13 @@ func (c *castDateFloatOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2019,9 +2128,13 @@ func (c *castDateFloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2076,9 +2189,13 @@ func (c *castDateInt2Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2099,9 +2216,13 @@ func (c *castDateInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2128,9 +2249,13 @@ func (c *castDateInt2Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2151,9 +2276,13 @@ func (c *castDateInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2212,9 +2341,13 @@ func (c *castDateInt4Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2235,9 +2368,13 @@ func (c *castDateInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2264,9 +2401,13 @@ func (c *castDateInt4Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2287,9 +2428,13 @@ func (c *castDateInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2348,9 +2493,13 @@ func (c *castDateIntOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2365,9 +2514,13 @@ func (c *castDateIntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2388,9 +2541,13 @@ func (c *castDateIntOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2405,9 +2562,13 @@ func (c *castDateIntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2460,9 +2621,13 @@ func (c *castDecimalBoolOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2477,9 +2642,13 @@ func (c *castDecimalBoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2500,9 +2669,13 @@ func (c *castDecimalBoolOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2517,9 +2690,13 @@ func (c *castDecimalBoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2572,9 +2749,13 @@ func (c *castDecimalDecimalOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2594,9 +2775,13 @@ func (c *castDecimalDecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2622,9 +2807,13 @@ func (c *castDecimalDecimalOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2644,9 +2833,13 @@ func (c *castDecimalDecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2704,9 +2897,13 @@ func (c *castDecimalFloatOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2729,9 +2926,13 @@ func (c *castDecimalFloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2760,9 +2961,13 @@ func (c *castDecimalFloatOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2785,9 +2990,13 @@ func (c *castDecimalFloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2848,9 +3057,13 @@ func (c *castDecimalInt2Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2884,9 +3097,13 @@ func (c *castDecimalInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -2926,9 +3143,13 @@ func (c *castDecimalInt2Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -2962,9 +3183,13 @@ func (c *castDecimalInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3036,9 +3261,13 @@ func (c *castDecimalInt4Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3072,9 +3301,13 @@ func (c *castDecimalInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3114,9 +3347,13 @@ func (c *castDecimalInt4Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3150,9 +3387,13 @@ func (c *castDecimalInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3224,9 +3465,13 @@ func (c *castDecimalIntOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3254,9 +3499,13 @@ func (c *castDecimalIntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3290,9 +3539,13 @@ func (c *castDecimalIntOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3320,9 +3573,13 @@ func (c *castDecimalIntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3388,9 +3645,13 @@ func (c *castFloatBoolOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3407,9 +3668,13 @@ func (c *castFloatBoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3432,9 +3697,13 @@ func (c *castFloatBoolOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3451,9 +3720,13 @@ func (c *castFloatBoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3508,9 +3781,13 @@ func (c *castFloatDecimalOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3533,9 +3810,13 @@ func (c *castFloatDecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3564,9 +3845,13 @@ func (c *castFloatDecimalOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3589,9 +3874,13 @@ func (c *castFloatDecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3652,9 +3941,13 @@ func (c *castFloatInt2Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3674,9 +3967,13 @@ func (c *castFloatInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3702,9 +3999,13 @@ func (c *castFloatInt2Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3724,9 +4025,13 @@ func (c *castFloatInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3784,9 +4089,13 @@ func (c *castFloatInt4Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3806,9 +4115,13 @@ func (c *castFloatInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3834,9 +4147,13 @@ func (c *castFloatInt4Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3856,9 +4173,13 @@ func (c *castFloatInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3916,9 +4237,13 @@ func (c *castFloatIntOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3938,9 +4263,13 @@ func (c *castFloatIntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -3966,9 +4295,13 @@ func (c *castFloatIntOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -3988,9 +4321,13 @@ func (c *castFloatIntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4048,9 +4385,13 @@ func (c *castInt2BoolOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4067,9 +4408,13 @@ func (c *castInt2BoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4092,9 +4437,13 @@ func (c *castInt2BoolOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4111,9 +4460,13 @@ func (c *castInt2BoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4168,9 +4521,13 @@ func (c *castInt2DecimalOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4191,9 +4548,13 @@ func (c *castInt2DecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4220,9 +4581,13 @@ func (c *castInt2DecimalOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4243,9 +4608,13 @@ func (c *castInt2DecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4304,9 +4673,13 @@ func (c *castInt2FloatOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4323,9 +4696,13 @@ func (c *castInt2FloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4348,9 +4725,13 @@ func (c *castInt2FloatOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4367,9 +4748,13 @@ func (c *castInt2FloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4424,9 +4809,13 @@ func (c *castInt2Int4Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4441,9 +4830,13 @@ func (c *castInt2Int4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4464,9 +4857,13 @@ func (c *castInt2Int4Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4481,9 +4878,13 @@ func (c *castInt2Int4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4536,9 +4937,13 @@ func (c *castInt2IntOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4553,9 +4958,13 @@ func (c *castInt2IntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4576,9 +4985,13 @@ func (c *castInt2IntOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4593,9 +5006,13 @@ func (c *castInt2IntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4648,9 +5065,13 @@ func (c *castInt4BoolOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4667,9 +5088,13 @@ func (c *castInt4BoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4692,9 +5117,13 @@ func (c *castInt4BoolOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4711,9 +5140,13 @@ func (c *castInt4BoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4768,9 +5201,13 @@ func (c *castInt4DecimalOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4791,9 +5228,13 @@ func (c *castInt4DecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4820,9 +5261,13 @@ func (c *castInt4DecimalOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4843,9 +5288,13 @@ func (c *castInt4DecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4904,9 +5353,13 @@ func (c *castInt4FloatOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4923,9 +5376,13 @@ func (c *castInt4FloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -4948,9 +5405,13 @@ func (c *castInt4FloatOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -4967,9 +5428,13 @@ func (c *castInt4FloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5024,9 +5489,13 @@ func (c *castInt4Int2Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5047,9 +5516,13 @@ func (c *castInt4Int2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5076,9 +5549,13 @@ func (c *castInt4Int2Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5099,9 +5576,13 @@ func (c *castInt4Int2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5160,9 +5641,13 @@ func (c *castInt4IntOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5177,9 +5662,13 @@ func (c *castInt4IntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5200,9 +5689,13 @@ func (c *castInt4IntOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5217,9 +5710,13 @@ func (c *castInt4IntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5272,9 +5769,13 @@ func (c *castIntBoolOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5291,9 +5792,13 @@ func (c *castIntBoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5316,9 +5821,13 @@ func (c *castIntBoolOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5335,9 +5844,13 @@ func (c *castIntBoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5392,9 +5905,13 @@ func (c *castIntDecimalOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5415,9 +5932,13 @@ func (c *castIntDecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5444,9 +5965,13 @@ func (c *castIntDecimalOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5467,9 +5992,13 @@ func (c *castIntDecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5528,9 +6057,13 @@ func (c *castIntFloatOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5547,9 +6080,13 @@ func (c *castIntFloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5572,9 +6109,13 @@ func (c *castIntFloatOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5591,9 +6132,13 @@ func (c *castIntFloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5648,9 +6193,13 @@ func (c *castIntInt2Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5671,9 +6220,13 @@ func (c *castIntInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5700,9 +6253,13 @@ func (c *castIntInt2Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5723,9 +6280,13 @@ func (c *castIntInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5784,9 +6345,13 @@ func (c *castIntInt4Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5807,9 +6372,13 @@ func (c *castIntInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5836,9 +6405,13 @@ func (c *castIntInt4Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5859,9 +6432,13 @@ func (c *castIntInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int @@ -5920,9 +6497,13 @@ func (c *castJsonbStringOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -5948,9 +6529,13 @@ func (c *castJsonbStringOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -5978,9 +6563,13 @@ func (c *castJsonbStringOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6006,9 +6595,13 @@ func (c *castJsonbStringOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -6068,9 +6661,13 @@ func (c *castStringBoolOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6091,9 +6688,13 @@ func (c *castStringBoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6118,9 +6719,13 @@ func (c *castStringBoolOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6141,9 +6746,13 @@ func (c *castStringBoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6200,9 +6809,13 @@ func (c *castStringBytesOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6223,9 +6836,13 @@ func (c *castStringBytesOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -6248,9 +6865,13 @@ func (c *castStringBytesOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6271,9 +6892,13 @@ func (c *castStringBytesOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -6328,9 +6953,13 @@ func (c *castStringDateOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6353,9 +6982,13 @@ func (c *castStringDateOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6382,9 +7015,13 @@ func (c *castStringDateOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6407,9 +7044,13 @@ func (c *castStringDateOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6468,9 +7109,13 @@ func (c *castStringDecimalOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6506,9 +7151,13 @@ func (c *castStringDecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6548,9 +7197,13 @@ func (c *castStringDecimalOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6586,9 +7239,13 @@ func (c *castStringDecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6660,9 +7317,13 @@ func (c *castStringFloatOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6684,9 +7345,13 @@ func (c *castStringFloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6712,9 +7377,13 @@ func (c *castStringFloatOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6736,9 +7405,13 @@ func (c *castStringFloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6796,9 +7469,13 @@ func (c *castStringInt2Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6828,9 +7505,13 @@ func (c *castStringInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6864,9 +7545,13 @@ func (c *castStringInt2Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6896,9 +7581,13 @@ func (c *castStringInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6964,9 +7653,13 @@ func (c *castStringInt4Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -6996,9 +7689,13 @@ func (c *castStringInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7032,9 +7729,13 @@ func (c *castStringInt4Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -7064,9 +7765,13 @@ func (c *castStringInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7132,9 +7837,13 @@ func (c *castStringIntOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -7158,9 +7867,13 @@ func (c *castStringIntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7188,9 +7901,13 @@ func (c *castStringIntOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -7214,9 +7931,13 @@ func (c *castStringIntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7276,9 +7997,13 @@ func (c *castStringIntervalOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -7303,9 +8028,13 @@ func (c *castStringIntervalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7334,9 +8063,13 @@ func (c *castStringIntervalOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -7361,9 +8094,13 @@ func (c *castStringIntervalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7424,9 +8161,13 @@ func (c *castStringJsonbOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -7447,9 +8188,13 @@ func (c *castStringJsonbOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -7472,9 +8217,13 @@ func (c *castStringJsonbOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -7495,9 +8244,13 @@ func (c *castStringJsonbOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -7552,9 +8305,13 @@ func (c *castStringStringOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -7595,9 +8352,13 @@ func (c *castStringStringOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -7640,9 +8401,13 @@ func (c *castStringStringOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -7683,9 +8448,13 @@ func (c *castStringStringOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -7760,9 +8529,13 @@ func (c *castStringTimestampOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -7789,9 +8562,13 @@ func (c *castStringTimestampOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7822,9 +8599,13 @@ func (c *castStringTimestampOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -7851,9 +8632,13 @@ func (c *castStringTimestampOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7916,9 +8701,13 @@ func (c *castStringTimestamptzOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -7945,9 +8734,13 @@ func (c *castStringTimestamptzOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7978,9 +8771,13 @@ func (c *castStringTimestamptzOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8007,9 +8804,13 @@ func (c *castStringTimestamptzOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -8072,9 +8873,13 @@ func (c *castStringUuidOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8095,9 +8900,13 @@ func (c *castStringUuidOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -8120,9 +8929,13 @@ func (c *castStringUuidOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8143,9 +8956,13 @@ func (c *castStringUuidOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -8201,9 +9018,13 @@ func (c *castDatumBoolOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8226,9 +9047,13 @@ func (c *castDatumBoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -8255,9 +9080,13 @@ func (c *castDatumBoolOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8280,9 +9109,13 @@ func (c *castDatumBoolOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -8342,9 +9175,13 @@ func (c *castDatumInt2Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8367,9 +9204,13 @@ func (c *castDatumInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -8396,9 +9237,13 @@ func (c *castDatumInt2Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8421,9 +9266,13 @@ func (c *castDatumInt2Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -8483,9 +9332,13 @@ func (c *castDatumInt4Op) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8508,9 +9361,13 @@ func (c *castDatumInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -8537,9 +9394,13 @@ func (c *castDatumInt4Op) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8562,9 +9423,13 @@ func (c *castDatumInt4Op) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -8624,9 +9489,13 @@ func (c *castDatumIntOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8649,9 +9518,13 @@ func (c *castDatumIntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -8678,9 +9551,13 @@ func (c *castDatumIntOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8703,9 +9580,13 @@ func (c *castDatumIntOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -8765,9 +9646,13 @@ func (c *castDatumFloatOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8790,9 +9675,13 @@ func (c *castDatumFloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -8819,9 +9708,13 @@ func (c *castDatumFloatOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8844,9 +9737,13 @@ func (c *castDatumFloatOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -8906,9 +9803,13 @@ func (c *castDatumDecimalOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8931,9 +9832,13 @@ func (c *castDatumDecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -8960,9 +9865,13 @@ func (c *castDatumDecimalOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -8985,9 +9894,13 @@ func (c *castDatumDecimalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -9047,9 +9960,13 @@ func (c *castDatumDateOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9072,9 +9989,13 @@ func (c *castDatumDateOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -9101,9 +10022,13 @@ func (c *castDatumDateOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9126,9 +10051,13 @@ func (c *castDatumDateOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -9188,9 +10117,13 @@ func (c *castDatumTimestampOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9213,9 +10146,13 @@ func (c *castDatumTimestampOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -9242,9 +10179,13 @@ func (c *castDatumTimestampOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9267,9 +10208,13 @@ func (c *castDatumTimestampOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -9329,9 +10274,13 @@ func (c *castDatumIntervalOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9354,9 +10303,13 @@ func (c *castDatumIntervalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -9383,9 +10336,13 @@ func (c *castDatumIntervalOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9408,9 +10365,13 @@ func (c *castDatumIntervalOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -9470,9 +10431,13 @@ func (c *castDatumStringOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9495,9 +10460,13 @@ func (c *castDatumStringOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -9522,9 +10491,13 @@ func (c *castDatumStringOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9547,9 +10520,13 @@ func (c *castDatumStringOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -9607,9 +10584,13 @@ func (c *castDatumBytesOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9632,9 +10613,13 @@ func (c *castDatumBytesOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -9659,9 +10644,13 @@ func (c *castDatumBytesOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9684,9 +10673,13 @@ func (c *castDatumBytesOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -9744,9 +10737,13 @@ func (c *castDatumTimestamptzOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9769,9 +10766,13 @@ func (c *castDatumTimestamptzOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -9798,9 +10799,13 @@ func (c *castDatumTimestamptzOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9823,9 +10828,13 @@ func (c *castDatumTimestamptzOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -9885,9 +10894,13 @@ func (c *castDatumUuidOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9910,9 +10923,13 @@ func (c *castDatumUuidOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -9937,9 +10954,13 @@ func (c *castDatumUuidOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -9962,9 +10983,13 @@ func (c *castDatumUuidOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -10022,9 +11047,13 @@ func (c *castDatumJsonbOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -10047,9 +11076,13 @@ func (c *castDatumJsonbOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -10074,9 +11107,13 @@ func (c *castDatumJsonbOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -10099,9 +11136,13 @@ func (c *castDatumJsonbOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -10158,9 +11199,13 @@ func (c *castDatumDatumOp) Next() coldata.Batch { outputNulls.Copy(inputNulls) if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -10189,9 +11234,13 @@ func (c *castDatumDatumOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -10222,9 +11271,13 @@ func (c *castDatumDatumOp) Next() coldata.Batch { } else { if sel != nil { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = sel[i] @@ -10253,9 +11306,13 @@ func (c *castDatumDatumOp) Next() coldata.Batch { } } else { { - var evalCtx *eval.Context = c.evalCtx - // Silence unused warning. + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. _ = evalCtx + _ = buf var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i diff --git a/pkg/sql/colexec/colexecbase/cast_tmpl.go b/pkg/sql/colexec/colexecbase/cast_tmpl.go index aac8c39b058e..861ab85a8ce9 100644 --- a/pkg/sql/colexec/colexecbase/cast_tmpl.go +++ b/pkg/sql/colexec/colexecbase/cast_tmpl.go @@ -22,6 +22,7 @@ package colexecbase import ( + "bytes" "context" "fmt" "math" @@ -81,7 +82,7 @@ const _TYPE_WIDTH = 0 // "castOp" template in the scope of this value's "callsite". const _GENERATE_CAST_OP = 0 -func _CAST(to, from, evalCtx, toType interface{}) { +func _CAST(to, from, evalCtx, toType, buf interface{}) { colexecerror.InternalError(errors.AssertionFailedf("")) } @@ -235,6 +236,7 @@ type castOpBase struct { colIdx int outputIdx int evalCtx *eval.Context + buf bytes.Buffer } func (c *castOpBase) Reset(ctx context.Context) { @@ -448,15 +450,15 @@ func (c *cast_NAMEOp) Next() coldata.Batch { if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) if sel != nil { - castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, true, true) + castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, &c.buf, true, true) } else { - castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, true, false) + castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, &c.buf, true, false) } } else { if sel != nil { - castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, false, true) + castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, &c.buf, false, true) } else { - castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, false, false) + castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, &c.buf, false, false) } } }, @@ -516,11 +518,13 @@ func castTuples( n int, sel []int, evalCtx *eval.Context, + buf *bytes.Buffer, hasNulls bool, hasSel bool, ) { - // Silence unused warning. + // Silence unused warnings. _ = evalCtx + _ = buf if !hasSel { // {{if $fromInfo.Sliceable}} _ = inputCol.Get(n - 1) @@ -546,7 +550,7 @@ func castTuples( } v := inputCol.Get(tupleIdx) var r _TO_GO_TYPE - _CAST(r, v, evalCtx, toType) + _CAST(r, v, evalCtx, toType, buf) if !hasSel { // {{if .Sliceable}} //gcassert:bce diff --git a/pkg/sql/colexec/execgen/cmd/execgen/cast_gen.go b/pkg/sql/colexec/execgen/cmd/execgen/cast_gen.go index 7e5532e639c9..8384089e5f64 100644 --- a/pkg/sql/colexec/execgen/cmd/execgen/cast_gen.go +++ b/pkg/sql/colexec/execgen/cmd/execgen/cast_gen.go @@ -32,8 +32,8 @@ func genCastOperators(inputFileContents string, wr io.Writer) error { ) s := r.Replace(inputFileContents) - castRe := makeFunctionRegex("_CAST", 4) - s = castRe.ReplaceAllString(s, makeTemplateFunctionCall("Cast", 4)) + castRe := makeFunctionRegex("_CAST", 5) + s = castRe.ReplaceAllString(s, makeTemplateFunctionCall("Cast", 5)) tmpl, err := template.New("cast").Funcs(template.FuncMap{"buildDict": buildDict}).Parse(s) if err != nil { diff --git a/pkg/sql/colexec/execgen/cmd/execgen/cast_gen_util.go b/pkg/sql/colexec/execgen/cmd/execgen/cast_gen_util.go index 5a4a587ad69c..66fb6bf5c4a8 100644 --- a/pkg/sql/colexec/execgen/cmd/execgen/cast_gen_util.go +++ b/pkg/sql/colexec/execgen/cmd/execgen/cast_gen_util.go @@ -107,7 +107,7 @@ type supportedNativeCastInfo struct { cast castFunc } -func boolToIntOrFloat(to, from, _, _ string) string { +func boolToIntOrFloat(to, from, _, _, _ string) string { convStr := ` %[1]s = 0 if %[2]s { @@ -117,7 +117,7 @@ func boolToIntOrFloat(to, from, _, _ string) string { return fmt.Sprintf(convStr, to, from) } -func bytesToUUID(to, from, _, _ string) string { +func bytesToUUID(to, from, _, _, _ string) string { convStr := ` _uuid, err := uuid.FromBytes(%[2]s) if err != nil { @@ -128,15 +128,15 @@ func bytesToUUID(to, from, _, _ string) string { return fmt.Sprintf(convStr, to, from) } -func decimalToBool(to, from, _, _ string) string { +func decimalToBool(to, from, _, _, _ string) string { return fmt.Sprintf("%[1]s = %[2]s.Sign() != 0", to, from) } -func decimalToDecimal(to, from, _, toType string) string { +func decimalToDecimal(to, from, _, toType, _ string) string { return toDecimal(fmt.Sprintf(`%[1]s.Set(&%[2]s)`, to, from), to, toType) } -func decimalToFloat(to, from, _, _ string) string { +func decimalToFloat(to, from, _, _, _ string) string { convStr := ` { f, err := %[2]s.Float64() @@ -153,7 +153,7 @@ func getDecimalToIntCastFunc(toIntWidth int32) castFunc { if toIntWidth == anyWidth { toIntWidth = 64 } - return func(to, from, evalCtx, toType string) string { + return func(to, from, evalCtx, toType, buf string) string { // convStr is a format string expecting three arguments: // 1. the code snippet that performs an assigment of int64 local // variable named '_i' to the result, possibly performing the bounds @@ -184,7 +184,7 @@ func getDecimalToIntCastFunc(toIntWidth int32) castFunc { } return fmt.Sprintf( convStr, - getIntToIntCastFunc(64 /* fromWidth */, toIntWidth)(to, "_i" /* from */, evalCtx, toType), + getIntToIntCastFunc(64 /* fromWidth */, toIntWidth)(to, "_i" /* from */, evalCtx, toType, buf), from, errOutOfRange, ) @@ -204,14 +204,14 @@ func toDecimal(conv, to, toType string) string { return fmt.Sprintf(convStr, conv, to, toType) } -func numToBool(to, from, _, _ string) string { +func numToBool(to, from, _, _, _ string) string { convStr := ` %[1]s = %[2]s != 0 ` return fmt.Sprintf(convStr, to, from) } -func floatToDecimal(to, from, _, toType string) string { +func floatToDecimal(to, from, _, toType, _ string) string { convStr := ` if _, err := %[1]s.SetFloat64(float64(%[2]s)); err != nil { colexecerror.ExpectedError(err) @@ -220,8 +220,8 @@ func floatToDecimal(to, from, _, toType string) string { return toDecimal(fmt.Sprintf(convStr, to, from), to, toType) } -func floatToInt(intWidth, floatWidth int32) func(string, string, string, string) string { - return func(to, from, _, _ string) string { +func floatToInt(intWidth, floatWidth int32) castFunc { + return func(to, from, _, _, _ string) string { convStr := ` if math.IsNaN(float64(%[2]s)) || %[2]s <= float%[4]d(math.MinInt%[3]d) || %[2]s >= float%[4]d(math.MaxInt%[3]d) { colexecerror.ExpectedError(tree.ErrIntOutOfRange) @@ -235,14 +235,14 @@ func floatToInt(intWidth, floatWidth int32) func(string, string, string, string) } } -func intToDecimal(to, from, _, toType string) string { +func intToDecimal(to, from, _, toType, _ string) string { conv := ` %[1]s.SetInt64(int64(%[2]s)) ` return toDecimal(fmt.Sprintf(conv, to, from), to, toType) } -func intToFloat(to, from, _, _ string) string { +func intToFloat(to, from, _, _, _ string) string { convStr := ` %[1]s = float64(%[2]s) ` @@ -257,7 +257,7 @@ func getIntToIntCastFunc(fromWidth, toWidth int32) castFunc { if toWidth == anyWidth { toWidth = 64 } - return func(to, from, _, _ string) string { + return func(to, from, _, _, _ string) string { if fromWidth <= toWidth { // If we're not reducing the width, there is no need to perform the // integer range check. @@ -286,7 +286,7 @@ func getIntToIntCastFunc(fromWidth, toWidth int32) castFunc { } } -func jsonToString(to, from, _, toType string) string { +func jsonToString(to, from, _, toType, _ string) string { convStr := ` _string := %[2]s.String() switch %[3]s.Oid() { @@ -302,7 +302,7 @@ func jsonToString(to, from, _, toType string) string { return fmt.Sprintf(convStr, to, from, toType) } -func stringToBool(to, from, _, _ string) string { +func stringToBool(to, from, _, _, _ string) string { convStr := ` var err error %[1]s, err = tree.ParseBool(string(%[2]s)) @@ -313,7 +313,7 @@ func stringToBool(to, from, _, _ string) string { return fmt.Sprintf(convStr, to, from) } -func stringToBytes(to, from, _, _ string) string { +func stringToBytes(to, from, _, _, _ string) string { convStr := ` var err error %[1]s, err = lex.DecodeRawBytesToByteArrayAuto(%[2]s) @@ -324,7 +324,7 @@ func stringToBytes(to, from, _, _ string) string { return fmt.Sprintf(convStr, to, from) } -func stringToDate(to, from, evalCtx, _ string) string { +func stringToDate(to, from, evalCtx, _, _ string) string { convStr := ` _now := %[3]s.GetRelativeParseTime() _dateStyle := %[3]s.GetDateStyle() @@ -337,7 +337,7 @@ func stringToDate(to, from, evalCtx, _ string) string { return fmt.Sprintf(convStr, to, from, evalCtx) } -func stringToDecimal(to, from, _, toType string) string { +func stringToDecimal(to, from, _, toType, _ string) string { convStr := ` _s := strings.TrimSpace(string(%[2]s)) _, res, err := tree.ExactCtx.SetString(&%[1]s, _s) @@ -359,7 +359,7 @@ func stringToDecimal(to, from, _, toType string) string { return toDecimal(fmt.Sprintf(convStr, to, from), to, toType) } -func stringToFloat(to, from, _, toType string) string { +func stringToFloat(to, from, _, toType, _ string) string { convStr := ` _s := string(%[2]s) var _err error @@ -375,7 +375,7 @@ func getStringToIntCastFunc(toIntWidth int32) castFunc { if toIntWidth == anyWidth { toIntWidth = 64 } - return func(to, from, evalCtx, toType string) string { + return func(to, from, evalCtx, toType, buf string) string { // convStr is a format string expecting three arguments: // 1. the code snippet that performs an assigment of int64 local // variable named '_i' to the result, possibly performing the bounds @@ -394,14 +394,14 @@ func getStringToIntCastFunc(toIntWidth int32) castFunc { ` return fmt.Sprintf( convStr, - getIntToIntCastFunc(64 /* fromWidth */, toIntWidth)(to, "_i" /* from */, evalCtx, toType), + getIntToIntCastFunc(64 /* fromWidth */, toIntWidth)(to, "_i" /* from */, evalCtx, toType, buf), from, toType, ) } } -func stringToInterval(to, from, evalCtx, toType string) string { +func stringToInterval(to, from, evalCtx, toType, _ string) string { convStr := ` _itm, err := %[4]s.IntervalTypeMetadata() if err != nil { @@ -416,7 +416,7 @@ func stringToInterval(to, from, evalCtx, toType string) string { return fmt.Sprintf(convStr, to, from, evalCtx, toType) } -func stringToJSON(to, from, _, _ string) string { +func stringToJSON(to, from, _, _, _ string) string { convStr := ` var err error %[1]s, err = json.ParseJSON(string(%[2]s)) @@ -427,7 +427,7 @@ func stringToJSON(to, from, _, _ string) string { return fmt.Sprintf(convStr, to, from) } -func stringToString(to, from, _, toType string) string { +func stringToString(to, from, _, toType, _ string) string { convStr := ` if %[3]s.Oid() == oid.T_name { // For Names we don't perform the truncation, and there is no need @@ -458,8 +458,8 @@ func stringToString(to, from, _, toType string) string { return fmt.Sprintf(convStr, to, from, toType) } -func getStringToTimestampCastFunc(withoutTimezone bool) func(_, _, _, _ string) string { - return func(to, from, evalCtx, toType string) string { +func getStringToTimestampCastFunc(withoutTimezone bool) castFunc { + return func(to, from, evalCtx, toType, _ string) string { var parseTimestampKind string if withoutTimezone { parseTimestampKind = "WithoutTimezone" @@ -484,7 +484,7 @@ func getStringToTimestampCastFunc(withoutTimezone bool) func(_, _, _, _ string) } } -func stringToUUID(to, from, _, _ string) string { +func stringToUUID(to, from, _, _, _ string) string { convStr := ` _uuid, err := uuid.FromString(string(%[2]s)) if err != nil { @@ -499,10 +499,8 @@ func stringToUUID(to, from, _, _ string) string { // to a value of the specified physical representation (i.e. to natively // supported type). The returned castFunc assumes that there is a converter // function named "converter" in scope. -func getDatumToNativeCastFunc( - nonDatumPhysicalRepresentation string, -) func(string, string, string, string) string { - return func(to, from, evalCtx, toType string) string { +func getDatumToNativeCastFunc(nonDatumPhysicalRepresentation string) castFunc { + return func(to, from, evalCtx, toType, _ string) string { convStr := ` { _castedDatum, err := eval.PerformCast(%[3]s, %[2]s.(tree.Datum), %[4]s) @@ -516,7 +514,7 @@ func getDatumToNativeCastFunc( } } -func datumToDatum(to, from, evalCtx, toType string) string { +func datumToDatum(to, from, evalCtx, toType, _ string) string { convStr := ` { _castedDatum, err := eval.PerformCast(%[3]s, %[2]s.(tree.Datum), %[4]s) @@ -638,8 +636,8 @@ func (i castToWidthTmplInfo) TypeName() string { return getTypeName(i.toType) } -func (i castToWidthTmplInfo) Cast(to, from, evalCtx, toType string) string { - return i.CastFn(to, from, evalCtx, toType) +func (i castToWidthTmplInfo) Cast(to, from, evalCtx, toType, buf string) string { + return i.CastFn(to, from, evalCtx, toType, buf) } func (i castToWidthTmplInfo) Sliceable() bool { @@ -662,8 +660,8 @@ func (i castDatumToWidthTmplInfo) TypeName() string { return getTypeName(i.toType) } -func (i castDatumToWidthTmplInfo) Cast(to, from, evalCtx, toType string) string { - return i.CastFn(to, from, evalCtx, toType) +func (i castDatumToWidthTmplInfo) Cast(to, from, evalCtx, toType, buf string) string { + return i.CastFn(to, from, evalCtx, toType, buf) } func (i castDatumToWidthTmplInfo) Sliceable() bool { @@ -674,8 +672,8 @@ func (i castBetweenDatumsTmplInfo) TypeName() string { return datumVecTypeName } -func (i castBetweenDatumsTmplInfo) Cast(to, from, evalCtx, toType string) string { - return datumToDatum(to, from, evalCtx, toType) +func (i castBetweenDatumsTmplInfo) Cast(to, from, evalCtx, toType, buf string) string { + return datumToDatum(to, from, evalCtx, toType, buf) } func (i castBetweenDatumsTmplInfo) Sliceable() bool { diff --git a/pkg/sql/colexec/execgen/cmd/execgen/overloads_base.go b/pkg/sql/colexec/execgen/cmd/execgen/overloads_base.go index 21f067226667..126ccbdf9dd1 100644 --- a/pkg/sql/colexec/execgen/cmd/execgen/overloads_base.go +++ b/pkg/sql/colexec/execgen/cmd/execgen/overloads_base.go @@ -359,7 +359,7 @@ type twoArgsResolvedOverloadRightWidthInfo struct { type assignFunc func(op *lastArgWidthOverload, targetElem, leftElem, rightElem, targetCol, leftCol, rightCol string) string type compareFunc func(targetElem, leftElem, rightElem, leftCol, rightCol string) string -type castFunc func(to, from, evalCtx, toType string) string +type castFunc func(to, from, evalCtx, toType, buf string) string type hashFunc func(targetElem, vElem, vVec, vIdx string) string // Assign produces a Go source string that assigns the "targetElem" variable to From e20e1637f6b4cd7baa146dab4df545a0ec7ff9fe Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Fri, 5 Aug 2022 11:30:26 -0700 Subject: [PATCH 2/2] colexecbase: add all casts of native types to strings This commit adds all of the casts from the types natively supported by the vectorized engine to strings. This has an additional benefit (apart from better performance on a lot of data: the concat binary projection with a string on one side is now supported natively (we recently fixed an issue to plan a cast of a non-string type to a string for a concat operation, but since we didn't have the cast support, we'd be falling back to the row-by-row engine in most cases). Release note: None --- pkg/sql/colexec/colexecbase/cast.eg.go | 5951 +++++++++++++---- pkg/sql/colexec/colexecbase/cast_test.go | 2 +- .../execgen/cmd/execgen/avg_agg_gen.go | 2 +- .../execgen/cmd/execgen/cast_gen_util.go | 174 +- .../execgen/cmd/execgen/overloads_base.go | 4 +- .../execgen/cmd/execgen/overloads_gen_util.go | 4 +- .../cmd/execgen/range_offset_handler_gen.go | 2 +- .../execgen/cmd/execgen/span_encoder_gen.go | 2 +- .../execgen/cmd/execgen/sum_agg_gen.go | 2 +- pkg/sql/sem/eval/cast.go | 2 +- pkg/sql/sem/tree/datum.go | 58 +- 11 files changed, 4710 insertions(+), 1493 deletions(-) diff --git a/pkg/sql/colexec/colexecbase/cast.eg.go b/pkg/sql/colexec/colexecbase/cast.eg.go index 25073f820b44..9d41c398fb09 100644 --- a/pkg/sql/colexec/colexecbase/cast.eg.go +++ b/pkg/sql/colexec/colexecbase/cast.eg.go @@ -17,6 +17,7 @@ import ( "strconv" "strings" "time" + "unicode/utf8" "github.com/cockroachdb/apd/v3" "github.com/cockroachdb/cockroach/pkg/col/coldata" @@ -205,6 +206,12 @@ func GetCastOperator( default: return &castBoolIntOp{castOpBase: base}, nil } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return &castBoolStringOp{castOpBase: base}, nil + } } } case types.BytesFamily: @@ -212,6 +219,12 @@ func GetCastOperator( case -1: default: switch toType.Family() { + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return &castBytesStringOp{castOpBase: base}, nil + } case types.UuidFamily: switch toType.Width() { case -1: @@ -247,6 +260,12 @@ func GetCastOperator( default: return &castDateIntOp{castOpBase: base}, nil } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return &castDateStringOp{castOpBase: base}, nil + } } } case types.DecimalFamily: @@ -282,6 +301,12 @@ func GetCastOperator( default: return &castDecimalIntOp{castOpBase: base}, nil } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return &castDecimalStringOp{castOpBase: base}, nil + } } } case types.FloatFamily: @@ -311,6 +336,12 @@ func GetCastOperator( default: return &castFloatIntOp{castOpBase: base}, nil } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return &castFloatStringOp{castOpBase: base}, nil + } } } case types.IntFamily: @@ -343,6 +374,12 @@ func GetCastOperator( default: return &castInt2IntOp{castOpBase: base}, nil } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return &castInt2StringOp{castOpBase: base}, nil + } } case 32: switch toType.Family() { @@ -372,6 +409,12 @@ func GetCastOperator( default: return &castInt4IntOp{castOpBase: base}, nil } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return &castInt4StringOp{castOpBase: base}, nil + } } case -1: default: @@ -401,6 +444,25 @@ func GetCastOperator( case 32: return &castIntInt4Op{castOpBase: base}, nil } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return &castIntStringOp{castOpBase: base}, nil + } + } + } + case types.IntervalFamily: + switch fromType.Width() { + case -1: + default: + switch toType.Family() { + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return &castIntervalStringOp{castOpBase: base}, nil + } } } case types.JsonFamily: @@ -499,6 +561,45 @@ func GetCastOperator( } } } + case types.TimestampFamily: + switch fromType.Width() { + case -1: + default: + switch toType.Family() { + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return &castTimestampStringOp{castOpBase: base}, nil + } + } + } + case types.TimestampTZFamily: + switch fromType.Width() { + case -1: + default: + switch toType.Family() { + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return &castTimestamptzStringOp{castOpBase: base}, nil + } + } + } + case types.UuidFamily: + switch fromType.Width() { + case -1: + default: + switch toType.Family() { + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return &castUuidStringOp{castOpBase: base}, nil + } + } + } } } return nil, errors.Errorf("unhandled cast %s -> %s", fromType.SQLString(), toType.SQLString()) @@ -621,6 +722,12 @@ func IsCastSupported(fromType, toType *types.T) bool { default: return true } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return true + } } } case types.BytesFamily: @@ -628,6 +735,12 @@ func IsCastSupported(fromType, toType *types.T) bool { case -1: default: switch toType.Family() { + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return true + } case types.UuidFamily: switch toType.Width() { case -1: @@ -663,6 +776,12 @@ func IsCastSupported(fromType, toType *types.T) bool { default: return true } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return true + } } } case types.DecimalFamily: @@ -698,6 +817,12 @@ func IsCastSupported(fromType, toType *types.T) bool { default: return true } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return true + } } } case types.FloatFamily: @@ -727,6 +852,12 @@ func IsCastSupported(fromType, toType *types.T) bool { default: return true } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return true + } } } case types.IntFamily: @@ -759,6 +890,12 @@ func IsCastSupported(fromType, toType *types.T) bool { default: return true } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return true + } } case 32: switch toType.Family() { @@ -788,6 +925,12 @@ func IsCastSupported(fromType, toType *types.T) bool { default: return true } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return true + } } case -1: default: @@ -817,6 +960,25 @@ func IsCastSupported(fromType, toType *types.T) bool { case 32: return true } + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return true + } + } + } + case types.IntervalFamily: + switch fromType.Width() { + case -1: + default: + switch toType.Family() { + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return true + } } } case types.JsonFamily: @@ -915,6 +1077,45 @@ func IsCastSupported(fromType, toType *types.T) bool { } } } + case types.TimestampFamily: + switch fromType.Width() { + case -1: + default: + switch toType.Family() { + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return true + } + } + } + case types.TimestampTZFamily: + switch fromType.Width() { + case -1: + default: + switch toType.Family() { + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return true + } + } + } + case types.UuidFamily: + switch fromType.Width() { + case -1: + default: + switch toType.Family() { + case types.StringFamily: + switch toType.Width() { + case -1: + default: + return true + } + } + } } } return false @@ -1728,14 +1929,14 @@ func (c *castBoolIntOp) Next() coldata.Batch { return batch } -type castBytesUuidOp struct { +type castBoolStringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castBytesUuidOp{} -var _ colexecop.ClosableOperator = &castBytesUuidOp{} +var _ colexecop.ResettableOperator = &castBoolStringOp{} +var _ colexecop.ClosableOperator = &castBoolStringOp{} -func (c *castBytesUuidOp) Next() coldata.Batch { +func (c *castBoolStringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -1749,7 +1950,7 @@ func (c *castBytesUuidOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Bytes() + inputCol := inputVec.Bool() inputNulls := inputVec.Nulls() outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() @@ -1773,11 +1974,28 @@ func (c *castBytesUuidOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r []byte - _uuid, err := uuid.FromBytes(v) - if err != nil { - colexecerror.ExpectedError(err) + r = []byte(strconv.FormatBool(v)) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - r = _uuid.GetBytes() outputCol.Set(tupleIdx, r) } @@ -1791,20 +2009,39 @@ func (c *castBytesUuidOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if true && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) var r []byte - _uuid, err := uuid.FromBytes(v) - if err != nil { - colexecerror.ExpectedError(err) + r = []byte(strconv.FormatBool(v)) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - r = _uuid.GetBytes() outputCol.Set(tupleIdx, r) } @@ -1829,11 +2066,28 @@ func (c *castBytesUuidOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r []byte - _uuid, err := uuid.FromBytes(v) - if err != nil { - colexecerror.ExpectedError(err) + r = []byte(strconv.FormatBool(v)) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - r = _uuid.GetBytes() outputCol.Set(tupleIdx, r) } @@ -1847,39 +2101,58 @@ func (c *castBytesUuidOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if false && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) var r []byte - _uuid, err := uuid.FromBytes(v) - if err != nil { - colexecerror.ExpectedError(err) - } - r = _uuid.GetBytes() - - outputCol.Set(tupleIdx, r) - } - } - } + r = []byte(strconv.FormatBool(v)) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + + outputCol.Set(tupleIdx, r) + } + } + } } }, ) return batch } -type castDateDecimalOp struct { +type castBytesStringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castDateDecimalOp{} -var _ colexecop.ClosableOperator = &castDateDecimalOp{} +var _ colexecop.ResettableOperator = &castBytesStringOp{} +var _ colexecop.ClosableOperator = &castBytesStringOp{} -func (c *castDateDecimalOp) Next() coldata.Batch { +func (c *castBytesStringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -1893,9 +2166,9 @@ func (c *castDateDecimalOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int64() + inputCol := inputVec.Bytes() inputNulls := inputVec.Nulls() - outputCol := outputVec.Decimal() + outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -1915,12 +2188,31 @@ func (c *castDateDecimalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r apd.Decimal + var r []byte - r.SetInt64(int64(v)) + _format := evalCtx.SessionData().DataConversionConfig.BytesEncodeFormat + r = []byte(lex.EncodeByteArrayToRawBytes(string(v), _format, false /* skipHexPrefix */)) - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -1935,25 +2227,40 @@ func (c *castDateDecimalOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = inputCol.Get(n - 1) - _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if true && inputNulls.NullAt(tupleIdx) { continue } - //gcassert:bce v := inputCol.Get(tupleIdx) - var r apd.Decimal + var r []byte - r.SetInt64(int64(v)) + _format := evalCtx.SessionData().DataConversionConfig.BytesEncodeFormat + r = []byte(lex.EncodeByteArrayToRawBytes(string(v), _format, false /* skipHexPrefix */)) - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -1975,12 +2282,31 @@ func (c *castDateDecimalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r apd.Decimal + var r []byte - r.SetInt64(int64(v)) + _format := evalCtx.SessionData().DataConversionConfig.BytesEncodeFormat + r = []byte(lex.EncodeByteArrayToRawBytes(string(v), _format, false /* skipHexPrefix */)) - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -1995,25 +2321,40 @@ func (c *castDateDecimalOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = inputCol.Get(n - 1) - _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if false && inputNulls.NullAt(tupleIdx) { continue } - //gcassert:bce v := inputCol.Get(tupleIdx) - var r apd.Decimal + var r []byte - r.SetInt64(int64(v)) + _format := evalCtx.SessionData().DataConversionConfig.BytesEncodeFormat + r = []byte(lex.EncodeByteArrayToRawBytes(string(v), _format, false /* skipHexPrefix */)) - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -2024,14 +2365,14 @@ func (c *castDateDecimalOp) Next() coldata.Batch { return batch } -type castDateFloatOp struct { +type castBytesUuidOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castDateFloatOp{} -var _ colexecop.ClosableOperator = &castDateFloatOp{} +var _ colexecop.ResettableOperator = &castBytesUuidOp{} +var _ colexecop.ClosableOperator = &castBytesUuidOp{} -func (c *castDateFloatOp) Next() coldata.Batch { +func (c *castBytesUuidOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -2045,9 +2386,9 @@ func (c *castDateFloatOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int64() + inputCol := inputVec.Bytes() inputNulls := inputVec.Nulls() - outputCol := outputVec.Float64() + outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -2067,9 +2408,13 @@ func (c *castDateFloatOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r float64 + var r []byte - r = float64(v) + _uuid, err := uuid.FromBytes(v) + if err != nil { + colexecerror.ExpectedError(err) + } + r = _uuid.GetBytes() outputCol.Set(tupleIdx, r) } @@ -2083,21 +2428,21 @@ func (c *castDateFloatOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = inputCol.Get(n - 1) - _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if true && inputNulls.NullAt(tupleIdx) { continue } - //gcassert:bce v := inputCol.Get(tupleIdx) - var r float64 + var r []byte - r = float64(v) + _uuid, err := uuid.FromBytes(v) + if err != nil { + colexecerror.ExpectedError(err) + } + r = _uuid.GetBytes() - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -2119,9 +2464,13 @@ func (c *castDateFloatOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r float64 + var r []byte - r = float64(v) + _uuid, err := uuid.FromBytes(v) + if err != nil { + colexecerror.ExpectedError(err) + } + r = _uuid.GetBytes() outputCol.Set(tupleIdx, r) } @@ -2135,21 +2484,21 @@ func (c *castDateFloatOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = inputCol.Get(n - 1) - _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if false && inputNulls.NullAt(tupleIdx) { continue } - //gcassert:bce v := inputCol.Get(tupleIdx) - var r float64 + var r []byte - r = float64(v) + _uuid, err := uuid.FromBytes(v) + if err != nil { + colexecerror.ExpectedError(err) + } + r = _uuid.GetBytes() - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -2160,14 +2509,14 @@ func (c *castDateFloatOp) Next() coldata.Batch { return batch } -type castDateInt2Op struct { +type castDateDecimalOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castDateInt2Op{} -var _ colexecop.ClosableOperator = &castDateInt2Op{} +var _ colexecop.ResettableOperator = &castDateDecimalOp{} +var _ colexecop.ClosableOperator = &castDateDecimalOp{} -func (c *castDateInt2Op) Next() coldata.Batch { +func (c *castDateDecimalOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -2183,7 +2532,7 @@ func (c *castDateInt2Op) Next() coldata.Batch { []coldata.Vec{outputVec}, func() { inputCol := inputVec.Int64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int16() + outputCol := outputVec.Decimal() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -2203,13 +2552,13 @@ func (c *castDateInt2Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int16 + var r apd.Decimal - shifted := v >> uint(15) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + r.SetInt64(int64(v)) + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) } - r = int16(v) outputCol.Set(tupleIdx, r) } @@ -2233,13 +2582,13 @@ func (c *castDateInt2Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int16 + var r apd.Decimal - shifted := v >> uint(15) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + r.SetInt64(int64(v)) + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) } - r = int16(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -2263,13 +2612,13 @@ func (c *castDateInt2Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int16 + var r apd.Decimal - shifted := v >> uint(15) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + r.SetInt64(int64(v)) + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) } - r = int16(v) outputCol.Set(tupleIdx, r) } @@ -2293,13 +2642,13 @@ func (c *castDateInt2Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int16 + var r apd.Decimal - shifted := v >> uint(15) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + r.SetInt64(int64(v)) + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) } - r = int16(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -2312,14 +2661,14 @@ func (c *castDateInt2Op) Next() coldata.Batch { return batch } -type castDateInt4Op struct { +type castDateFloatOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castDateInt4Op{} -var _ colexecop.ClosableOperator = &castDateInt4Op{} +var _ colexecop.ResettableOperator = &castDateFloatOp{} +var _ colexecop.ClosableOperator = &castDateFloatOp{} -func (c *castDateInt4Op) Next() coldata.Batch { +func (c *castDateFloatOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -2335,7 +2684,7 @@ func (c *castDateInt4Op) Next() coldata.Batch { []coldata.Vec{outputVec}, func() { inputCol := inputVec.Int64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int32() + outputCol := outputVec.Float64() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -2355,13 +2704,9 @@ func (c *castDateInt4Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int32 + var r float64 - shifted := v >> uint(31) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - r = int32(v) + r = float64(v) outputCol.Set(tupleIdx, r) } @@ -2385,13 +2730,9 @@ func (c *castDateInt4Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int32 + var r float64 - shifted := v >> uint(31) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - r = int32(v) + r = float64(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -2415,13 +2756,9 @@ func (c *castDateInt4Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int32 + var r float64 - shifted := v >> uint(31) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - r = int32(v) + r = float64(v) outputCol.Set(tupleIdx, r) } @@ -2445,13 +2782,9 @@ func (c *castDateInt4Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int32 + var r float64 - shifted := v >> uint(31) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - r = int32(v) + r = float64(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -2464,14 +2797,14 @@ func (c *castDateInt4Op) Next() coldata.Batch { return batch } -type castDateIntOp struct { +type castDateInt2Op struct { castOpBase } -var _ colexecop.ResettableOperator = &castDateIntOp{} -var _ colexecop.ClosableOperator = &castDateIntOp{} +var _ colexecop.ResettableOperator = &castDateInt2Op{} +var _ colexecop.ClosableOperator = &castDateInt2Op{} -func (c *castDateIntOp) Next() coldata.Batch { +func (c *castDateInt2Op) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -2487,7 +2820,7 @@ func (c *castDateIntOp) Next() coldata.Batch { []coldata.Vec{outputVec}, func() { inputCol := inputVec.Int64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int64() + outputCol := outputVec.Int16() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -2507,8 +2840,14 @@ func (c *castDateIntOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 - r = int64(v) + var r int16 + + shifted := v >> uint(15) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + r = int16(v) + outputCol.Set(tupleIdx, r) } } @@ -2531,8 +2870,14 @@ func (c *castDateIntOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int64 - r = int64(v) + var r int16 + + shifted := v >> uint(15) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + r = int16(v) + //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -2555,8 +2900,14 @@ func (c *castDateIntOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 - r = int64(v) + var r int16 + + shifted := v >> uint(15) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + r = int16(v) + outputCol.Set(tupleIdx, r) } } @@ -2579,8 +2930,14 @@ func (c *castDateIntOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int64 - r = int64(v) + var r int16 + + shifted := v >> uint(15) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + r = int16(v) + //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -2592,14 +2949,14 @@ func (c *castDateIntOp) Next() coldata.Batch { return batch } -type castDecimalBoolOp struct { +type castDateInt4Op struct { castOpBase } -var _ colexecop.ResettableOperator = &castDecimalBoolOp{} -var _ colexecop.ClosableOperator = &castDecimalBoolOp{} +var _ colexecop.ResettableOperator = &castDateInt4Op{} +var _ colexecop.ClosableOperator = &castDateInt4Op{} -func (c *castDecimalBoolOp) Next() coldata.Batch { +func (c *castDateInt4Op) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -2613,9 +2970,9 @@ func (c *castDecimalBoolOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Decimal() + inputCol := inputVec.Int64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Bool() + outputCol := outputVec.Int32() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -2635,8 +2992,14 @@ func (c *castDecimalBoolOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r bool - r = v.Sign() != 0 + var r int32 + + shifted := v >> uint(31) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + r = int32(v) + outputCol.Set(tupleIdx, r) } } @@ -2659,8 +3022,14 @@ func (c *castDecimalBoolOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r bool - r = v.Sign() != 0 + var r int32 + + shifted := v >> uint(31) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + r = int32(v) + //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -2683,8 +3052,14 @@ func (c *castDecimalBoolOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r bool - r = v.Sign() != 0 + var r int32 + + shifted := v >> uint(31) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + r = int32(v) + outputCol.Set(tupleIdx, r) } } @@ -2707,8 +3082,14 @@ func (c *castDecimalBoolOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r bool - r = v.Sign() != 0 + var r int32 + + shifted := v >> uint(31) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + r = int32(v) + //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -2720,14 +3101,14 @@ func (c *castDecimalBoolOp) Next() coldata.Batch { return batch } -type castDecimalDecimalOp struct { +type castDateIntOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castDecimalDecimalOp{} -var _ colexecop.ClosableOperator = &castDecimalDecimalOp{} +var _ colexecop.ResettableOperator = &castDateIntOp{} +var _ colexecop.ClosableOperator = &castDateIntOp{} -func (c *castDecimalDecimalOp) Next() coldata.Batch { +func (c *castDateIntOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -2741,9 +3122,9 @@ func (c *castDecimalDecimalOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Decimal() + inputCol := inputVec.Int64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Decimal() + outputCol := outputVec.Int64() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -2763,13 +3144,8 @@ func (c *castDecimalDecimalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r apd.Decimal - - r.Set(&v) - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) - } - + var r int64 + r = int64(v) outputCol.Set(tupleIdx, r) } } @@ -2792,13 +3168,8 @@ func (c *castDecimalDecimalOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r apd.Decimal - - r.Set(&v) - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) - } - + var r int64 + r = int64(v) //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -2821,13 +3192,8 @@ func (c *castDecimalDecimalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r apd.Decimal - - r.Set(&v) - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) - } - + var r int64 + r = int64(v) outputCol.Set(tupleIdx, r) } } @@ -2850,13 +3216,8 @@ func (c *castDecimalDecimalOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r apd.Decimal - - r.Set(&v) - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) - } - + var r int64 + r = int64(v) //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -2868,14 +3229,14 @@ func (c *castDecimalDecimalOp) Next() coldata.Batch { return batch } -type castDecimalFloatOp struct { +type castDateStringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castDecimalFloatOp{} -var _ colexecop.ClosableOperator = &castDecimalFloatOp{} +var _ colexecop.ResettableOperator = &castDateStringOp{} +var _ colexecop.ClosableOperator = &castDateStringOp{} -func (c *castDecimalFloatOp) Next() coldata.Batch { +func (c *castDateStringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -2889,9 +3250,9 @@ func (c *castDecimalFloatOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Decimal() + inputCol := inputVec.Int64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Float64() + outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -2911,14 +3272,33 @@ func (c *castDecimalFloatOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r float64 + var r []byte - { - f, err := v.Float64() - if err != nil { - colexecerror.ExpectedError(tree.ErrFloatOutOfRange) + _date := pgdate.MakeCompatibleDateFromDisk(v) + buf.Reset() + _date.Format(buf) + r = []byte(buf.String()) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) } - r = f + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -2934,7 +3314,6 @@ func (c *castDecimalFloatOp) Next() coldata.Batch { _ = evalCtx _ = buf _ = inputCol.Get(n - 1) - _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -2943,17 +3322,35 @@ func (c *castDecimalFloatOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r float64 + var r []byte - { - f, err := v.Float64() - if err != nil { - colexecerror.ExpectedError(tree.ErrFloatOutOfRange) + _date := pgdate.MakeCompatibleDateFromDisk(v) + buf.Reset() + _date.Format(buf) + r = []byte(buf.String()) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) } - r = f + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -2975,14 +3372,33 @@ func (c *castDecimalFloatOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r float64 + var r []byte - { - f, err := v.Float64() - if err != nil { - colexecerror.ExpectedError(tree.ErrFloatOutOfRange) + _date := pgdate.MakeCompatibleDateFromDisk(v) + buf.Reset() + _date.Format(buf) + r = []byte(buf.String()) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) } - r = f + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -2998,7 +3414,6 @@ func (c *castDecimalFloatOp) Next() coldata.Batch { _ = evalCtx _ = buf _ = inputCol.Get(n - 1) - _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -3007,17 +3422,35 @@ func (c *castDecimalFloatOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r float64 + var r []byte - { - f, err := v.Float64() - if err != nil { - colexecerror.ExpectedError(tree.ErrFloatOutOfRange) + _date := pgdate.MakeCompatibleDateFromDisk(v) + buf.Reset() + _date.Format(buf) + r = []byte(buf.String()) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) } - r = f + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -3028,14 +3461,14 @@ func (c *castDecimalFloatOp) Next() coldata.Batch { return batch } -type castDecimalInt2Op struct { +type castDecimalBoolOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castDecimalInt2Op{} -var _ colexecop.ClosableOperator = &castDecimalInt2Op{} +var _ colexecop.ResettableOperator = &castDecimalBoolOp{} +var _ colexecop.ClosableOperator = &castDecimalBoolOp{} -func (c *castDecimalInt2Op) Next() coldata.Batch { +func (c *castDecimalBoolOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -3051,7 +3484,7 @@ func (c *castDecimalInt2Op) Next() coldata.Batch { []coldata.Vec{outputVec}, func() { inputCol := inputVec.Decimal() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int16() + outputCol := outputVec.Bool() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -3071,27 +3504,8 @@ func (c *castDecimalInt2Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int16 - - { - var tmpDec apd.Decimal //gcassert:noescape - _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) - if err != nil { - colexecerror.ExpectedError(err) - } - _i, err := tmpDec.Int64() - if err != nil { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) - } - - shifted := _i >> uint(15) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) - } - r = int16(_i) - - } - + var r bool + r = v.Sign() != 0 outputCol.Set(tupleIdx, r) } } @@ -3114,27 +3528,8 @@ func (c *castDecimalInt2Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int16 - - { - var tmpDec apd.Decimal //gcassert:noescape - _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) - if err != nil { - colexecerror.ExpectedError(err) - } - _i, err := tmpDec.Int64() - if err != nil { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) - } - - shifted := _i >> uint(15) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) - } - r = int16(_i) - - } - + var r bool + r = v.Sign() != 0 //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -3157,27 +3552,8 @@ func (c *castDecimalInt2Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int16 - - { - var tmpDec apd.Decimal //gcassert:noescape - _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) - if err != nil { - colexecerror.ExpectedError(err) - } - _i, err := tmpDec.Int64() - if err != nil { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) - } - - shifted := _i >> uint(15) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) - } - r = int16(_i) - - } - + var r bool + r = v.Sign() != 0 outputCol.Set(tupleIdx, r) } } @@ -3200,27 +3576,8 @@ func (c *castDecimalInt2Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int16 - - { - var tmpDec apd.Decimal //gcassert:noescape - _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) - if err != nil { - colexecerror.ExpectedError(err) - } - _i, err := tmpDec.Int64() - if err != nil { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) - } - - shifted := _i >> uint(15) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) - } - r = int16(_i) - - } - + var r bool + r = v.Sign() != 0 //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -3232,14 +3589,14 @@ func (c *castDecimalInt2Op) Next() coldata.Batch { return batch } -type castDecimalInt4Op struct { +type castDecimalDecimalOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castDecimalInt4Op{} -var _ colexecop.ClosableOperator = &castDecimalInt4Op{} +var _ colexecop.ResettableOperator = &castDecimalDecimalOp{} +var _ colexecop.ClosableOperator = &castDecimalDecimalOp{} -func (c *castDecimalInt4Op) Next() coldata.Batch { +func (c *castDecimalDecimalOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -3255,7 +3612,7 @@ func (c *castDecimalInt4Op) Next() coldata.Batch { []coldata.Vec{outputVec}, func() { inputCol := inputVec.Decimal() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int32() + outputCol := outputVec.Decimal() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -3275,25 +3632,11 @@ func (c *castDecimalInt4Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int32 - - { - var tmpDec apd.Decimal //gcassert:noescape - _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) - if err != nil { - colexecerror.ExpectedError(err) - } - _i, err := tmpDec.Int64() - if err != nil { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - - shifted := _i >> uint(31) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - r = int32(_i) + var r apd.Decimal + r.Set(&v) + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) } outputCol.Set(tupleIdx, r) @@ -3318,25 +3661,11 @@ func (c *castDecimalInt4Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int32 - - { - var tmpDec apd.Decimal //gcassert:noescape - _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) - if err != nil { - colexecerror.ExpectedError(err) - } - _i, err := tmpDec.Int64() - if err != nil { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - - shifted := _i >> uint(31) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - r = int32(_i) + var r apd.Decimal + r.Set(&v) + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) } //gcassert:bce @@ -3361,25 +3690,11 @@ func (c *castDecimalInt4Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int32 - - { - var tmpDec apd.Decimal //gcassert:noescape - _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) - if err != nil { - colexecerror.ExpectedError(err) - } - _i, err := tmpDec.Int64() - if err != nil { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - - shifted := _i >> uint(31) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - r = int32(_i) + var r apd.Decimal + r.Set(&v) + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) } outputCol.Set(tupleIdx, r) @@ -3404,25 +3719,11 @@ func (c *castDecimalInt4Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int32 - - { - var tmpDec apd.Decimal //gcassert:noescape - _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) - if err != nil { - colexecerror.ExpectedError(err) - } - _i, err := tmpDec.Int64() - if err != nil { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - - shifted := _i >> uint(31) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - r = int32(_i) + var r apd.Decimal + r.Set(&v) + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) } //gcassert:bce @@ -3436,14 +3737,14 @@ func (c *castDecimalInt4Op) Next() coldata.Batch { return batch } -type castDecimalIntOp struct { +type castDecimalFloatOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castDecimalIntOp{} -var _ colexecop.ClosableOperator = &castDecimalIntOp{} +var _ colexecop.ResettableOperator = &castDecimalFloatOp{} +var _ colexecop.ClosableOperator = &castDecimalFloatOp{} -func (c *castDecimalIntOp) Next() coldata.Batch { +func (c *castDecimalFloatOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -3459,7 +3760,7 @@ func (c *castDecimalIntOp) Next() coldata.Batch { []coldata.Vec{outputVec}, func() { inputCol := inputVec.Decimal() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int64() + outputCol := outputVec.Float64() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -3479,19 +3780,14 @@ func (c *castDecimalIntOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 + var r float64 { - var tmpDec apd.Decimal //gcassert:noescape - _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) - if err != nil { - colexecerror.ExpectedError(err) - } - _i, err := tmpDec.Int64() + f, err := v.Float64() if err != nil { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) + colexecerror.ExpectedError(tree.ErrFloatOutOfRange) } - r = int64(_i) + r = f } outputCol.Set(tupleIdx, r) @@ -3516,19 +3812,14 @@ func (c *castDecimalIntOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int64 + var r float64 { - var tmpDec apd.Decimal //gcassert:noescape - _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) - if err != nil { - colexecerror.ExpectedError(err) - } - _i, err := tmpDec.Int64() + f, err := v.Float64() if err != nil { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) + colexecerror.ExpectedError(tree.ErrFloatOutOfRange) } - r = int64(_i) + r = f } //gcassert:bce @@ -3553,19 +3844,14 @@ func (c *castDecimalIntOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 + var r float64 { - var tmpDec apd.Decimal //gcassert:noescape - _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) - if err != nil { - colexecerror.ExpectedError(err) - } - _i, err := tmpDec.Int64() + f, err := v.Float64() if err != nil { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) + colexecerror.ExpectedError(tree.ErrFloatOutOfRange) } - r = int64(_i) + r = f } outputCol.Set(tupleIdx, r) @@ -3590,19 +3876,14 @@ func (c *castDecimalIntOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int64 + var r float64 { - var tmpDec apd.Decimal //gcassert:noescape - _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) - if err != nil { - colexecerror.ExpectedError(err) - } - _i, err := tmpDec.Int64() + f, err := v.Float64() if err != nil { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) + colexecerror.ExpectedError(tree.ErrFloatOutOfRange) } - r = int64(_i) + r = f } //gcassert:bce @@ -3616,14 +3897,14 @@ func (c *castDecimalIntOp) Next() coldata.Batch { return batch } -type castFloatBoolOp struct { +type castDecimalInt2Op struct { castOpBase } -var _ colexecop.ResettableOperator = &castFloatBoolOp{} -var _ colexecop.ClosableOperator = &castFloatBoolOp{} +var _ colexecop.ResettableOperator = &castDecimalInt2Op{} +var _ colexecop.ClosableOperator = &castDecimalInt2Op{} -func (c *castFloatBoolOp) Next() coldata.Batch { +func (c *castDecimalInt2Op) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -3637,9 +3918,9 @@ func (c *castFloatBoolOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Float64() + inputCol := inputVec.Decimal() inputNulls := inputVec.Nulls() - outputCol := outputVec.Bool() + outputCol := outputVec.Int16() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -3659,16 +3940,33 @@ func (c *castFloatBoolOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r bool - - r = v != 0 + var r int16 - outputCol.Set(tupleIdx, r) - } - } - } else { - { - var ( + { + var tmpDec apd.Decimal //gcassert:noescape + _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) + if err != nil { + colexecerror.ExpectedError(err) + } + _i, err := tmpDec.Int64() + if err != nil { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + + shifted := _i >> uint(15) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + r = int16(_i) + + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( evalCtx *eval.Context = c.evalCtx buf *bytes.Buffer = &c.buf ) @@ -3685,9 +3983,26 @@ func (c *castFloatBoolOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r bool + var r int16 - r = v != 0 + { + var tmpDec apd.Decimal //gcassert:noescape + _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) + if err != nil { + colexecerror.ExpectedError(err) + } + _i, err := tmpDec.Int64() + if err != nil { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + + shifted := _i >> uint(15) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + r = int16(_i) + + } //gcassert:bce outputCol.Set(tupleIdx, r) @@ -3711,9 +4026,26 @@ func (c *castFloatBoolOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r bool + var r int16 - r = v != 0 + { + var tmpDec apd.Decimal //gcassert:noescape + _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) + if err != nil { + colexecerror.ExpectedError(err) + } + _i, err := tmpDec.Int64() + if err != nil { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + + shifted := _i >> uint(15) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + r = int16(_i) + + } outputCol.Set(tupleIdx, r) } @@ -3737,9 +4069,26 @@ func (c *castFloatBoolOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r bool + var r int16 - r = v != 0 + { + var tmpDec apd.Decimal //gcassert:noescape + _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) + if err != nil { + colexecerror.ExpectedError(err) + } + _i, err := tmpDec.Int64() + if err != nil { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + + shifted := _i >> uint(15) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + r = int16(_i) + + } //gcassert:bce outputCol.Set(tupleIdx, r) @@ -3752,14 +4101,14 @@ func (c *castFloatBoolOp) Next() coldata.Batch { return batch } -type castFloatDecimalOp struct { +type castDecimalInt4Op struct { castOpBase } -var _ colexecop.ResettableOperator = &castFloatDecimalOp{} -var _ colexecop.ClosableOperator = &castFloatDecimalOp{} +var _ colexecop.ResettableOperator = &castDecimalInt4Op{} +var _ colexecop.ClosableOperator = &castDecimalInt4Op{} -func (c *castFloatDecimalOp) Next() coldata.Batch { +func (c *castDecimalInt4Op) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -3773,9 +4122,9 @@ func (c *castFloatDecimalOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Float64() + inputCol := inputVec.Decimal() inputNulls := inputVec.Nulls() - outputCol := outputVec.Decimal() + outputCol := outputVec.Int32() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -3795,14 +4144,25 @@ func (c *castFloatDecimalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r apd.Decimal + var r int32 - if _, err := r.SetFloat64(float64(v)); err != nil { - colexecerror.ExpectedError(err) - } + { + var tmpDec apd.Decimal //gcassert:noescape + _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) + if err != nil { + colexecerror.ExpectedError(err) + } + _i, err := tmpDec.Int64() + if err != nil { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + + shifted := _i >> uint(31) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + r = int32(_i) - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) } outputCol.Set(tupleIdx, r) @@ -3827,14 +4187,25 @@ func (c *castFloatDecimalOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r apd.Decimal + var r int32 - if _, err := r.SetFloat64(float64(v)); err != nil { - colexecerror.ExpectedError(err) - } + { + var tmpDec apd.Decimal //gcassert:noescape + _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) + if err != nil { + colexecerror.ExpectedError(err) + } + _i, err := tmpDec.Int64() + if err != nil { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + + shifted := _i >> uint(31) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + r = int32(_i) - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) } //gcassert:bce @@ -3859,14 +4230,25 @@ func (c *castFloatDecimalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r apd.Decimal + var r int32 - if _, err := r.SetFloat64(float64(v)); err != nil { - colexecerror.ExpectedError(err) - } + { + var tmpDec apd.Decimal //gcassert:noescape + _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) + if err != nil { + colexecerror.ExpectedError(err) + } + _i, err := tmpDec.Int64() + if err != nil { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + + shifted := _i >> uint(31) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + r = int32(_i) - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) } outputCol.Set(tupleIdx, r) @@ -3891,14 +4273,25 @@ func (c *castFloatDecimalOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r apd.Decimal + var r int32 - if _, err := r.SetFloat64(float64(v)); err != nil { - colexecerror.ExpectedError(err) - } + { + var tmpDec apd.Decimal //gcassert:noescape + _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) + if err != nil { + colexecerror.ExpectedError(err) + } + _i, err := tmpDec.Int64() + if err != nil { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + + shifted := _i >> uint(31) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + r = int32(_i) - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) } //gcassert:bce @@ -3912,14 +4305,14 @@ func (c *castFloatDecimalOp) Next() coldata.Batch { return batch } -type castFloatInt2Op struct { +type castDecimalIntOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castFloatInt2Op{} -var _ colexecop.ClosableOperator = &castFloatInt2Op{} +var _ colexecop.ResettableOperator = &castDecimalIntOp{} +var _ colexecop.ClosableOperator = &castDecimalIntOp{} -func (c *castFloatInt2Op) Next() coldata.Batch { +func (c *castDecimalIntOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -3933,9 +4326,9 @@ func (c *castFloatInt2Op) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Float64() + inputCol := inputVec.Decimal() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int16() + outputCol := outputVec.Int64() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -3955,12 +4348,20 @@ func (c *castFloatInt2Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int16 + var r int64 - if math.IsNaN(float64(v)) || v <= float64(math.MinInt16) || v >= float64(math.MaxInt16) { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) + { + var tmpDec apd.Decimal //gcassert:noescape + _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) + if err != nil { + colexecerror.ExpectedError(err) + } + _i, err := tmpDec.Int64() + if err != nil { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) + } + r = int64(_i) } - r = int16(v) outputCol.Set(tupleIdx, r) } @@ -3984,12 +4385,20 @@ func (c *castFloatInt2Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int16 + var r int64 - if math.IsNaN(float64(v)) || v <= float64(math.MinInt16) || v >= float64(math.MaxInt16) { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) + { + var tmpDec apd.Decimal //gcassert:noescape + _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) + if err != nil { + colexecerror.ExpectedError(err) + } + _i, err := tmpDec.Int64() + if err != nil { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) + } + r = int64(_i) } - r = int16(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -4013,12 +4422,20 @@ func (c *castFloatInt2Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int16 + var r int64 - if math.IsNaN(float64(v)) || v <= float64(math.MinInt16) || v >= float64(math.MaxInt16) { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) + { + var tmpDec apd.Decimal //gcassert:noescape + _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) + if err != nil { + colexecerror.ExpectedError(err) + } + _i, err := tmpDec.Int64() + if err != nil { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) + } + r = int64(_i) } - r = int16(v) outputCol.Set(tupleIdx, r) } @@ -4042,12 +4459,20 @@ func (c *castFloatInt2Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int16 + var r int64 - if math.IsNaN(float64(v)) || v <= float64(math.MinInt16) || v >= float64(math.MaxInt16) { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) + { + var tmpDec apd.Decimal //gcassert:noescape + _, err := tree.DecimalCtx.RoundToIntegralValue(&tmpDec, &v) + if err != nil { + colexecerror.ExpectedError(err) + } + _i, err := tmpDec.Int64() + if err != nil { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) + } + r = int64(_i) } - r = int16(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -4060,14 +4485,14 @@ func (c *castFloatInt2Op) Next() coldata.Batch { return batch } -type castFloatInt4Op struct { +type castDecimalStringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castFloatInt4Op{} -var _ colexecop.ClosableOperator = &castFloatInt4Op{} +var _ colexecop.ResettableOperator = &castDecimalStringOp{} +var _ colexecop.ClosableOperator = &castDecimalStringOp{} -func (c *castFloatInt4Op) Next() coldata.Batch { +func (c *castDecimalStringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -4081,9 +4506,9 @@ func (c *castFloatInt4Op) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Float64() + inputCol := inputVec.Decimal() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int32() + outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -4103,12 +4528,30 @@ func (c *castFloatInt4Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int32 + var r []byte - if math.IsNaN(float64(v)) || v <= float64(math.MinInt32) || v >= float64(math.MaxInt32) { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) + r = []byte(v.String()) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - r = int32(v) outputCol.Set(tupleIdx, r) } @@ -4123,7 +4566,6 @@ func (c *castFloatInt4Op) Next() coldata.Batch { _ = evalCtx _ = buf _ = inputCol.Get(n - 1) - _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -4132,14 +4574,31 @@ func (c *castFloatInt4Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int32 + var r []byte - if math.IsNaN(float64(v)) || v <= float64(math.MinInt32) || v >= float64(math.MaxInt32) { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) + r = []byte(v.String()) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - r = int32(v) - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -4161,12 +4620,30 @@ func (c *castFloatInt4Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int32 + var r []byte - if math.IsNaN(float64(v)) || v <= float64(math.MinInt32) || v >= float64(math.MaxInt32) { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) + r = []byte(v.String()) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - r = int32(v) outputCol.Set(tupleIdx, r) } @@ -4181,7 +4658,6 @@ func (c *castFloatInt4Op) Next() coldata.Batch { _ = evalCtx _ = buf _ = inputCol.Get(n - 1) - _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -4190,14 +4666,31 @@ func (c *castFloatInt4Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int32 + var r []byte - if math.IsNaN(float64(v)) || v <= float64(math.MinInt32) || v >= float64(math.MaxInt32) { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) + r = []byte(v.String()) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - r = int32(v) - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -4208,14 +4701,14 @@ func (c *castFloatInt4Op) Next() coldata.Batch { return batch } -type castFloatIntOp struct { +type castFloatBoolOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castFloatIntOp{} -var _ colexecop.ClosableOperator = &castFloatIntOp{} +var _ colexecop.ResettableOperator = &castFloatBoolOp{} +var _ colexecop.ClosableOperator = &castFloatBoolOp{} -func (c *castFloatIntOp) Next() coldata.Batch { +func (c *castFloatBoolOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -4231,7 +4724,7 @@ func (c *castFloatIntOp) Next() coldata.Batch { []coldata.Vec{outputVec}, func() { inputCol := inputVec.Float64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int64() + outputCol := outputVec.Bool() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -4251,12 +4744,9 @@ func (c *castFloatIntOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 + var r bool - if math.IsNaN(float64(v)) || v <= float64(math.MinInt64) || v >= float64(math.MaxInt64) { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) - } - r = int64(v) + r = v != 0 outputCol.Set(tupleIdx, r) } @@ -4280,12 +4770,9 @@ func (c *castFloatIntOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int64 + var r bool - if math.IsNaN(float64(v)) || v <= float64(math.MinInt64) || v >= float64(math.MaxInt64) { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) - } - r = int64(v) + r = v != 0 //gcassert:bce outputCol.Set(tupleIdx, r) @@ -4309,12 +4796,9 @@ func (c *castFloatIntOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 + var r bool - if math.IsNaN(float64(v)) || v <= float64(math.MinInt64) || v >= float64(math.MaxInt64) { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) - } - r = int64(v) + r = v != 0 outputCol.Set(tupleIdx, r) } @@ -4338,12 +4822,9 @@ func (c *castFloatIntOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int64 + var r bool - if math.IsNaN(float64(v)) || v <= float64(math.MinInt64) || v >= float64(math.MaxInt64) { - colexecerror.ExpectedError(tree.ErrIntOutOfRange) - } - r = int64(v) + r = v != 0 //gcassert:bce outputCol.Set(tupleIdx, r) @@ -4356,14 +4837,14 @@ func (c *castFloatIntOp) Next() coldata.Batch { return batch } -type castInt2BoolOp struct { +type castFloatDecimalOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castInt2BoolOp{} -var _ colexecop.ClosableOperator = &castInt2BoolOp{} +var _ colexecop.ResettableOperator = &castFloatDecimalOp{} +var _ colexecop.ClosableOperator = &castFloatDecimalOp{} -func (c *castInt2BoolOp) Next() coldata.Batch { +func (c *castFloatDecimalOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -4377,9 +4858,9 @@ func (c *castInt2BoolOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int16() + inputCol := inputVec.Float64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Bool() + outputCol := outputVec.Decimal() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -4399,9 +4880,15 @@ func (c *castInt2BoolOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r bool + var r apd.Decimal - r = v != 0 + if _, err := r.SetFloat64(float64(v)); err != nil { + colexecerror.ExpectedError(err) + } + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) + } outputCol.Set(tupleIdx, r) } @@ -4425,9 +4912,15 @@ func (c *castInt2BoolOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r bool + var r apd.Decimal - r = v != 0 + if _, err := r.SetFloat64(float64(v)); err != nil { + colexecerror.ExpectedError(err) + } + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) + } //gcassert:bce outputCol.Set(tupleIdx, r) @@ -4451,9 +4944,15 @@ func (c *castInt2BoolOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r bool + var r apd.Decimal - r = v != 0 + if _, err := r.SetFloat64(float64(v)); err != nil { + colexecerror.ExpectedError(err) + } + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) + } outputCol.Set(tupleIdx, r) } @@ -4477,9 +4976,15 @@ func (c *castInt2BoolOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r bool + var r apd.Decimal - r = v != 0 + if _, err := r.SetFloat64(float64(v)); err != nil { + colexecerror.ExpectedError(err) + } + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) + } //gcassert:bce outputCol.Set(tupleIdx, r) @@ -4492,14 +4997,14 @@ func (c *castInt2BoolOp) Next() coldata.Batch { return batch } -type castInt2DecimalOp struct { +type castFloatInt2Op struct { castOpBase } -var _ colexecop.ResettableOperator = &castInt2DecimalOp{} -var _ colexecop.ClosableOperator = &castInt2DecimalOp{} +var _ colexecop.ResettableOperator = &castFloatInt2Op{} +var _ colexecop.ClosableOperator = &castFloatInt2Op{} -func (c *castInt2DecimalOp) Next() coldata.Batch { +func (c *castFloatInt2Op) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -4513,9 +5018,9 @@ func (c *castInt2DecimalOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int16() + inputCol := inputVec.Float64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Decimal() + outputCol := outputVec.Int16() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -4535,13 +5040,12 @@ func (c *castInt2DecimalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r apd.Decimal - - r.SetInt64(int64(v)) + var r int16 - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) + if math.IsNaN(float64(v)) || v <= float64(math.MinInt16) || v >= float64(math.MaxInt16) { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) } + r = int16(v) outputCol.Set(tupleIdx, r) } @@ -4565,13 +5069,12 @@ func (c *castInt2DecimalOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r apd.Decimal - - r.SetInt64(int64(v)) + var r int16 - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) + if math.IsNaN(float64(v)) || v <= float64(math.MinInt16) || v >= float64(math.MaxInt16) { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) } + r = int16(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -4595,13 +5098,12 @@ func (c *castInt2DecimalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r apd.Decimal - - r.SetInt64(int64(v)) + var r int16 - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) + if math.IsNaN(float64(v)) || v <= float64(math.MinInt16) || v >= float64(math.MaxInt16) { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) } + r = int16(v) outputCol.Set(tupleIdx, r) } @@ -4625,13 +5127,12 @@ func (c *castInt2DecimalOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r apd.Decimal - - r.SetInt64(int64(v)) + var r int16 - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) + if math.IsNaN(float64(v)) || v <= float64(math.MinInt16) || v >= float64(math.MaxInt16) { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) } + r = int16(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -4644,14 +5145,14 @@ func (c *castInt2DecimalOp) Next() coldata.Batch { return batch } -type castInt2FloatOp struct { +type castFloatInt4Op struct { castOpBase } -var _ colexecop.ResettableOperator = &castInt2FloatOp{} -var _ colexecop.ClosableOperator = &castInt2FloatOp{} +var _ colexecop.ResettableOperator = &castFloatInt4Op{} +var _ colexecop.ClosableOperator = &castFloatInt4Op{} -func (c *castInt2FloatOp) Next() coldata.Batch { +func (c *castFloatInt4Op) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -4665,9 +5166,9 @@ func (c *castInt2FloatOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int16() + inputCol := inputVec.Float64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Float64() + outputCol := outputVec.Int32() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -4687,9 +5188,12 @@ func (c *castInt2FloatOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r float64 + var r int32 - r = float64(v) + if math.IsNaN(float64(v)) || v <= float64(math.MinInt32) || v >= float64(math.MaxInt32) { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) + } + r = int32(v) outputCol.Set(tupleIdx, r) } @@ -4713,9 +5217,12 @@ func (c *castInt2FloatOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r float64 + var r int32 - r = float64(v) + if math.IsNaN(float64(v)) || v <= float64(math.MinInt32) || v >= float64(math.MaxInt32) { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) + } + r = int32(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -4739,9 +5246,12 @@ func (c *castInt2FloatOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r float64 + var r int32 - r = float64(v) + if math.IsNaN(float64(v)) || v <= float64(math.MinInt32) || v >= float64(math.MaxInt32) { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) + } + r = int32(v) outputCol.Set(tupleIdx, r) } @@ -4765,9 +5275,12 @@ func (c *castInt2FloatOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r float64 + var r int32 - r = float64(v) + if math.IsNaN(float64(v)) || v <= float64(math.MinInt32) || v >= float64(math.MaxInt32) { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) + } + r = int32(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -4780,14 +5293,14 @@ func (c *castInt2FloatOp) Next() coldata.Batch { return batch } -type castInt2Int4Op struct { +type castFloatIntOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castInt2Int4Op{} -var _ colexecop.ClosableOperator = &castInt2Int4Op{} +var _ colexecop.ResettableOperator = &castFloatIntOp{} +var _ colexecop.ClosableOperator = &castFloatIntOp{} -func (c *castInt2Int4Op) Next() coldata.Batch { +func (c *castFloatIntOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -4801,9 +5314,9 @@ func (c *castInt2Int4Op) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int16() + inputCol := inputVec.Float64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int32() + outputCol := outputVec.Int64() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -4823,8 +5336,13 @@ func (c *castInt2Int4Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int32 - r = int32(v) + var r int64 + + if math.IsNaN(float64(v)) || v <= float64(math.MinInt64) || v >= float64(math.MaxInt64) { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) + } + r = int64(v) + outputCol.Set(tupleIdx, r) } } @@ -4847,8 +5365,13 @@ func (c *castInt2Int4Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int32 - r = int32(v) + var r int64 + + if math.IsNaN(float64(v)) || v <= float64(math.MinInt64) || v >= float64(math.MaxInt64) { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) + } + r = int64(v) + //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -4871,8 +5394,13 @@ func (c *castInt2Int4Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int32 - r = int32(v) + var r int64 + + if math.IsNaN(float64(v)) || v <= float64(math.MinInt64) || v >= float64(math.MaxInt64) { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) + } + r = int64(v) + outputCol.Set(tupleIdx, r) } } @@ -4895,8 +5423,13 @@ func (c *castInt2Int4Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int32 - r = int32(v) + var r int64 + + if math.IsNaN(float64(v)) || v <= float64(math.MinInt64) || v >= float64(math.MaxInt64) { + colexecerror.ExpectedError(tree.ErrIntOutOfRange) + } + r = int64(v) + //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -4908,14 +5441,14 @@ func (c *castInt2Int4Op) Next() coldata.Batch { return batch } -type castInt2IntOp struct { +type castFloatStringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castInt2IntOp{} -var _ colexecop.ClosableOperator = &castInt2IntOp{} +var _ colexecop.ResettableOperator = &castFloatStringOp{} +var _ colexecop.ClosableOperator = &castFloatStringOp{} -func (c *castInt2IntOp) Next() coldata.Batch { +func (c *castFloatStringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -4929,9 +5462,9 @@ func (c *castInt2IntOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int16() + inputCol := inputVec.Float64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int64() + outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -4951,8 +5484,33 @@ func (c *castInt2IntOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 - r = int64(v) + var r []byte + + dcc := evalCtx.SessionData().DataConversionConfig + r = tree.PgwireFormatFloat(nil /* buf */, v, dcc, types.Float) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + outputCol.Set(tupleIdx, r) } } @@ -4966,7 +5524,6 @@ func (c *castInt2IntOp) Next() coldata.Batch { _ = evalCtx _ = buf _ = inputCol.Get(n - 1) - _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -4975,9 +5532,33 @@ func (c *castInt2IntOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int64 - r = int64(v) - //gcassert:bce + var r []byte + + dcc := evalCtx.SessionData().DataConversionConfig + r = tree.PgwireFormatFloat(nil /* buf */, v, dcc, types.Float) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + outputCol.Set(tupleIdx, r) } } @@ -4999,8 +5580,33 @@ func (c *castInt2IntOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 - r = int64(v) + var r []byte + + dcc := evalCtx.SessionData().DataConversionConfig + r = tree.PgwireFormatFloat(nil /* buf */, v, dcc, types.Float) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + outputCol.Set(tupleIdx, r) } } @@ -5014,7 +5620,6 @@ func (c *castInt2IntOp) Next() coldata.Batch { _ = evalCtx _ = buf _ = inputCol.Get(n - 1) - _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -5023,9 +5628,33 @@ func (c *castInt2IntOp) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int64 - r = int64(v) - //gcassert:bce + var r []byte + + dcc := evalCtx.SessionData().DataConversionConfig + r = tree.PgwireFormatFloat(nil /* buf */, v, dcc, types.Float) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + outputCol.Set(tupleIdx, r) } } @@ -5036,14 +5665,14 @@ func (c *castInt2IntOp) Next() coldata.Batch { return batch } -type castInt4BoolOp struct { +type castInt2BoolOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castInt4BoolOp{} -var _ colexecop.ClosableOperator = &castInt4BoolOp{} +var _ colexecop.ResettableOperator = &castInt2BoolOp{} +var _ colexecop.ClosableOperator = &castInt2BoolOp{} -func (c *castInt4BoolOp) Next() coldata.Batch { +func (c *castInt2BoolOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -5057,7 +5686,7 @@ func (c *castInt4BoolOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int32() + inputCol := inputVec.Int16() inputNulls := inputVec.Nulls() outputCol := outputVec.Bool() outputNulls := outputVec.Nulls() @@ -5172,14 +5801,14 @@ func (c *castInt4BoolOp) Next() coldata.Batch { return batch } -type castInt4DecimalOp struct { +type castInt2DecimalOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castInt4DecimalOp{} -var _ colexecop.ClosableOperator = &castInt4DecimalOp{} +var _ colexecop.ResettableOperator = &castInt2DecimalOp{} +var _ colexecop.ClosableOperator = &castInt2DecimalOp{} -func (c *castInt4DecimalOp) Next() coldata.Batch { +func (c *castInt2DecimalOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -5193,7 +5822,7 @@ func (c *castInt4DecimalOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int32() + inputCol := inputVec.Int16() inputNulls := inputVec.Nulls() outputCol := outputVec.Decimal() outputNulls := outputVec.Nulls() @@ -5324,14 +5953,14 @@ func (c *castInt4DecimalOp) Next() coldata.Batch { return batch } -type castInt4FloatOp struct { +type castInt2FloatOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castInt4FloatOp{} -var _ colexecop.ClosableOperator = &castInt4FloatOp{} +var _ colexecop.ResettableOperator = &castInt2FloatOp{} +var _ colexecop.ClosableOperator = &castInt2FloatOp{} -func (c *castInt4FloatOp) Next() coldata.Batch { +func (c *castInt2FloatOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -5345,7 +5974,7 @@ func (c *castInt4FloatOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int32() + inputCol := inputVec.Int16() inputNulls := inputVec.Nulls() outputCol := outputVec.Float64() outputNulls := outputVec.Nulls() @@ -5460,14 +6089,14 @@ func (c *castInt4FloatOp) Next() coldata.Batch { return batch } -type castInt4Int2Op struct { +type castInt2Int4Op struct { castOpBase } -var _ colexecop.ResettableOperator = &castInt4Int2Op{} -var _ colexecop.ClosableOperator = &castInt4Int2Op{} +var _ colexecop.ResettableOperator = &castInt2Int4Op{} +var _ colexecop.ClosableOperator = &castInt2Int4Op{} -func (c *castInt4Int2Op) Next() coldata.Batch { +func (c *castInt2Int4Op) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -5481,9 +6110,9 @@ func (c *castInt4Int2Op) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int32() + inputCol := inputVec.Int16() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int16() + outputCol := outputVec.Int32() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -5503,14 +6132,8 @@ func (c *castInt4Int2Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int16 - - shifted := v >> uint(15) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) - } - r = int16(v) - + var r int32 + r = int32(v) outputCol.Set(tupleIdx, r) } } @@ -5533,14 +6156,8 @@ func (c *castInt4Int2Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int16 - - shifted := v >> uint(15) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) - } - r = int16(v) - + var r int32 + r = int32(v) //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -5563,14 +6180,8 @@ func (c *castInt4Int2Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int16 - - shifted := v >> uint(15) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) - } - r = int16(v) - + var r int32 + r = int32(v) outputCol.Set(tupleIdx, r) } } @@ -5593,14 +6204,8 @@ func (c *castInt4Int2Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int16 - - shifted := v >> uint(15) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) - } - r = int16(v) - + var r int32 + r = int32(v) //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -5612,14 +6217,14 @@ func (c *castInt4Int2Op) Next() coldata.Batch { return batch } -type castInt4IntOp struct { +type castInt2IntOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castInt4IntOp{} -var _ colexecop.ClosableOperator = &castInt4IntOp{} +var _ colexecop.ResettableOperator = &castInt2IntOp{} +var _ colexecop.ClosableOperator = &castInt2IntOp{} -func (c *castInt4IntOp) Next() coldata.Batch { +func (c *castInt2IntOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -5633,7 +6238,7 @@ func (c *castInt4IntOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int32() + inputCol := inputVec.Int16() inputNulls := inputVec.Nulls() outputCol := outputVec.Int64() outputNulls := outputVec.Nulls() @@ -5740,14 +6345,14 @@ func (c *castInt4IntOp) Next() coldata.Batch { return batch } -type castIntBoolOp struct { +type castInt2StringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castIntBoolOp{} -var _ colexecop.ClosableOperator = &castIntBoolOp{} +var _ colexecop.ResettableOperator = &castInt2StringOp{} +var _ colexecop.ClosableOperator = &castInt2StringOp{} -func (c *castIntBoolOp) Next() coldata.Batch { +func (c *castInt2StringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -5761,9 +6366,9 @@ func (c *castIntBoolOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int64() + inputCol := inputVec.Int16() inputNulls := inputVec.Nulls() - outputCol := outputVec.Bool() + outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -5783,12 +6388,280 @@ func (c *castIntBoolOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r bool - - r = v != 0 + var r []byte - outputCol.Set(tupleIdx, r) - } + if toType.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if v > math.MaxInt8 || v < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) + } + if v == 0 { + r = []byte{} + } else { + r = []byte{byte(v)} + } + } else { + r = []byte(strconv.FormatInt(int64(v), 10)) + } + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = inputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if true && inputNulls.NullAt(tupleIdx) { + continue + } + //gcassert:bce + v := inputCol.Get(tupleIdx) + var r []byte + + if toType.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if v > math.MaxInt8 || v < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) + } + if v == 0 { + r = []byte{} + } else { + r = []byte{byte(v)} + } + } else { + r = []byte(strconv.FormatInt(int64(v), 10)) + } + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + + outputCol.Set(tupleIdx, r) + } + } + } + } else { + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r []byte + + if toType.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if v > math.MaxInt8 || v < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) + } + if v == 0 { + r = []byte{} + } else { + r = []byte{byte(v)} + } + } else { + r = []byte(strconv.FormatInt(int64(v), 10)) + } + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = inputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if false && inputNulls.NullAt(tupleIdx) { + continue + } + //gcassert:bce + v := inputCol.Get(tupleIdx) + var r []byte + + if toType.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if v > math.MaxInt8 || v < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) + } + if v == 0 { + r = []byte{} + } else { + r = []byte{byte(v)} + } + } else { + r = []byte(strconv.FormatInt(int64(v), 10)) + } + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + + outputCol.Set(tupleIdx, r) + } + } + } + } + }, + ) + return batch +} + +type castInt4BoolOp struct { + castOpBase +} + +var _ colexecop.ResettableOperator = &castInt4BoolOp{} +var _ colexecop.ClosableOperator = &castInt4BoolOp{} + +func (c *castInt4BoolOp) Next() coldata.Batch { + batch := c.Input.Next() + n := batch.Length() + if n == 0 { + return coldata.ZeroBatch + } + sel := batch.Selection() + inputVec := batch.ColVec(c.colIdx) + outputVec := batch.ColVec(c.outputIdx) + toType := outputVec.Type() + // Remove unused warnings. + _ = toType + c.allocator.PerformOperation( + []coldata.Vec{outputVec}, func() { + inputCol := inputVec.Int32() + inputNulls := inputVec.Nulls() + outputCol := outputVec.Bool() + outputNulls := outputVec.Nulls() + if inputVec.MaybeHasNulls() { + outputNulls.Copy(inputNulls) + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r bool + + r = v != 0 + + outputCol.Set(tupleIdx, r) + } } } else { { @@ -5876,14 +6749,14 @@ func (c *castIntBoolOp) Next() coldata.Batch { return batch } -type castIntDecimalOp struct { +type castInt4DecimalOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castIntDecimalOp{} -var _ colexecop.ClosableOperator = &castIntDecimalOp{} +var _ colexecop.ResettableOperator = &castInt4DecimalOp{} +var _ colexecop.ClosableOperator = &castInt4DecimalOp{} -func (c *castIntDecimalOp) Next() coldata.Batch { +func (c *castInt4DecimalOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -5897,7 +6770,7 @@ func (c *castIntDecimalOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int64() + inputCol := inputVec.Int32() inputNulls := inputVec.Nulls() outputCol := outputVec.Decimal() outputNulls := outputVec.Nulls() @@ -6028,14 +6901,14 @@ func (c *castIntDecimalOp) Next() coldata.Batch { return batch } -type castIntFloatOp struct { +type castInt4FloatOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castIntFloatOp{} -var _ colexecop.ClosableOperator = &castIntFloatOp{} +var _ colexecop.ResettableOperator = &castInt4FloatOp{} +var _ colexecop.ClosableOperator = &castInt4FloatOp{} -func (c *castIntFloatOp) Next() coldata.Batch { +func (c *castInt4FloatOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -6049,7 +6922,7 @@ func (c *castIntFloatOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int64() + inputCol := inputVec.Int32() inputNulls := inputVec.Nulls() outputCol := outputVec.Float64() outputNulls := outputVec.Nulls() @@ -6164,14 +7037,14 @@ func (c *castIntFloatOp) Next() coldata.Batch { return batch } -type castIntInt2Op struct { +type castInt4Int2Op struct { castOpBase } -var _ colexecop.ResettableOperator = &castIntInt2Op{} -var _ colexecop.ClosableOperator = &castIntInt2Op{} +var _ colexecop.ResettableOperator = &castInt4Int2Op{} +var _ colexecop.ClosableOperator = &castInt4Int2Op{} -func (c *castIntInt2Op) Next() coldata.Batch { +func (c *castInt4Int2Op) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -6185,7 +7058,7 @@ func (c *castIntInt2Op) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int64() + inputCol := inputVec.Int32() inputNulls := inputVec.Nulls() outputCol := outputVec.Int16() outputNulls := outputVec.Nulls() @@ -6316,14 +7189,14 @@ func (c *castIntInt2Op) Next() coldata.Batch { return batch } -type castIntInt4Op struct { +type castInt4IntOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castIntInt4Op{} -var _ colexecop.ClosableOperator = &castIntInt4Op{} +var _ colexecop.ResettableOperator = &castInt4IntOp{} +var _ colexecop.ClosableOperator = &castInt4IntOp{} -func (c *castIntInt4Op) Next() coldata.Batch { +func (c *castInt4IntOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -6337,9 +7210,9 @@ func (c *castIntInt4Op) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Int64() + inputCol := inputVec.Int32() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int32() + outputCol := outputVec.Int64() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -6359,14 +7232,8 @@ func (c *castIntInt4Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int32 - - shifted := v >> uint(31) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - r = int32(v) - + var r int64 + r = int64(v) outputCol.Set(tupleIdx, r) } } @@ -6389,14 +7256,8 @@ func (c *castIntInt4Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int32 - - shifted := v >> uint(31) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - r = int32(v) - + var r int64 + r = int64(v) //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -6419,14 +7280,8 @@ func (c *castIntInt4Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int32 - - shifted := v >> uint(31) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - r = int32(v) - + var r int64 + r = int64(v) outputCol.Set(tupleIdx, r) } } @@ -6449,14 +7304,8 @@ func (c *castIntInt4Op) Next() coldata.Batch { } //gcassert:bce v := inputCol.Get(tupleIdx) - var r int32 - - shifted := v >> uint(31) - if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) - } - r = int32(v) - + var r int64 + r = int64(v) //gcassert:bce outputCol.Set(tupleIdx, r) } @@ -6468,14 +7317,14 @@ func (c *castIntInt4Op) Next() coldata.Batch { return batch } -type castJsonbStringOp struct { +type castInt4StringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castJsonbStringOp{} -var _ colexecop.ClosableOperator = &castJsonbStringOp{} +var _ colexecop.ResettableOperator = &castInt4StringOp{} +var _ colexecop.ClosableOperator = &castInt4StringOp{} -func (c *castJsonbStringOp) Next() coldata.Batch { +func (c *castInt4StringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -6489,7 +7338,7 @@ func (c *castJsonbStringOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.JSON() + inputCol := inputVec.Int32() inputNulls := inputVec.Nulls() outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() @@ -6513,16 +7362,41 @@ func (c *castJsonbStringOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r []byte - _string := v.String() - switch toType.Oid() { - case oid.T_char: - // "char" is supposed to truncate long values. - _string = util.TruncateString(_string, 1) - case oid.T_bpchar: + if toType.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if v > math.MaxInt8 || v < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) + } + if v == 0 { + r = []byte{} + } else { + r = []byte{byte(v)} + } + } else { + r = []byte(strconv.FormatInt(int64(v), 10)) + } + + if toType.Oid() != oid.T_name { // bpchar types truncate trailing whitespace. - _string = strings.TrimRight(_string, " ") + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - r = []byte(_string) outputCol.Set(tupleIdx, r) } @@ -6536,25 +7410,52 @@ func (c *castJsonbStringOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if true && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) var r []byte - _string := v.String() - switch toType.Oid() { - case oid.T_char: - // "char" is supposed to truncate long values. - _string = util.TruncateString(_string, 1) - case oid.T_bpchar: + if toType.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if v > math.MaxInt8 || v < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) + } + if v == 0 { + r = []byte{} + } else { + r = []byte{byte(v)} + } + } else { + r = []byte(strconv.FormatInt(int64(v), 10)) + } + + if toType.Oid() != oid.T_name { // bpchar types truncate trailing whitespace. - _string = strings.TrimRight(_string, " ") + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - r = []byte(_string) outputCol.Set(tupleIdx, r) } @@ -6579,16 +7480,41 @@ func (c *castJsonbStringOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r []byte - _string := v.String() - switch toType.Oid() { - case oid.T_char: - // "char" is supposed to truncate long values. - _string = util.TruncateString(_string, 1) - case oid.T_bpchar: + if toType.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if v > math.MaxInt8 || v < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) + } + if v == 0 { + r = []byte{} + } else { + r = []byte{byte(v)} + } + } else { + r = []byte(strconv.FormatInt(int64(v), 10)) + } + + if toType.Oid() != oid.T_name { // bpchar types truncate trailing whitespace. - _string = strings.TrimRight(_string, " ") + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - r = []byte(_string) outputCol.Set(tupleIdx, r) } @@ -6602,25 +7528,52 @@ func (c *castJsonbStringOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if false && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) var r []byte - _string := v.String() - switch toType.Oid() { - case oid.T_char: - // "char" is supposed to truncate long values. - _string = util.TruncateString(_string, 1) - case oid.T_bpchar: + if toType.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if v > math.MaxInt8 || v < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) + } + if v == 0 { + r = []byte{} + } else { + r = []byte{byte(v)} + } + } else { + r = []byte(strconv.FormatInt(int64(v), 10)) + } + + if toType.Oid() != oid.T_name { // bpchar types truncate trailing whitespace. - _string = strings.TrimRight(_string, " ") + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - r = []byte(_string) outputCol.Set(tupleIdx, r) } @@ -6632,14 +7585,14 @@ func (c *castJsonbStringOp) Next() coldata.Batch { return batch } -type castStringBoolOp struct { +type castIntBoolOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringBoolOp{} -var _ colexecop.ClosableOperator = &castStringBoolOp{} +var _ colexecop.ResettableOperator = &castIntBoolOp{} +var _ colexecop.ClosableOperator = &castIntBoolOp{} -func (c *castStringBoolOp) Next() coldata.Batch { +func (c *castIntBoolOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -6653,7 +7606,7 @@ func (c *castStringBoolOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Bytes() + inputCol := inputVec.Int64() inputNulls := inputVec.Nulls() outputCol := outputVec.Bool() outputNulls := outputVec.Nulls() @@ -6677,11 +7630,7 @@ func (c *castStringBoolOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r bool - var err error - r, err = tree.ParseBool(string(v)) - if err != nil { - colexecerror.ExpectedError(err) - } + r = v != 0 outputCol.Set(tupleIdx, r) } @@ -6695,6 +7644,7 @@ func (c *castStringBoolOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6702,14 +7652,11 @@ func (c *castStringBoolOp) Next() coldata.Batch { if true && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) var r bool - var err error - r, err = tree.ParseBool(string(v)) - if err != nil { - colexecerror.ExpectedError(err) - } + r = v != 0 //gcassert:bce outputCol.Set(tupleIdx, r) @@ -6735,11 +7682,7 @@ func (c *castStringBoolOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r bool - var err error - r, err = tree.ParseBool(string(v)) - if err != nil { - colexecerror.ExpectedError(err) - } + r = v != 0 outputCol.Set(tupleIdx, r) } @@ -6753,6 +7696,7 @@ func (c *castStringBoolOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6760,14 +7704,11 @@ func (c *castStringBoolOp) Next() coldata.Batch { if false && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) var r bool - var err error - r, err = tree.ParseBool(string(v)) - if err != nil { - colexecerror.ExpectedError(err) - } + r = v != 0 //gcassert:bce outputCol.Set(tupleIdx, r) @@ -6780,14 +7721,14 @@ func (c *castStringBoolOp) Next() coldata.Batch { return batch } -type castStringBytesOp struct { +type castIntDecimalOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringBytesOp{} -var _ colexecop.ClosableOperator = &castStringBytesOp{} +var _ colexecop.ResettableOperator = &castIntDecimalOp{} +var _ colexecop.ClosableOperator = &castIntDecimalOp{} -func (c *castStringBytesOp) Next() coldata.Batch { +func (c *castIntDecimalOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -6801,9 +7742,9 @@ func (c *castStringBytesOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Bytes() + inputCol := inputVec.Int64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Bytes() + outputCol := outputVec.Decimal() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -6823,11 +7764,11 @@ func (c *castStringBytesOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r []byte + var r apd.Decimal - var err error - r, err = lex.DecodeRawBytesToByteArrayAuto(v) - if err != nil { + r.SetInt64(int64(v)) + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { colexecerror.ExpectedError(err) } @@ -6843,21 +7784,25 @@ func (c *castStringBytesOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) + _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if true && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r []byte + var r apd.Decimal - var err error - r, err = lex.DecodeRawBytesToByteArrayAuto(v) - if err != nil { + r.SetInt64(int64(v)) + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { colexecerror.ExpectedError(err) } + //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -6879,11 +7824,11 @@ func (c *castStringBytesOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r []byte + var r apd.Decimal - var err error - r, err = lex.DecodeRawBytesToByteArrayAuto(v) - if err != nil { + r.SetInt64(int64(v)) + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { colexecerror.ExpectedError(err) } @@ -6899,21 +7844,25 @@ func (c *castStringBytesOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) + _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if false && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r []byte + var r apd.Decimal - var err error - r, err = lex.DecodeRawBytesToByteArrayAuto(v) - if err != nil { + r.SetInt64(int64(v)) + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { colexecerror.ExpectedError(err) } + //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -6924,14 +7873,14 @@ func (c *castStringBytesOp) Next() coldata.Batch { return batch } -type castStringDateOp struct { +type castIntFloatOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringDateOp{} -var _ colexecop.ClosableOperator = &castStringDateOp{} +var _ colexecop.ResettableOperator = &castIntFloatOp{} +var _ colexecop.ClosableOperator = &castIntFloatOp{} -func (c *castStringDateOp) Next() coldata.Batch { +func (c *castIntFloatOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -6945,9 +7894,9 @@ func (c *castStringDateOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Bytes() + inputCol := inputVec.Int64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int64() + outputCol := outputVec.Float64() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -6967,15 +7916,9 @@ func (c *castStringDateOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 + var r float64 - _now := evalCtx.GetRelativeParseTime() - _dateStyle := evalCtx.GetDateStyle() - _d, _, err := pgdate.ParseDate(_now, _dateStyle, string(v)) - if err != nil { - colexecerror.ExpectedError(err) - } - r = _d.UnixEpochDays() + r = float64(v) outputCol.Set(tupleIdx, r) } @@ -6989,6 +7932,7 @@ func (c *castStringDateOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -6996,16 +7940,11 @@ func (c *castStringDateOp) Next() coldata.Batch { if true && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r int64 + var r float64 - _now := evalCtx.GetRelativeParseTime() - _dateStyle := evalCtx.GetDateStyle() - _d, _, err := pgdate.ParseDate(_now, _dateStyle, string(v)) - if err != nil { - colexecerror.ExpectedError(err) - } - r = _d.UnixEpochDays() + r = float64(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -7029,15 +7968,9 @@ func (c *castStringDateOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 + var r float64 - _now := evalCtx.GetRelativeParseTime() - _dateStyle := evalCtx.GetDateStyle() - _d, _, err := pgdate.ParseDate(_now, _dateStyle, string(v)) - if err != nil { - colexecerror.ExpectedError(err) - } - r = _d.UnixEpochDays() + r = float64(v) outputCol.Set(tupleIdx, r) } @@ -7051,6 +7984,7 @@ func (c *castStringDateOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7058,16 +7992,11 @@ func (c *castStringDateOp) Next() coldata.Batch { if false && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r int64 + var r float64 - _now := evalCtx.GetRelativeParseTime() - _dateStyle := evalCtx.GetDateStyle() - _d, _, err := pgdate.ParseDate(_now, _dateStyle, string(v)) - if err != nil { - colexecerror.ExpectedError(err) - } - r = _d.UnixEpochDays() + r = float64(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -7080,14 +8009,14 @@ func (c *castStringDateOp) Next() coldata.Batch { return batch } -type castStringDecimalOp struct { +type castIntInt2Op struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringDecimalOp{} -var _ colexecop.ClosableOperator = &castStringDecimalOp{} +var _ colexecop.ResettableOperator = &castIntInt2Op{} +var _ colexecop.ClosableOperator = &castIntInt2Op{} -func (c *castStringDecimalOp) Next() coldata.Batch { +func (c *castIntInt2Op) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -7101,9 +8030,9 @@ func (c *castStringDecimalOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Bytes() + inputCol := inputVec.Int64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Decimal() + outputCol := outputVec.Int16() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -7123,28 +8052,13 @@ func (c *castStringDecimalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r apd.Decimal - - _s := strings.TrimSpace(string(v)) - _, res, err := tree.ExactCtx.SetString(&r, _s) - if res != 0 || err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, types.Decimal, err)) - } - switch r.Form { - case apd.NaNSignaling: - r.Form = apd.NaN - r.Negative = false - case apd.NaN: - r.Negative = false - case apd.Finite: - if r.IsZero() && r.Negative { - r.Negative = false - } - } + var r int16 - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) + shifted := v >> uint(15) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) } + r = int16(v) outputCol.Set(tupleIdx, r) } @@ -7158,6 +8072,7 @@ func (c *castStringDecimalOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7165,29 +8080,15 @@ func (c *castStringDecimalOp) Next() coldata.Batch { if true && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r apd.Decimal - - _s := strings.TrimSpace(string(v)) - _, res, err := tree.ExactCtx.SetString(&r, _s) - if res != 0 || err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, types.Decimal, err)) - } - switch r.Form { - case apd.NaNSignaling: - r.Form = apd.NaN - r.Negative = false - case apd.NaN: - r.Negative = false - case apd.Finite: - if r.IsZero() && r.Negative { - r.Negative = false - } - } + var r int16 - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) + shifted := v >> uint(15) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) } + r = int16(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -7211,28 +8112,13 @@ func (c *castStringDecimalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r apd.Decimal - - _s := strings.TrimSpace(string(v)) - _, res, err := tree.ExactCtx.SetString(&r, _s) - if res != 0 || err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, types.Decimal, err)) - } - switch r.Form { - case apd.NaNSignaling: - r.Form = apd.NaN - r.Negative = false - case apd.NaN: - r.Negative = false - case apd.Finite: - if r.IsZero() && r.Negative { - r.Negative = false - } - } + var r int16 - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) + shifted := v >> uint(15) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) } + r = int16(v) outputCol.Set(tupleIdx, r) } @@ -7246,6 +8132,7 @@ func (c *castStringDecimalOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7253,29 +8140,15 @@ func (c *castStringDecimalOp) Next() coldata.Batch { if false && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r apd.Decimal - - _s := strings.TrimSpace(string(v)) - _, res, err := tree.ExactCtx.SetString(&r, _s) - if res != 0 || err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, types.Decimal, err)) - } - switch r.Form { - case apd.NaNSignaling: - r.Form = apd.NaN - r.Negative = false - case apd.NaN: - r.Negative = false - case apd.Finite: - if r.IsZero() && r.Negative { - r.Negative = false - } - } + var r int16 - if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { - colexecerror.ExpectedError(err) + shifted := v >> uint(15) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) } + r = int16(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -7288,14 +8161,14 @@ func (c *castStringDecimalOp) Next() coldata.Batch { return batch } -type castStringFloatOp struct { +type castIntInt4Op struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringFloatOp{} -var _ colexecop.ClosableOperator = &castStringFloatOp{} +var _ colexecop.ResettableOperator = &castIntInt4Op{} +var _ colexecop.ClosableOperator = &castIntInt4Op{} -func (c *castStringFloatOp) Next() coldata.Batch { +func (c *castIntInt4Op) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -7309,9 +8182,9 @@ func (c *castStringFloatOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Bytes() + inputCol := inputVec.Int64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Float64() + outputCol := outputVec.Int32() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -7331,14 +8204,13 @@ func (c *castStringFloatOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r float64 + var r int32 - _s := string(v) - var _err error - r, _err = strconv.ParseFloat(strings.TrimSpace(_s), 64) - if _err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, _err)) + shifted := v >> uint(31) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) } + r = int32(v) outputCol.Set(tupleIdx, r) } @@ -7352,6 +8224,7 @@ func (c *castStringFloatOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7359,15 +8232,15 @@ func (c *castStringFloatOp) Next() coldata.Batch { if true && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r float64 + var r int32 - _s := string(v) - var _err error - r, _err = strconv.ParseFloat(strings.TrimSpace(_s), 64) - if _err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, _err)) + shifted := v >> uint(31) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) } + r = int32(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -7391,14 +8264,13 @@ func (c *castStringFloatOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r float64 + var r int32 - _s := string(v) - var _err error - r, _err = strconv.ParseFloat(strings.TrimSpace(_s), 64) - if _err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, _err)) + shifted := v >> uint(31) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) } + r = int32(v) outputCol.Set(tupleIdx, r) } @@ -7412,6 +8284,7 @@ func (c *castStringFloatOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = inputCol.Get(n - 1) _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { @@ -7419,15 +8292,15 @@ func (c *castStringFloatOp) Next() coldata.Batch { if false && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r float64 + var r int32 - _s := string(v) - var _err error - r, _err = strconv.ParseFloat(strings.TrimSpace(_s), 64) - if _err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, _err)) + shifted := v >> uint(31) + if (v >= 0 && shifted > 0) || (v < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) } + r = int32(v) //gcassert:bce outputCol.Set(tupleIdx, r) @@ -7440,14 +8313,14 @@ func (c *castStringFloatOp) Next() coldata.Batch { return batch } -type castStringInt2Op struct { +type castIntStringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringInt2Op{} -var _ colexecop.ClosableOperator = &castStringInt2Op{} +var _ colexecop.ResettableOperator = &castIntStringOp{} +var _ colexecop.ClosableOperator = &castIntStringOp{} -func (c *castStringInt2Op) Next() coldata.Batch { +func (c *castIntStringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -7461,9 +8334,9 @@ func (c *castStringInt2Op) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Bytes() + inputCol := inputVec.Int64() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int16() + outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -7483,21 +8356,42 @@ func (c *castStringInt2Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int16 + var r []byte - { - _s := string(v) - _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) - if err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + if toType.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if v > math.MaxInt8 || v < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) } - - shifted := _i >> uint(15) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + if v == 0 { + r = []byte{} + } else { + r = []byte{byte(v)} } - r = int16(_i) + } else { + r = []byte(strconv.FormatInt(int64(v), 10)) + } + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -7512,32 +8406,53 @@ func (c *castStringInt2Op) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = outputCol.Get(n - 1) + _ = inputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if true && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r int16 + var r []byte - { - _s := string(v) - _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) - if err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + if toType.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if v > math.MaxInt8 || v < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) } - - shifted := _i >> uint(15) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + if v == 0 { + r = []byte{} + } else { + r = []byte{byte(v)} } - r = int16(_i) + } else { + r = []byte(strconv.FormatInt(int64(v), 10)) + } + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -7559,61 +8474,103 @@ func (c *castStringInt2Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int16 + var r []byte - { - _s := string(v) - _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) - if err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + if toType.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if v > math.MaxInt8 || v < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) } - - shifted := _i >> uint(15) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + if v == 0 { + r = []byte{} + } else { + r = []byte{byte(v)} } - r = int16(_i) - + } else { + r = []byte(strconv.FormatInt(int64(v), 10)) } - outputCol.Set(tupleIdx, r) - } - } - } else { - { - var ( - evalCtx *eval.Context = c.evalCtx - buf *bytes.Buffer = &c.buf + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf ) // Silence unused warnings. _ = evalCtx _ = buf - _ = outputCol.Get(n - 1) + _ = inputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if false && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r int16 + var r []byte - { - _s := string(v) - _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) - if err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + if toType.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if v > math.MaxInt8 || v < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) } - - shifted := _i >> uint(15) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + if v == 0 { + r = []byte{} + } else { + r = []byte{byte(v)} } - r = int16(_i) + } else { + r = []byte(strconv.FormatInt(int64(v), 10)) + } + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -7624,14 +8581,14 @@ func (c *castStringInt2Op) Next() coldata.Batch { return batch } -type castStringInt4Op struct { +type castIntervalStringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringInt4Op{} -var _ colexecop.ClosableOperator = &castStringInt4Op{} +var _ colexecop.ResettableOperator = &castIntervalStringOp{} +var _ colexecop.ClosableOperator = &castIntervalStringOp{} -func (c *castStringInt4Op) Next() coldata.Batch { +func (c *castIntervalStringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -7645,9 +8602,9 @@ func (c *castStringInt4Op) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Bytes() + inputCol := inputVec.Interval() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int32() + outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -7667,21 +8624,33 @@ func (c *castStringInt4Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int32 + var r []byte - { - _s := string(v) - _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) - if err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) - } + dcc := evalCtx.SessionData().DataConversionConfig + buf.Reset() + v.FormatWithStyle(buf, dcc.IntervalStyle) + r = []byte(buf.String()) - shifted := _i >> uint(31) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) } - r = int32(_i) - + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -7696,32 +8665,44 @@ func (c *castStringInt4Op) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = outputCol.Get(n - 1) + _ = inputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if true && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r int32 + var r []byte - { - _s := string(v) - _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) - if err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) - } + dcc := evalCtx.SessionData().DataConversionConfig + buf.Reset() + v.FormatWithStyle(buf, dcc.IntervalStyle) + r = []byte(buf.String()) - shifted := _i >> uint(31) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") } - r = int32(_i) - + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -7743,21 +8724,33 @@ func (c *castStringInt4Op) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int32 + var r []byte - { - _s := string(v) - _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) - if err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) - } + dcc := evalCtx.SessionData().DataConversionConfig + buf.Reset() + v.FormatWithStyle(buf, dcc.IntervalStyle) + r = []byte(buf.String()) - shifted := _i >> uint(31) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) } - r = int32(_i) - + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -7772,32 +8765,44 @@ func (c *castStringInt4Op) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = outputCol.Get(n - 1) + _ = inputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if false && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r int32 + var r []byte - { - _s := string(v) - _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) - if err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) - } + dcc := evalCtx.SessionData().DataConversionConfig + buf.Reset() + v.FormatWithStyle(buf, dcc.IntervalStyle) + r = []byte(buf.String()) - shifted := _i >> uint(31) - if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { - colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") } - r = int32(_i) - + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -7808,14 +8813,14 @@ func (c *castStringInt4Op) Next() coldata.Batch { return batch } -type castStringIntOp struct { +type castJsonbStringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringIntOp{} -var _ colexecop.ClosableOperator = &castStringIntOp{} +var _ colexecop.ResettableOperator = &castJsonbStringOp{} +var _ colexecop.ClosableOperator = &castJsonbStringOp{} -func (c *castStringIntOp) Next() coldata.Batch { +func (c *castJsonbStringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -7829,9 +8834,9 @@ func (c *castStringIntOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Bytes() + inputCol := inputVec.JSON() inputNulls := inputVec.Nulls() - outputCol := outputVec.Int64() + outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -7851,15 +8856,29 @@ func (c *castStringIntOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 + var r []byte - { - _s := string(v) - _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) - if err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + r = []byte(v.String()) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") } - r = int64(_i) + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -7874,7 +8893,6 @@ func (c *castStringIntOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -7882,18 +8900,31 @@ func (c *castStringIntOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 + var r []byte - { - _s := string(v) - _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) - if err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + r = []byte(v.String()) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") } - r = int64(_i) + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -7915,15 +8946,29 @@ func (c *castStringIntOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 + var r []byte - { - _s := string(v) - _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) - if err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + r = []byte(v.String()) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") } - r = int64(_i) + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -7938,7 +8983,6 @@ func (c *castStringIntOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -7946,18 +8990,1887 @@ func (c *castStringIntOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r int64 + var r []byte - { - _s := string(v) - _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) - if err != nil { - colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + r = []byte(v.String()) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") } - r = int64(_i) + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + + outputCol.Set(tupleIdx, r) + } + } + } + } + }, + ) + return batch +} + +type castStringBoolOp struct { + castOpBase +} + +var _ colexecop.ResettableOperator = &castStringBoolOp{} +var _ colexecop.ClosableOperator = &castStringBoolOp{} + +func (c *castStringBoolOp) Next() coldata.Batch { + batch := c.Input.Next() + n := batch.Length() + if n == 0 { + return coldata.ZeroBatch + } + sel := batch.Selection() + inputVec := batch.ColVec(c.colIdx) + outputVec := batch.ColVec(c.outputIdx) + toType := outputVec.Type() + // Remove unused warnings. + _ = toType + c.allocator.PerformOperation( + []coldata.Vec{outputVec}, func() { + inputCol := inputVec.Bytes() + inputNulls := inputVec.Nulls() + outputCol := outputVec.Bool() + outputNulls := outputVec.Nulls() + if inputVec.MaybeHasNulls() { + outputNulls.Copy(inputNulls) + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r bool + + var err error + r, err = tree.ParseBool(string(v)) + if err != nil { + colexecerror.ExpectedError(err) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r bool + + var err error + r, err = tree.ParseBool(string(v)) + if err != nil { + colexecerror.ExpectedError(err) + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } else { + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r bool + + var err error + r, err = tree.ParseBool(string(v)) + if err != nil { + colexecerror.ExpectedError(err) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r bool + + var err error + r, err = tree.ParseBool(string(v)) + if err != nil { + colexecerror.ExpectedError(err) + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } + }, + ) + return batch +} + +type castStringBytesOp struct { + castOpBase +} + +var _ colexecop.ResettableOperator = &castStringBytesOp{} +var _ colexecop.ClosableOperator = &castStringBytesOp{} + +func (c *castStringBytesOp) Next() coldata.Batch { + batch := c.Input.Next() + n := batch.Length() + if n == 0 { + return coldata.ZeroBatch + } + sel := batch.Selection() + inputVec := batch.ColVec(c.colIdx) + outputVec := batch.ColVec(c.outputIdx) + toType := outputVec.Type() + // Remove unused warnings. + _ = toType + c.allocator.PerformOperation( + []coldata.Vec{outputVec}, func() { + inputCol := inputVec.Bytes() + inputNulls := inputVec.Nulls() + outputCol := outputVec.Bytes() + outputNulls := outputVec.Nulls() + if inputVec.MaybeHasNulls() { + outputNulls.Copy(inputNulls) + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r []byte + + var err error + r, err = lex.DecodeRawBytesToByteArrayAuto(v) + if err != nil { + colexecerror.ExpectedError(err) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r []byte + + var err error + r, err = lex.DecodeRawBytesToByteArrayAuto(v) + if err != nil { + colexecerror.ExpectedError(err) + } + + outputCol.Set(tupleIdx, r) + } + } + } + } else { + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r []byte + + var err error + r, err = lex.DecodeRawBytesToByteArrayAuto(v) + if err != nil { + colexecerror.ExpectedError(err) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r []byte + + var err error + r, err = lex.DecodeRawBytesToByteArrayAuto(v) + if err != nil { + colexecerror.ExpectedError(err) + } + + outputCol.Set(tupleIdx, r) + } + } + } + } + }, + ) + return batch +} + +type castStringDateOp struct { + castOpBase +} + +var _ colexecop.ResettableOperator = &castStringDateOp{} +var _ colexecop.ClosableOperator = &castStringDateOp{} + +func (c *castStringDateOp) Next() coldata.Batch { + batch := c.Input.Next() + n := batch.Length() + if n == 0 { + return coldata.ZeroBatch + } + sel := batch.Selection() + inputVec := batch.ColVec(c.colIdx) + outputVec := batch.ColVec(c.outputIdx) + toType := outputVec.Type() + // Remove unused warnings. + _ = toType + c.allocator.PerformOperation( + []coldata.Vec{outputVec}, func() { + inputCol := inputVec.Bytes() + inputNulls := inputVec.Nulls() + outputCol := outputVec.Int64() + outputNulls := outputVec.Nulls() + if inputVec.MaybeHasNulls() { + outputNulls.Copy(inputNulls) + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int64 + + _now := evalCtx.GetRelativeParseTime() + _dateStyle := evalCtx.GetDateStyle() + _d, _, err := pgdate.ParseDate(_now, _dateStyle, string(v)) + if err != nil { + colexecerror.ExpectedError(err) + } + r = _d.UnixEpochDays() + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int64 + + _now := evalCtx.GetRelativeParseTime() + _dateStyle := evalCtx.GetDateStyle() + _d, _, err := pgdate.ParseDate(_now, _dateStyle, string(v)) + if err != nil { + colexecerror.ExpectedError(err) + } + r = _d.UnixEpochDays() + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } else { + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int64 + + _now := evalCtx.GetRelativeParseTime() + _dateStyle := evalCtx.GetDateStyle() + _d, _, err := pgdate.ParseDate(_now, _dateStyle, string(v)) + if err != nil { + colexecerror.ExpectedError(err) + } + r = _d.UnixEpochDays() + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int64 + + _now := evalCtx.GetRelativeParseTime() + _dateStyle := evalCtx.GetDateStyle() + _d, _, err := pgdate.ParseDate(_now, _dateStyle, string(v)) + if err != nil { + colexecerror.ExpectedError(err) + } + r = _d.UnixEpochDays() + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } + }, + ) + return batch +} + +type castStringDecimalOp struct { + castOpBase +} + +var _ colexecop.ResettableOperator = &castStringDecimalOp{} +var _ colexecop.ClosableOperator = &castStringDecimalOp{} + +func (c *castStringDecimalOp) Next() coldata.Batch { + batch := c.Input.Next() + n := batch.Length() + if n == 0 { + return coldata.ZeroBatch + } + sel := batch.Selection() + inputVec := batch.ColVec(c.colIdx) + outputVec := batch.ColVec(c.outputIdx) + toType := outputVec.Type() + // Remove unused warnings. + _ = toType + c.allocator.PerformOperation( + []coldata.Vec{outputVec}, func() { + inputCol := inputVec.Bytes() + inputNulls := inputVec.Nulls() + outputCol := outputVec.Decimal() + outputNulls := outputVec.Nulls() + if inputVec.MaybeHasNulls() { + outputNulls.Copy(inputNulls) + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r apd.Decimal + + _s := strings.TrimSpace(string(v)) + _, res, err := tree.ExactCtx.SetString(&r, _s) + if res != 0 || err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, types.Decimal, err)) + } + switch r.Form { + case apd.NaNSignaling: + r.Form = apd.NaN + r.Negative = false + case apd.NaN: + r.Negative = false + case apd.Finite: + if r.IsZero() && r.Negative { + r.Negative = false + } + } + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r apd.Decimal + + _s := strings.TrimSpace(string(v)) + _, res, err := tree.ExactCtx.SetString(&r, _s) + if res != 0 || err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, types.Decimal, err)) + } + switch r.Form { + case apd.NaNSignaling: + r.Form = apd.NaN + r.Negative = false + case apd.NaN: + r.Negative = false + case apd.Finite: + if r.IsZero() && r.Negative { + r.Negative = false + } + } + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } else { + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r apd.Decimal + + _s := strings.TrimSpace(string(v)) + _, res, err := tree.ExactCtx.SetString(&r, _s) + if res != 0 || err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, types.Decimal, err)) + } + switch r.Form { + case apd.NaNSignaling: + r.Form = apd.NaN + r.Negative = false + case apd.NaN: + r.Negative = false + case apd.Finite: + if r.IsZero() && r.Negative { + r.Negative = false + } + } + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r apd.Decimal + + _s := strings.TrimSpace(string(v)) + _, res, err := tree.ExactCtx.SetString(&r, _s) + if res != 0 || err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, types.Decimal, err)) + } + switch r.Form { + case apd.NaNSignaling: + r.Form = apd.NaN + r.Negative = false + case apd.NaN: + r.Negative = false + case apd.Finite: + if r.IsZero() && r.Negative { + r.Negative = false + } + } + + if err := tree.LimitDecimalWidth(&r, int(toType.Precision()), int(toType.Scale())); err != nil { + colexecerror.ExpectedError(err) + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } + }, + ) + return batch +} + +type castStringFloatOp struct { + castOpBase +} + +var _ colexecop.ResettableOperator = &castStringFloatOp{} +var _ colexecop.ClosableOperator = &castStringFloatOp{} + +func (c *castStringFloatOp) Next() coldata.Batch { + batch := c.Input.Next() + n := batch.Length() + if n == 0 { + return coldata.ZeroBatch + } + sel := batch.Selection() + inputVec := batch.ColVec(c.colIdx) + outputVec := batch.ColVec(c.outputIdx) + toType := outputVec.Type() + // Remove unused warnings. + _ = toType + c.allocator.PerformOperation( + []coldata.Vec{outputVec}, func() { + inputCol := inputVec.Bytes() + inputNulls := inputVec.Nulls() + outputCol := outputVec.Float64() + outputNulls := outputVec.Nulls() + if inputVec.MaybeHasNulls() { + outputNulls.Copy(inputNulls) + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r float64 + + _s := string(v) + var _err error + r, _err = strconv.ParseFloat(strings.TrimSpace(_s), 64) + if _err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, _err)) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r float64 + + _s := string(v) + var _err error + r, _err = strconv.ParseFloat(strings.TrimSpace(_s), 64) + if _err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, _err)) + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } else { + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r float64 + + _s := string(v) + var _err error + r, _err = strconv.ParseFloat(strings.TrimSpace(_s), 64) + if _err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, _err)) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r float64 + + _s := string(v) + var _err error + r, _err = strconv.ParseFloat(strings.TrimSpace(_s), 64) + if _err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, _err)) + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } + }, + ) + return batch +} + +type castStringInt2Op struct { + castOpBase +} + +var _ colexecop.ResettableOperator = &castStringInt2Op{} +var _ colexecop.ClosableOperator = &castStringInt2Op{} + +func (c *castStringInt2Op) Next() coldata.Batch { + batch := c.Input.Next() + n := batch.Length() + if n == 0 { + return coldata.ZeroBatch + } + sel := batch.Selection() + inputVec := batch.ColVec(c.colIdx) + outputVec := batch.ColVec(c.outputIdx) + toType := outputVec.Type() + // Remove unused warnings. + _ = toType + c.allocator.PerformOperation( + []coldata.Vec{outputVec}, func() { + inputCol := inputVec.Bytes() + inputNulls := inputVec.Nulls() + outputCol := outputVec.Int16() + outputNulls := outputVec.Nulls() + if inputVec.MaybeHasNulls() { + outputNulls.Copy(inputNulls) + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int16 + + { + _s := string(v) + _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) + if err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + } + + shifted := _i >> uint(15) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + r = int16(_i) + + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int16 + + { + _s := string(v) + _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) + if err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + } + + shifted := _i >> uint(15) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + r = int16(_i) + + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } else { + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int16 + + { + _s := string(v) + _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) + if err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + } + + shifted := _i >> uint(15) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + r = int16(_i) + + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int16 + + { + _s := string(v) + _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) + if err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + } + + shifted := _i >> uint(15) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt2OutOfRange) + } + r = int16(_i) + + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } + }, + ) + return batch +} + +type castStringInt4Op struct { + castOpBase +} + +var _ colexecop.ResettableOperator = &castStringInt4Op{} +var _ colexecop.ClosableOperator = &castStringInt4Op{} + +func (c *castStringInt4Op) Next() coldata.Batch { + batch := c.Input.Next() + n := batch.Length() + if n == 0 { + return coldata.ZeroBatch + } + sel := batch.Selection() + inputVec := batch.ColVec(c.colIdx) + outputVec := batch.ColVec(c.outputIdx) + toType := outputVec.Type() + // Remove unused warnings. + _ = toType + c.allocator.PerformOperation( + []coldata.Vec{outputVec}, func() { + inputCol := inputVec.Bytes() + inputNulls := inputVec.Nulls() + outputCol := outputVec.Int32() + outputNulls := outputVec.Nulls() + if inputVec.MaybeHasNulls() { + outputNulls.Copy(inputNulls) + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int32 + + { + _s := string(v) + _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) + if err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + } + + shifted := _i >> uint(31) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + r = int32(_i) + + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int32 + + { + _s := string(v) + _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) + if err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + } + + shifted := _i >> uint(31) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + r = int32(_i) + + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } else { + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int32 + + { + _s := string(v) + _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) + if err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + } + + shifted := _i >> uint(31) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + r = int32(_i) + + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int32 + + { + _s := string(v) + _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) + if err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + } + + shifted := _i >> uint(31) + if (_i >= 0 && shifted > 0) || (_i < 0 && shifted < -1) { + colexecerror.ExpectedError(tree.ErrInt4OutOfRange) + } + r = int32(_i) + + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } + }, + ) + return batch +} + +type castStringIntOp struct { + castOpBase +} + +var _ colexecop.ResettableOperator = &castStringIntOp{} +var _ colexecop.ClosableOperator = &castStringIntOp{} + +func (c *castStringIntOp) Next() coldata.Batch { + batch := c.Input.Next() + n := batch.Length() + if n == 0 { + return coldata.ZeroBatch + } + sel := batch.Selection() + inputVec := batch.ColVec(c.colIdx) + outputVec := batch.ColVec(c.outputIdx) + toType := outputVec.Type() + // Remove unused warnings. + _ = toType + c.allocator.PerformOperation( + []coldata.Vec{outputVec}, func() { + inputCol := inputVec.Bytes() + inputNulls := inputVec.Nulls() + outputCol := outputVec.Int64() + outputNulls := outputVec.Nulls() + if inputVec.MaybeHasNulls() { + outputNulls.Copy(inputNulls) + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int64 + + { + _s := string(v) + _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) + if err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + } + r = int64(_i) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int64 + + { + _s := string(v) + _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) + if err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + } + r = int64(_i) + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } else { + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int64 + + { + _s := string(v) + _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) + if err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + } + r = int64(_i) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r int64 + + { + _s := string(v) + _i, err := strconv.ParseInt(strings.TrimSpace(_s), 0, 64) + if err != nil { + colexecerror.ExpectedError(tree.MakeParseError(_s, toType, err)) + } + r = int64(_i) + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } + }, + ) + return batch +} + +type castStringIntervalOp struct { + castOpBase +} + +var _ colexecop.ResettableOperator = &castStringIntervalOp{} +var _ colexecop.ClosableOperator = &castStringIntervalOp{} + +func (c *castStringIntervalOp) Next() coldata.Batch { + batch := c.Input.Next() + n := batch.Length() + if n == 0 { + return coldata.ZeroBatch + } + sel := batch.Selection() + inputVec := batch.ColVec(c.colIdx) + outputVec := batch.ColVec(c.outputIdx) + toType := outputVec.Type() + // Remove unused warnings. + _ = toType + c.allocator.PerformOperation( + []coldata.Vec{outputVec}, func() { + inputCol := inputVec.Bytes() + inputNulls := inputVec.Nulls() + outputCol := outputVec.Interval() + outputNulls := outputVec.Nulls() + if inputVec.MaybeHasNulls() { + outputNulls.Copy(inputNulls) + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r duration.Duration + + _itm, err := toType.IntervalTypeMetadata() + if err != nil { + colexecerror.ExpectedError(err) + } + _intervalStyle := evalCtx.GetIntervalStyle() + r, err = tree.ParseIntervalWithTypeMetadata(_intervalStyle, string(v), _itm) + if err != nil { + colexecerror.ExpectedError(err) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r duration.Duration + + _itm, err := toType.IntervalTypeMetadata() + if err != nil { + colexecerror.ExpectedError(err) + } + _intervalStyle := evalCtx.GetIntervalStyle() + r, err = tree.ParseIntervalWithTypeMetadata(_intervalStyle, string(v), _itm) + if err != nil { + colexecerror.ExpectedError(err) + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } else { + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r duration.Duration + + _itm, err := toType.IntervalTypeMetadata() + if err != nil { + colexecerror.ExpectedError(err) + } + _intervalStyle := evalCtx.GetIntervalStyle() + r, err = tree.ParseIntervalWithTypeMetadata(_intervalStyle, string(v), _itm) + if err != nil { + colexecerror.ExpectedError(err) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + _ = outputCol.Get(n - 1) + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r duration.Duration + + _itm, err := toType.IntervalTypeMetadata() + if err != nil { + colexecerror.ExpectedError(err) + } + _intervalStyle := evalCtx.GetIntervalStyle() + r, err = tree.ParseIntervalWithTypeMetadata(_intervalStyle, string(v), _itm) + if err != nil { + colexecerror.ExpectedError(err) + } + + //gcassert:bce + outputCol.Set(tupleIdx, r) + } + } + } + } + }, + ) + return batch +} + +type castStringJsonbOp struct { + castOpBase +} + +var _ colexecop.ResettableOperator = &castStringJsonbOp{} +var _ colexecop.ClosableOperator = &castStringJsonbOp{} + +func (c *castStringJsonbOp) Next() coldata.Batch { + batch := c.Input.Next() + n := batch.Length() + if n == 0 { + return coldata.ZeroBatch + } + sel := batch.Selection() + inputVec := batch.ColVec(c.colIdx) + outputVec := batch.ColVec(c.outputIdx) + toType := outputVec.Type() + // Remove unused warnings. + _ = toType + c.allocator.PerformOperation( + []coldata.Vec{outputVec}, func() { + inputCol := inputVec.Bytes() + inputNulls := inputVec.Nulls() + outputCol := outputVec.JSON() + outputNulls := outputVec.Nulls() + if inputVec.MaybeHasNulls() { + outputNulls.Copy(inputNulls) + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r json.JSON + + var err error + r, err = json.ParseJSON(string(v)) + if err != nil { + colexecerror.ExpectedError(pgerror.Wrapf(err, pgcode.Syntax, "could not parse JSON")) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r json.JSON + + var err error + r, err = json.ParseJSON(string(v)) + if err != nil { + colexecerror.ExpectedError(pgerror.Wrapf(err, pgcode.Syntax, "could not parse JSON")) + } + + outputCol.Set(tupleIdx, r) + } + } + } + } else { + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r json.JSON + + var err error + r, err = json.ParseJSON(string(v)) + if err != nil { + colexecerror.ExpectedError(pgerror.Wrapf(err, pgcode.Syntax, "could not parse JSON")) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r json.JSON + + var err error + r, err = json.ParseJSON(string(v)) + if err != nil { + colexecerror.ExpectedError(pgerror.Wrapf(err, pgcode.Syntax, "could not parse JSON")) + } + + outputCol.Set(tupleIdx, r) + } + } + } + } + }, + ) + return batch +} + +type castStringStringOp struct { + castOpBase +} + +var _ colexecop.ResettableOperator = &castStringStringOp{} +var _ colexecop.ClosableOperator = &castStringStringOp{} + +func (c *castStringStringOp) Next() coldata.Batch { + batch := c.Input.Next() + n := batch.Length() + if n == 0 { + return coldata.ZeroBatch + } + sel := batch.Selection() + inputVec := batch.ColVec(c.colIdx) + outputVec := batch.ColVec(c.outputIdx) + toType := outputVec.Type() + // Remove unused warnings. + _ = toType + c.allocator.PerformOperation( + []coldata.Vec{outputVec}, func() { + inputCol := inputVec.Bytes() + inputNulls := inputVec.Nulls() + outputCol := outputVec.Bytes() + outputNulls := outputVec.Nulls() + if inputVec.MaybeHasNulls() { + outputNulls.Copy(inputNulls) + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r []byte + + r = v + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if true && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r []byte + + r = v + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + + outputCol.Set(tupleIdx, r) + } + } + } + } else { + if sel != nil { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = sel[i] + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r []byte + + r = v + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } + + outputCol.Set(tupleIdx, r) + } + } + } else { + { + var ( + evalCtx *eval.Context = c.evalCtx + buf *bytes.Buffer = &c.buf + ) + // Silence unused warnings. + _ = evalCtx + _ = buf + var tupleIdx int + for i := 0; i < n; i++ { + tupleIdx = i + if false && inputNulls.NullAt(tupleIdx) { + continue + } + v := inputCol.Get(tupleIdx) + var r []byte + + r = v + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -7968,14 +10881,14 @@ func (c *castStringIntOp) Next() coldata.Batch { return batch } -type castStringIntervalOp struct { +type castStringTimestampOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringIntervalOp{} -var _ colexecop.ClosableOperator = &castStringIntervalOp{} +var _ colexecop.ResettableOperator = &castStringTimestampOp{} +var _ colexecop.ClosableOperator = &castStringTimestampOp{} -func (c *castStringIntervalOp) Next() coldata.Batch { +func (c *castStringTimestampOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -7991,7 +10904,7 @@ func (c *castStringIntervalOp) Next() coldata.Batch { []coldata.Vec{outputVec}, func() { inputCol := inputVec.Bytes() inputNulls := inputVec.Nulls() - outputCol := outputVec.Interval() + outputCol := outputVec.Timestamp() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -8011,16 +10924,19 @@ func (c *castStringIntervalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r duration.Duration + var r time.Time - _itm, err := toType.IntervalTypeMetadata() + _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) + _now := evalCtx.GetRelativeParseTime() + _dateStyle := evalCtx.GetDateStyle() + _t, _, err := pgdate.ParseTimestampWithoutTimezone(_now, _dateStyle, string(v)) if err != nil { colexecerror.ExpectedError(err) } - _intervalStyle := evalCtx.GetIntervalStyle() - r, err = tree.ParseIntervalWithTypeMetadata(_intervalStyle, string(v), _itm) - if err != nil { - colexecerror.ExpectedError(err) + + r = _t.Round(_roundTo) + if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) } outputCol.Set(tupleIdx, r) @@ -8043,16 +10959,19 @@ func (c *castStringIntervalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r duration.Duration + var r time.Time - _itm, err := toType.IntervalTypeMetadata() + _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) + _now := evalCtx.GetRelativeParseTime() + _dateStyle := evalCtx.GetDateStyle() + _t, _, err := pgdate.ParseTimestampWithoutTimezone(_now, _dateStyle, string(v)) if err != nil { colexecerror.ExpectedError(err) } - _intervalStyle := evalCtx.GetIntervalStyle() - r, err = tree.ParseIntervalWithTypeMetadata(_intervalStyle, string(v), _itm) - if err != nil { - colexecerror.ExpectedError(err) + + r = _t.Round(_roundTo) + if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) } //gcassert:bce @@ -8077,16 +10996,19 @@ func (c *castStringIntervalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r duration.Duration + var r time.Time - _itm, err := toType.IntervalTypeMetadata() + _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) + _now := evalCtx.GetRelativeParseTime() + _dateStyle := evalCtx.GetDateStyle() + _t, _, err := pgdate.ParseTimestampWithoutTimezone(_now, _dateStyle, string(v)) if err != nil { colexecerror.ExpectedError(err) } - _intervalStyle := evalCtx.GetIntervalStyle() - r, err = tree.ParseIntervalWithTypeMetadata(_intervalStyle, string(v), _itm) - if err != nil { - colexecerror.ExpectedError(err) + + r = _t.Round(_roundTo) + if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) } outputCol.Set(tupleIdx, r) @@ -8109,16 +11031,19 @@ func (c *castStringIntervalOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r duration.Duration + var r time.Time - _itm, err := toType.IntervalTypeMetadata() + _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) + _now := evalCtx.GetRelativeParseTime() + _dateStyle := evalCtx.GetDateStyle() + _t, _, err := pgdate.ParseTimestampWithoutTimezone(_now, _dateStyle, string(v)) if err != nil { colexecerror.ExpectedError(err) } - _intervalStyle := evalCtx.GetIntervalStyle() - r, err = tree.ParseIntervalWithTypeMetadata(_intervalStyle, string(v), _itm) - if err != nil { - colexecerror.ExpectedError(err) + + r = _t.Round(_roundTo) + if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) } //gcassert:bce @@ -8132,14 +11057,14 @@ func (c *castStringIntervalOp) Next() coldata.Batch { return batch } -type castStringJsonbOp struct { +type castStringTimestamptzOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringJsonbOp{} -var _ colexecop.ClosableOperator = &castStringJsonbOp{} +var _ colexecop.ResettableOperator = &castStringTimestamptzOp{} +var _ colexecop.ClosableOperator = &castStringTimestamptzOp{} -func (c *castStringJsonbOp) Next() coldata.Batch { +func (c *castStringTimestamptzOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -8155,7 +11080,7 @@ func (c *castStringJsonbOp) Next() coldata.Batch { []coldata.Vec{outputVec}, func() { inputCol := inputVec.Bytes() inputNulls := inputVec.Nulls() - outputCol := outputVec.JSON() + outputCol := outputVec.Timestamp() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -8175,12 +11100,19 @@ func (c *castStringJsonbOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r json.JSON + var r time.Time - var err error - r, err = json.ParseJSON(string(v)) + _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) + _now := evalCtx.GetRelativeParseTime() + _dateStyle := evalCtx.GetDateStyle() + _t, _, err := pgdate.ParseTimestamp(_now, _dateStyle, string(v)) if err != nil { - colexecerror.ExpectedError(pgerror.Wrapf(err, pgcode.Syntax, "could not parse JSON")) + colexecerror.ExpectedError(err) + } + + r = _t.Round(_roundTo) + if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) } outputCol.Set(tupleIdx, r) @@ -8195,6 +11127,7 @@ func (c *castStringJsonbOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -8202,14 +11135,22 @@ func (c *castStringJsonbOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r json.JSON + var r time.Time - var err error - r, err = json.ParseJSON(string(v)) + _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) + _now := evalCtx.GetRelativeParseTime() + _dateStyle := evalCtx.GetDateStyle() + _t, _, err := pgdate.ParseTimestamp(_now, _dateStyle, string(v)) if err != nil { - colexecerror.ExpectedError(pgerror.Wrapf(err, pgcode.Syntax, "could not parse JSON")) + colexecerror.ExpectedError(err) + } + + r = _t.Round(_roundTo) + if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) } + //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -8231,12 +11172,19 @@ func (c *castStringJsonbOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r json.JSON + var r time.Time - var err error - r, err = json.ParseJSON(string(v)) + _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) + _now := evalCtx.GetRelativeParseTime() + _dateStyle := evalCtx.GetDateStyle() + _t, _, err := pgdate.ParseTimestamp(_now, _dateStyle, string(v)) if err != nil { - colexecerror.ExpectedError(pgerror.Wrapf(err, pgcode.Syntax, "could not parse JSON")) + colexecerror.ExpectedError(err) + } + + r = _t.Round(_roundTo) + if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) } outputCol.Set(tupleIdx, r) @@ -8251,6 +11199,7 @@ func (c *castStringJsonbOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf + _ = outputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i @@ -8258,14 +11207,22 @@ func (c *castStringJsonbOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r json.JSON + var r time.Time - var err error - r, err = json.ParseJSON(string(v)) + _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) + _now := evalCtx.GetRelativeParseTime() + _dateStyle := evalCtx.GetDateStyle() + _t, _, err := pgdate.ParseTimestamp(_now, _dateStyle, string(v)) if err != nil { - colexecerror.ExpectedError(pgerror.Wrapf(err, pgcode.Syntax, "could not parse JSON")) + colexecerror.ExpectedError(err) + } + + r = _t.Round(_roundTo) + if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) } + //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -8276,14 +11233,14 @@ func (c *castStringJsonbOp) Next() coldata.Batch { return batch } -type castStringStringOp struct { +type castStringUuidOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringStringOp{} -var _ colexecop.ClosableOperator = &castStringStringOp{} +var _ colexecop.ResettableOperator = &castStringUuidOp{} +var _ colexecop.ClosableOperator = &castStringUuidOp{} -func (c *castStringStringOp) Next() coldata.Batch { +func (c *castStringUuidOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -8321,31 +11278,11 @@ func (c *castStringStringOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r []byte - if toType.Oid() == oid.T_name { - // For Names we don't perform the truncation, and there is no need - // to do anything about the Oids since those are stored in the type. - r = v - } else { - // bpchar types truncate trailing whitespace. - if toType.Oid() == oid.T_bpchar { - v = bytes.TrimRight(v, " ") - } - // If the string type specifies a limit we truncate to that limit: - // 'hello'::CHAR(2) -> 'he' - // This is true of all the string type variants. - if toType.Width() > 0 { - // TODO(yuzefovich): figure out whether we can avoid converting - // to a string. - v = []byte(util.TruncateString(string(v), int(toType.Width()))) - } - if toType.Oid() == oid.T_char { - // "char" is supposed to truncate long values. - // TODO(yuzefovich): figure out whether we can avoid converting - // to a string. - v = []byte(util.TruncateString(string(v), 1)) - } - r = v + _uuid, err := uuid.FromString(string(v)) + if err != nil { + colexecerror.ExpectedError(err) } + r = _uuid.GetBytes() outputCol.Set(tupleIdx, r) } @@ -8368,31 +11305,11 @@ func (c *castStringStringOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r []byte - if toType.Oid() == oid.T_name { - // For Names we don't perform the truncation, and there is no need - // to do anything about the Oids since those are stored in the type. - r = v - } else { - // bpchar types truncate trailing whitespace. - if toType.Oid() == oid.T_bpchar { - v = bytes.TrimRight(v, " ") - } - // If the string type specifies a limit we truncate to that limit: - // 'hello'::CHAR(2) -> 'he' - // This is true of all the string type variants. - if toType.Width() > 0 { - // TODO(yuzefovich): figure out whether we can avoid converting - // to a string. - v = []byte(util.TruncateString(string(v), int(toType.Width()))) - } - if toType.Oid() == oid.T_char { - // "char" is supposed to truncate long values. - // TODO(yuzefovich): figure out whether we can avoid converting - // to a string. - v = []byte(util.TruncateString(string(v), 1)) - } - r = v + _uuid, err := uuid.FromString(string(v)) + if err != nil { + colexecerror.ExpectedError(err) } + r = _uuid.GetBytes() outputCol.Set(tupleIdx, r) } @@ -8417,31 +11334,11 @@ func (c *castStringStringOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r []byte - if toType.Oid() == oid.T_name { - // For Names we don't perform the truncation, and there is no need - // to do anything about the Oids since those are stored in the type. - r = v - } else { - // bpchar types truncate trailing whitespace. - if toType.Oid() == oid.T_bpchar { - v = bytes.TrimRight(v, " ") - } - // If the string type specifies a limit we truncate to that limit: - // 'hello'::CHAR(2) -> 'he' - // This is true of all the string type variants. - if toType.Width() > 0 { - // TODO(yuzefovich): figure out whether we can avoid converting - // to a string. - v = []byte(util.TruncateString(string(v), int(toType.Width()))) - } - if toType.Oid() == oid.T_char { - // "char" is supposed to truncate long values. - // TODO(yuzefovich): figure out whether we can avoid converting - // to a string. - v = []byte(util.TruncateString(string(v), 1)) - } - r = v + _uuid, err := uuid.FromString(string(v)) + if err != nil { + colexecerror.ExpectedError(err) } + r = _uuid.GetBytes() outputCol.Set(tupleIdx, r) } @@ -8464,31 +11361,11 @@ func (c *castStringStringOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r []byte - if toType.Oid() == oid.T_name { - // For Names we don't perform the truncation, and there is no need - // to do anything about the Oids since those are stored in the type. - r = v - } else { - // bpchar types truncate trailing whitespace. - if toType.Oid() == oid.T_bpchar { - v = bytes.TrimRight(v, " ") - } - // If the string type specifies a limit we truncate to that limit: - // 'hello'::CHAR(2) -> 'he' - // This is true of all the string type variants. - if toType.Width() > 0 { - // TODO(yuzefovich): figure out whether we can avoid converting - // to a string. - v = []byte(util.TruncateString(string(v), int(toType.Width()))) - } - if toType.Oid() == oid.T_char { - // "char" is supposed to truncate long values. - // TODO(yuzefovich): figure out whether we can avoid converting - // to a string. - v = []byte(util.TruncateString(string(v), 1)) - } - r = v + _uuid, err := uuid.FromString(string(v)) + if err != nil { + colexecerror.ExpectedError(err) } + r = _uuid.GetBytes() outputCol.Set(tupleIdx, r) } @@ -8500,14 +11377,14 @@ func (c *castStringStringOp) Next() coldata.Batch { return batch } -type castStringTimestampOp struct { +type castTimestampStringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringTimestampOp{} -var _ colexecop.ClosableOperator = &castStringTimestampOp{} +var _ colexecop.ResettableOperator = &castTimestampStringOp{} +var _ colexecop.ClosableOperator = &castTimestampStringOp{} -func (c *castStringTimestampOp) Next() coldata.Batch { +func (c *castTimestampStringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -8521,9 +11398,9 @@ func (c *castStringTimestampOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Bytes() + inputCol := inputVec.Timestamp() inputNulls := inputVec.Nulls() - outputCol := outputVec.Timestamp() + outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -8543,18 +11420,29 @@ func (c *castStringTimestampOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r time.Time + var r []byte - _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) - _now := evalCtx.GetRelativeParseTime() - _dateStyle := evalCtx.GetDateStyle() - _t, _, err := pgdate.ParseTimestampWithoutTimezone(_now, _dateStyle, string(v)) - if err != nil { - colexecerror.ExpectedError(err) + r = []byte(tree.FormatTimestamp(v)) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } } - r = _t.Round(_roundTo) - if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { - colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -8569,29 +11457,40 @@ func (c *castStringTimestampOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = outputCol.Get(n - 1) + _ = inputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if true && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r time.Time - - _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) - _now := evalCtx.GetRelativeParseTime() - _dateStyle := evalCtx.GetDateStyle() - _t, _, err := pgdate.ParseTimestampWithoutTimezone(_now, _dateStyle, string(v)) - if err != nil { - colexecerror.ExpectedError(err) + var r []byte + + r = []byte(tree.FormatTimestamp(v)) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } } - r = _t.Round(_roundTo) - if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { - colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -8613,18 +11512,29 @@ func (c *castStringTimestampOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r time.Time + var r []byte - _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) - _now := evalCtx.GetRelativeParseTime() - _dateStyle := evalCtx.GetDateStyle() - _t, _, err := pgdate.ParseTimestampWithoutTimezone(_now, _dateStyle, string(v)) - if err != nil { - colexecerror.ExpectedError(err) + r = []byte(tree.FormatTimestamp(v)) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } } - r = _t.Round(_roundTo) - if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { - colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -8639,29 +11549,40 @@ func (c *castStringTimestampOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = outputCol.Get(n - 1) + _ = inputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if false && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r time.Time + var r []byte - _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) - _now := evalCtx.GetRelativeParseTime() - _dateStyle := evalCtx.GetDateStyle() - _t, _, err := pgdate.ParseTimestampWithoutTimezone(_now, _dateStyle, string(v)) - if err != nil { - colexecerror.ExpectedError(err) + r = []byte(tree.FormatTimestamp(v)) + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } } - r = _t.Round(_roundTo) - if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { - colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -8672,14 +11593,14 @@ func (c *castStringTimestampOp) Next() coldata.Batch { return batch } -type castStringTimestamptzOp struct { +type castTimestamptzStringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringTimestamptzOp{} -var _ colexecop.ClosableOperator = &castStringTimestamptzOp{} +var _ colexecop.ResettableOperator = &castTimestamptzStringOp{} +var _ colexecop.ClosableOperator = &castTimestamptzStringOp{} -func (c *castStringTimestamptzOp) Next() coldata.Batch { +func (c *castTimestamptzStringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -8693,9 +11614,9 @@ func (c *castStringTimestamptzOp) Next() coldata.Batch { _ = toType c.allocator.PerformOperation( []coldata.Vec{outputVec}, func() { - inputCol := inputVec.Bytes() + inputCol := inputVec.Timestamp() inputNulls := inputVec.Nulls() - outputCol := outputVec.Timestamp() + outputCol := outputVec.Bytes() outputNulls := outputVec.Nulls() if inputVec.MaybeHasNulls() { outputNulls.Copy(inputNulls) @@ -8715,18 +11636,40 @@ func (c *castStringTimestamptzOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r time.Time + var r []byte - _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) - _now := evalCtx.GetRelativeParseTime() - _dateStyle := evalCtx.GetDateStyle() - _t, _, err := pgdate.ParseTimestamp(_now, _dateStyle, string(v)) - if err != nil { - colexecerror.ExpectedError(err) + // Convert to context timezone for correct display. + _t := v.In(evalCtx.GetLocation()) + + _t = _t.Round(time.Microsecond) + if _t.After(tree.MaxSupportedTime) || _t.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(_t)) } - r = _t.Round(_roundTo) - if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { - colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) + + buf.Reset() + tree.FormatTimestampTZ(_t, buf) + r = []byte(buf.String()) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -8741,29 +11684,51 @@ func (c *castStringTimestamptzOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = outputCol.Get(n - 1) + _ = inputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if true && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r time.Time + var r []byte - _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) - _now := evalCtx.GetRelativeParseTime() - _dateStyle := evalCtx.GetDateStyle() - _t, _, err := pgdate.ParseTimestamp(_now, _dateStyle, string(v)) - if err != nil { - colexecerror.ExpectedError(err) + // Convert to context timezone for correct display. + _t := v.In(evalCtx.GetLocation()) + + _t = _t.Round(time.Microsecond) + if _t.After(tree.MaxSupportedTime) || _t.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(_t)) } - r = _t.Round(_roundTo) - if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { - colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) + + buf.Reset() + tree.FormatTimestampTZ(_t, buf) + r = []byte(buf.String()) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -8785,18 +11750,40 @@ func (c *castStringTimestamptzOp) Next() coldata.Batch { continue } v := inputCol.Get(tupleIdx) - var r time.Time + var r []byte - _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) - _now := evalCtx.GetRelativeParseTime() - _dateStyle := evalCtx.GetDateStyle() - _t, _, err := pgdate.ParseTimestamp(_now, _dateStyle, string(v)) - if err != nil { - colexecerror.ExpectedError(err) + // Convert to context timezone for correct display. + _t := v.In(evalCtx.GetLocation()) + + _t = _t.Round(time.Microsecond) + if _t.After(tree.MaxSupportedTime) || _t.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(_t)) } - r = _t.Round(_roundTo) - if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { - colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) + + buf.Reset() + tree.FormatTimestampTZ(_t, buf) + r = []byte(buf.String()) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } outputCol.Set(tupleIdx, r) @@ -8811,29 +11798,51 @@ func (c *castStringTimestamptzOp) Next() coldata.Batch { // Silence unused warnings. _ = evalCtx _ = buf - _ = outputCol.Get(n - 1) + _ = inputCol.Get(n - 1) var tupleIdx int for i := 0; i < n; i++ { tupleIdx = i if false && inputNulls.NullAt(tupleIdx) { continue } + //gcassert:bce v := inputCol.Get(tupleIdx) - var r time.Time + var r []byte - _roundTo := tree.TimeFamilyPrecisionToRoundDuration(toType.Precision()) - _now := evalCtx.GetRelativeParseTime() - _dateStyle := evalCtx.GetDateStyle() - _t, _, err := pgdate.ParseTimestamp(_now, _dateStyle, string(v)) - if err != nil { - colexecerror.ExpectedError(err) + // Convert to context timezone for correct display. + _t := v.In(evalCtx.GetLocation()) + + _t = _t.Round(time.Microsecond) + if _t.After(tree.MaxSupportedTime) || _t.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(_t)) } - r = _t.Round(_roundTo) - if r.After(tree.MaxSupportedTime) || r.Before(tree.MinSupportedTime) { - colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(r)) + + buf.Reset() + tree.FormatTimestampTZ(_t, buf) + r = []byte(buf.String()) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) } - //gcassert:bce outputCol.Set(tupleIdx, r) } } @@ -8844,14 +11853,14 @@ func (c *castStringTimestamptzOp) Next() coldata.Batch { return batch } -type castStringUuidOp struct { +type castUuidStringOp struct { castOpBase } -var _ colexecop.ResettableOperator = &castStringUuidOp{} -var _ colexecop.ClosableOperator = &castStringUuidOp{} +var _ colexecop.ResettableOperator = &castUuidStringOp{} +var _ colexecop.ClosableOperator = &castUuidStringOp{} -func (c *castStringUuidOp) Next() coldata.Batch { +func (c *castUuidStringOp) Next() coldata.Batch { batch := c.Input.Next() n := batch.Length() if n == 0 { @@ -8889,11 +11898,33 @@ func (c *castStringUuidOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r []byte - _uuid, err := uuid.FromString(string(v)) + _uuid, err := uuid.FromBytes(v) if err != nil { colexecerror.ExpectedError(err) } - r = _uuid.GetBytes() + r = []byte(_uuid.String()) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } outputCol.Set(tupleIdx, r) } @@ -8916,11 +11947,33 @@ func (c *castStringUuidOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r []byte - _uuid, err := uuid.FromString(string(v)) + _uuid, err := uuid.FromBytes(v) if err != nil { colexecerror.ExpectedError(err) } - r = _uuid.GetBytes() + r = []byte(_uuid.String()) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } outputCol.Set(tupleIdx, r) } @@ -8945,11 +11998,33 @@ func (c *castStringUuidOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r []byte - _uuid, err := uuid.FromString(string(v)) + _uuid, err := uuid.FromBytes(v) if err != nil { colexecerror.ExpectedError(err) } - r = _uuid.GetBytes() + r = []byte(_uuid.String()) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } outputCol.Set(tupleIdx, r) } @@ -8972,11 +12047,33 @@ func (c *castStringUuidOp) Next() coldata.Batch { v := inputCol.Get(tupleIdx) var r []byte - _uuid, err := uuid.FromString(string(v)) + _uuid, err := uuid.FromBytes(v) if err != nil { colexecerror.ExpectedError(err) } - r = _uuid.GetBytes() + r = []byte(_uuid.String()) + + if toType.Oid() != oid.T_name { + // bpchar types truncate trailing whitespace. + if toType.Oid() == oid.T_bpchar { + r = bytes.TrimRight(r, " ") + } + // If the string type specifies a limit we truncate to that limit: + // 'hello'::CHAR(2) -> 'he' + // This is true of all the string type variants. + if toType.Width() > 0 { + r = []byte(util.TruncateString(string(r), int(toType.Width()))) + } + if toType.Oid() == oid.T_char { + // "char" is supposed to truncate long values. + r = []byte(util.TruncateString(string(r), 1)) + } + } + if toType.Width() > 0 && utf8.RuneCountInString(string(r)) > int(toType.Width()) { + _typeString := toType.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type "+_typeString)) + } outputCol.Set(tupleIdx, r) } diff --git a/pkg/sql/colexec/colexecbase/cast_test.go b/pkg/sql/colexec/colexecbase/cast_test.go index 1c13cc734393..412f9dbbe655 100644 --- a/pkg/sql/colexec/colexecbase/cast_test.go +++ b/pkg/sql/colexec/colexecbase/cast_test.go @@ -61,7 +61,7 @@ func TestRandomizedCast(t *testing.T) { } } } - const numTypePairs = 5 + var numTypePairs = rng.Intn(10) + 1 numRows := 1 + rng.Intn(coldata.BatchSize()) + rng.Intn(3)*coldata.BatchSize() log.Infof(ctx, "num rows = %d", numRows) for run := 0; run < numTypePairs; run++ { diff --git a/pkg/sql/colexec/execgen/cmd/execgen/avg_agg_gen.go b/pkg/sql/colexec/execgen/cmd/execgen/avg_agg_gen.go index 8b6d1fe5a25a..a5ccf35d4179 100644 --- a/pkg/sql/colexec/execgen/cmd/execgen/avg_agg_gen.go +++ b/pkg/sql/colexec/execgen/cmd/execgen/avg_agg_gen.go @@ -145,7 +145,7 @@ func genAvgAgg(inputFileContents string, wr io.Writer) error { // canonical representatives, so we can operate with their type family // directly. for _, inputTypeFamily := range []types.Family{types.IntFamily, types.DecimalFamily, types.FloatFamily, types.IntervalFamily} { - tmplInfo := avgAggTypeTmplInfo{TypeFamily: toString(inputTypeFamily)} + tmplInfo := avgAggTypeTmplInfo{TypeFamily: familyToString(inputTypeFamily)} for _, inputTypeWidth := range supportedWidthsByCanonicalTypeFamily[inputTypeFamily] { // Note that we don't use execinfrapb.GetAggregateInfo because we don't // want to bring in a dependency on that package to reduce the burden diff --git a/pkg/sql/colexec/execgen/cmd/execgen/cast_gen_util.go b/pkg/sql/colexec/execgen/cmd/execgen/cast_gen_util.go index 66fb6bf5c4a8..e247eef28e03 100644 --- a/pkg/sql/colexec/execgen/cmd/execgen/cast_gen_util.go +++ b/pkg/sql/colexec/execgen/cmd/execgen/cast_gen_util.go @@ -41,7 +41,9 @@ var nativeCastInfos = []supportedNativeCastInfo{ {types.Bool, types.Int2, boolToIntOrFloat}, {types.Bool, types.Int4, boolToIntOrFloat}, {types.Bool, types.Int, boolToIntOrFloat}, + {types.Bool, types.String, boolToString}, + {types.Bytes, types.String, bytesToString}, {types.Bytes, types.Uuid, bytesToUUID}, {types.Date, types.Decimal, intToDecimal}, @@ -53,6 +55,7 @@ var nativeCastInfos = []supportedNativeCastInfo{ {types.Date, types.Int2, getIntToIntCastFunc(64 /* fromWidth */, 16 /* toWidth */)}, {types.Date, types.Int4, getIntToIntCastFunc(64 /* fromWidth */, 32 /* toWidth */)}, {types.Date, types.Int, getIntToIntCastFunc(64 /* fromWidth */, anyWidth)}, + {types.Date, types.String, dateToString}, {types.Decimal, types.Bool, decimalToBool}, {types.Decimal, types.Decimal, decimalToDecimal}, @@ -60,28 +63,35 @@ var nativeCastInfos = []supportedNativeCastInfo{ {types.Decimal, types.Int2, getDecimalToIntCastFunc(16)}, {types.Decimal, types.Int4, getDecimalToIntCastFunc(32)}, {types.Decimal, types.Int, getDecimalToIntCastFunc(anyWidth)}, + {types.Decimal, types.String, decimalToString}, {types.Float, types.Bool, numToBool}, {types.Float, types.Decimal, floatToDecimal}, {types.Float, types.Int2, floatToInt(16, 64 /* floatWidth */)}, {types.Float, types.Int4, floatToInt(32, 64 /* floatWidth */)}, {types.Float, types.Int, floatToInt(anyWidth, 64 /* floatWidth */)}, + {types.Float, types.String, floatToString}, {types.Int2, types.Bool, numToBool}, {types.Int2, types.Decimal, intToDecimal}, {types.Int2, types.Float, intToFloat}, {types.Int2, types.Int4, getIntToIntCastFunc(16, 32)}, {types.Int2, types.Int, getIntToIntCastFunc(16, anyWidth)}, + {types.Int2, types.String, intToString}, {types.Int4, types.Bool, numToBool}, {types.Int4, types.Decimal, intToDecimal}, {types.Int4, types.Float, intToFloat}, {types.Int4, types.Int2, getIntToIntCastFunc(32, 16)}, {types.Int4, types.Int, getIntToIntCastFunc(32, anyWidth)}, + {types.Int4, types.String, intToString}, {types.Int, types.Bool, numToBool}, {types.Int, types.Decimal, intToDecimal}, {types.Int, types.Float, intToFloat}, {types.Int, types.Int2, getIntToIntCastFunc(anyWidth, 16)}, {types.Int, types.Int4, getIntToIntCastFunc(anyWidth, 32)}, + {types.Int, types.String, intToString}, + + {types.Interval, types.String, intervalToString}, {types.Jsonb, types.String, jsonToString}, @@ -99,6 +109,12 @@ var nativeCastInfos = []supportedNativeCastInfo{ {types.String, types.Timestamp, getStringToTimestampCastFunc(true /* withoutTimezone */)}, {types.String, types.TimestampTZ, getStringToTimestampCastFunc(false /* withoutTimezone */)}, {types.String, types.Uuid, stringToUUID}, + + {types.Timestamp, types.String, timestampToString}, + + {types.TimestampTZ, types.String, timestampTZToString}, + + {types.Uuid, types.String, uuidToString}, } type supportedNativeCastInfo struct { @@ -117,6 +133,18 @@ func boolToIntOrFloat(to, from, _, _, _ string) string { return fmt.Sprintf(convStr, to, from) } +func boolToString(to, from, _, toType, _ string) string { + return toString(fmt.Sprintf("%s = []byte(strconv.FormatBool(%s))", to, from), to, toType) +} + +func bytesToString(to, from, evalCtx, toType, _ string) string { + convStr := ` + _format := %[3]s.SessionData().DataConversionConfig.BytesEncodeFormat + %[1]s = []byte(lex.EncodeByteArrayToRawBytes(string(%[2]s), _format, false /* skipHexPrefix */)) +` + return toString(fmt.Sprintf(convStr, to, from, evalCtx), to, toType) +} + func bytesToUUID(to, from, _, _, _ string) string { convStr := ` _uuid, err := uuid.FromBytes(%[2]s) @@ -128,6 +156,16 @@ func bytesToUUID(to, from, _, _, _ string) string { return fmt.Sprintf(convStr, to, from) } +func dateToString(to, from, _, toType, buf string) string { + convStr := ` + _date := pgdate.MakeCompatibleDateFromDisk(%[2]s) + %[3]s.Reset() + _date.Format(%[3]s) + %[1]s = []byte(%[3]s.String()) + ` + return toString(fmt.Sprintf(convStr, to, from, buf), to, toType) +} + func decimalToBool(to, from, _, _, _ string) string { return fmt.Sprintf("%[1]s = %[2]s.Sign() != 0", to, from) } @@ -191,6 +229,10 @@ func getDecimalToIntCastFunc(toIntWidth int32) castFunc { } } +func decimalToString(to, from, _, toType, _ string) string { + return toString(fmt.Sprintf("%s = []byte(%s.String())", to, from), to, toType) +} + // toDecimal returns the templated code that performs the cast to a decimal. It // first will execute whatever is passed in 'conv' (the main conversion) and // then will perform the rounding of 'to' variable according to 'toType'. @@ -235,6 +277,14 @@ func floatToInt(intWidth, floatWidth int32) castFunc { } } +func floatToString(to, from, evalCtx, toType, _ string) string { + convStr := ` + dcc := %[3]s.SessionData().DataConversionConfig + %[1]s = tree.PgwireFormatFloat(nil /* buf */, %[2]s, dcc, types.Float) +` + return toString(fmt.Sprintf(convStr, to, from, evalCtx), to, toType) +} + func intToDecimal(to, from, _, toType, _ string) string { conv := ` %[1]s.SetInt64(int64(%[2]s)) @@ -286,20 +336,37 @@ func getIntToIntCastFunc(fromWidth, toWidth int32) castFunc { } } -func jsonToString(to, from, _, toType, _ string) string { +func intToString(to, from, _, toType, _ string) string { convStr := ` - _string := %[2]s.String() - switch %[3]s.Oid() { - case oid.T_char: - // "char" is supposed to truncate long values. - _string = util.TruncateString(_string, 1) - case oid.T_bpchar: - // bpchar types truncate trailing whitespace. - _string = strings.TrimRight(_string, " ") + if %[3]s.Oid() == oid.T_char { + // int to "char" casts just return the corresponding ASCII byte. + if %[2]s > math.MaxInt8 || %[2]s < math.MinInt8 { + colexecerror.ExpectedError(tree.ErrCharOutOfRange) + } + if %[2]s == 0 { + %[1]s = []byte{} + } else { + %[1]s = []byte{byte(%[2]s)} + } + } else { + %[1]s = []byte(strconv.FormatInt(int64(%[2]s), 10)) } - %[1]s = []byte(_string) - ` - return fmt.Sprintf(convStr, to, from, toType) +` + return toString(fmt.Sprintf(convStr, to, from, toType), to, toType) +} + +func intervalToString(to, from, evalCtx, toType, buf string) string { + convStr := ` + dcc := %[3]s.SessionData().DataConversionConfig + %[4]s.Reset() + %[2]s.FormatWithStyle(%[4]s, dcc.IntervalStyle) + %[1]s = []byte(%[4]s.String()) +` + return toString(fmt.Sprintf(convStr, to, from, evalCtx, buf), to, toType) +} + +func jsonToString(to, from, _, toType, _ string) string { + return toString(fmt.Sprintf("%s = []byte(%s.String())", to, from), to, toType) } func stringToBool(to, from, _, _, _ string) string { @@ -427,13 +494,19 @@ func stringToJSON(to, from, _, _, _ string) string { return fmt.Sprintf(convStr, to, from) } -func stringToString(to, from, _, toType, _ string) string { +// TODO(yuzefovich): figure out whether we can avoid converting to a string in +// the template below. + +// toString returns the templated code that performs the cast to a string. It +// first will execute whatever is passed in 'conv' (the main conversion) and +// then will perform the truncation of 'to' variable according to 'toType'. +func toString(conv, to, toType string) string { + // The logic here is a combination of the relevant pieces from + // eval.performCastWithoutPrecisionTruncation as well as from + // tree.AdjustValueToType. convStr := ` - if %[3]s.Oid() == oid.T_name { - // For Names we don't perform the truncation, and there is no need - // to do anything about the Oids since those are stored in the type. - %[1]s = %[2]s - } else { + %[1]s + if %[3]s.Oid() != oid.T_name { // bpchar types truncate trailing whitespace. if %[3]s.Oid() == oid.T_bpchar { %[2]s = bytes.TrimRight(%[2]s, " ") @@ -442,20 +515,37 @@ func stringToString(to, from, _, toType, _ string) string { // 'hello'::CHAR(2) -> 'he' // This is true of all the string type variants. if %[3]s.Width() > 0 { - // TODO(yuzefovich): figure out whether we can avoid converting - // to a string. %[2]s = []byte(util.TruncateString(string(%[2]s), int(%[3]s.Width()))) } if %[3]s.Oid() == oid.T_char { // "char" is supposed to truncate long values. - // TODO(yuzefovich): figure out whether we can avoid converting - // to a string. %[2]s = []byte(util.TruncateString(string(%[2]s), 1)) } - %[1]s = %[2]s + } + if %[3]s.Width() > 0 && utf8.RuneCountInString(string(%[2]s)) > int(%[3]s.Width()) { + _typeString := %[3]s.SQLString() + colexecerror.ExpectedError( + pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type " + _typeString, + )) } ` - return fmt.Sprintf(convStr, to, from, toType) + return fmt.Sprintf(convStr, conv, to, toType) +} + +func stringToString(to, from, _, toType, _ string) string { + return toString(fmt.Sprintf("%s = %s", to, from), to, toType) +} + +// roundTimestamp is a template that takes a timestamp specified by 'from', +// rounds it according to 'precision', and assigns the result to 'to' timestamp. +func roundTimestamp(to, from, precision string) string { + roundStr := ` + %[1]s = %[2]s.Round(%[3]s) + if %[1]s.After(tree.MaxSupportedTime) || %[1]s.Before(tree.MinSupportedTime) { + colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(%[1]s)) + } +` + return fmt.Sprintf(roundStr, to, from, precision) } func getStringToTimestampCastFunc(withoutTimezone bool) castFunc { @@ -475,12 +565,10 @@ func getStringToTimestampCastFunc(withoutTimezone bool) castFunc { if err != nil { colexecerror.ExpectedError(err) } - %[1]s = _t.Round(_roundTo) - if %[1]s.After(tree.MaxSupportedTime) || %[1]s.Before(tree.MinSupportedTime) { - colexecerror.ExpectedError(tree.NewTimestampExceedsBoundsError(%[1]s)) - } + %[1]s ` - return fmt.Sprintf(convStr, to, from, evalCtx, toType, parseTimestampKind) + roundAndAssign := roundTimestamp(to, "_t", "_roundTo") + return fmt.Sprintf(convStr, roundAndAssign, from, evalCtx, toType, parseTimestampKind) } } @@ -495,6 +583,34 @@ func stringToUUID(to, from, _, _, _ string) string { return fmt.Sprintf(convStr, to, from) } +func timestampToString(to, from, _, toType, _ string) string { + return toString(fmt.Sprintf("%s = []byte(tree.FormatTimestamp(%s))", to, from), to, toType) +} + +func timestampTZToString(to, from, evalCtx, toType, buf string) string { + convStr := ` + // Convert to context timezone for correct display. + _t := %[2]s.In(%[3]s.GetLocation()) + %[5]s + %[4]s.Reset() + tree.FormatTimestampTZ(_t, %[4]s) + %[1]s = []byte(%[4]s.String()) +` + roundT := roundTimestamp("_t", "_t", "time.Microsecond") + return toString(fmt.Sprintf(convStr, to, from, evalCtx, buf, roundT), to, toType) +} + +func uuidToString(to, from, _, toType, _ string) string { + convStr := ` + _uuid, err := uuid.FromBytes(%[2]s) + if err != nil { + colexecerror.ExpectedError(err) + } + %[1]s = []byte(_uuid.String()) + ` + return toString(fmt.Sprintf(convStr, to, from), to, toType) +} + // getDatumToNativeCastFunc returns a castFunc for casting datum-backed value // to a value of the specified physical representation (i.e. to natively // supported type). The returned castFunc assumes that there is a converter diff --git a/pkg/sql/colexec/execgen/cmd/execgen/overloads_base.go b/pkg/sql/colexec/execgen/cmd/execgen/overloads_base.go index 126ccbdf9dd1..74438060106b 100644 --- a/pkg/sql/colexec/execgen/cmd/execgen/overloads_base.go +++ b/pkg/sql/colexec/execgen/cmd/execgen/overloads_base.go @@ -123,7 +123,7 @@ func (b *overloadBase) String() string { return fmt.Sprintf("%s: %s", b.Name, b.OpStr) } -func toString(family types.Family) string { +func familyToString(family types.Family) string { switch family { case typeconv.DatumVecCanonicalTypeFamily: return "typeconv.DatumVecCanonicalTypeFamily" @@ -140,7 +140,7 @@ type argTypeOverloadBase struct { func newArgTypeOverloadBase(canonicalTypeFamily types.Family) *argTypeOverloadBase { return &argTypeOverloadBase{ CanonicalTypeFamily: canonicalTypeFamily, - CanonicalTypeFamilyStr: toString(canonicalTypeFamily), + CanonicalTypeFamilyStr: familyToString(canonicalTypeFamily), } } diff --git a/pkg/sql/colexec/execgen/cmd/execgen/overloads_gen_util.go b/pkg/sql/colexec/execgen/cmd/execgen/overloads_gen_util.go index bfe96534ab77..8ba86057b752 100644 --- a/pkg/sql/colexec/execgen/cmd/execgen/overloads_gen_util.go +++ b/pkg/sql/colexec/execgen/cmd/execgen/overloads_gen_util.go @@ -49,13 +49,13 @@ func populateTwoArgsOverloads( if !found { colexecerror.InternalError(errors.AssertionFailedf("didn't find supported widths for %s", leftFamily)) } - leftFamilyStr := toString(leftFamily) + leftFamilyStr := familyToString(leftFamily) for _, rightFamily := range combinableCanonicalTypeFamilies[leftFamily] { rightWidths, found := supportedWidthsByCanonicalTypeFamily[rightFamily] if !found { colexecerror.InternalError(errors.AssertionFailedf("didn't find supported widths for %s", rightFamily)) } - rightFamilyStr := toString(rightFamily) + rightFamilyStr := familyToString(rightFamily) for _, leftWidth := range leftWidths { for _, rightWidth := range rightWidths { customizer, ok := customizers[typePair{leftFamily, leftWidth, rightFamily, rightWidth}] diff --git a/pkg/sql/colexec/execgen/cmd/execgen/range_offset_handler_gen.go b/pkg/sql/colexec/execgen/cmd/execgen/range_offset_handler_gen.go index 4c3bb9932452..feaad76bebf4 100644 --- a/pkg/sql/colexec/execgen/cmd/execgen/range_offset_handler_gen.go +++ b/pkg/sql/colexec/execgen/cmd/execgen/range_offset_handler_gen.go @@ -76,7 +76,7 @@ func rangeOffsetHandlerGenerator(inputFileContents string, wr io.Writer) error { ordColDirInfo := windowFrameOrdDirInfo{IsOrdColAsc: isOrdColAsc} for _, typeFamily := range rangeOrderColTypeFamilies { canonicalTypeFamily := typeconv.TypeFamilyToCanonicalTypeFamily(typeFamily) - typeFamilyStr := toString(typeFamily) + typeFamilyStr := familyToString(typeFamily) typeFamilyInfo := windowFrameOrderTypeFamilyInfo{ TypeFamily: typeFamilyStr, } diff --git a/pkg/sql/colexec/execgen/cmd/execgen/span_encoder_gen.go b/pkg/sql/colexec/execgen/cmd/execgen/span_encoder_gen.go index b0f7e238b384..bd390c673dd3 100644 --- a/pkg/sql/colexec/execgen/cmd/execgen/span_encoder_gen.go +++ b/pkg/sql/colexec/execgen/cmd/execgen/span_encoder_gen.go @@ -48,7 +48,7 @@ func genSpanEncoder(inputFileContents string, wr io.Writer) error { // We are currently unable to encode JSON as a table key. continue } - familyInfo := spanEncoderTypeFamilyInfo{TypeFamily: toString(family)} + familyInfo := spanEncoderTypeFamilyInfo{TypeFamily: familyToString(family)} for _, width := range supportedWidthsByCanonicalTypeFamily[family] { overload := spanEncoderTmplInfo{ Asc: asc, diff --git a/pkg/sql/colexec/execgen/cmd/execgen/sum_agg_gen.go b/pkg/sql/colexec/execgen/cmd/execgen/sum_agg_gen.go index 3b7583e56f60..64cede0e6950 100644 --- a/pkg/sql/colexec/execgen/cmd/execgen/sum_agg_gen.go +++ b/pkg/sql/colexec/execgen/cmd/execgen/sum_agg_gen.go @@ -161,7 +161,7 @@ func genSumAgg(inputFileContents string, wr io.Writer, isSumInt bool) error { var tmplInfos []sumAggTypeTmplInfo for _, inputTypeFamily := range supportedTypeFamilies { tmplInfo := sumAggTypeTmplInfo{ - TypeFamily: toString(inputTypeFamily), + TypeFamily: familyToString(inputTypeFamily), } for _, inputTypeWidth := range supportedWidthsByCanonicalTypeFamily[inputTypeFamily] { // Note that we don't use execinfrapb.GetAggregateInfo because we don't diff --git a/pkg/sql/sem/eval/cast.go b/pkg/sql/sem/eval/cast.go index 7fedc6246598..094e15780cc3 100644 --- a/pkg/sql/sem/eval/cast.go +++ b/pkg/sql/sem/eval/cast.go @@ -399,7 +399,7 @@ func performCastWithoutPrecisionTruncation( s = string(b) case *tree.DInt: if typ.Oid() == oid.T_char { - // int to "char" casts just return the correspondong ASCII byte. + // int to "char" casts just return the corresponding ASCII byte. if *t > math.MaxInt8 || *t < math.MinInt8 { return nil, tree.ErrCharOutOfRange } else if *t == 0 { diff --git a/pkg/sql/sem/tree/datum.go b/pkg/sql/sem/tree/datum.go index 60cd0a61800c..2fa33c4d758e 100644 --- a/pkg/sql/sem/tree/datum.go +++ b/pkg/sql/sem/tree/datum.go @@ -2807,6 +2807,11 @@ func (d *DTimestamp) Max(ctx CompareContext) (Datum, bool) { // AmbiguousFormat implements the Datum interface. func (*DTimestamp) AmbiguousFormat() bool { return true } +// FormatTimestamp outputs a timestamp in the UTC timezone. +func FormatTimestamp(t time.Time) string { + return t.UTC().Format(timestampOutputFormat) +} + // Format implements the NodeFormatter interface. func (d *DTimestamp) Format(ctx *FmtCtx) { f := ctx.flags @@ -2814,7 +2819,7 @@ func (d *DTimestamp) Format(ctx *FmtCtx) { if !bareStrings { ctx.WriteByte('\'') } - ctx.WriteString(d.UTC().Format(timestampOutputFormat)) + ctx.WriteString(FormatTimestamp(d.Time)) if !bareStrings { ctx.WriteByte('\'') } @@ -2974,15 +2979,11 @@ func (d *DTimestampTZ) Max(ctx CompareContext) (Datum, bool) { // AmbiguousFormat implements the Datum interface. func (*DTimestampTZ) AmbiguousFormat() bool { return true } -// Format implements the NodeFormatter interface. -func (d *DTimestampTZ) Format(ctx *FmtCtx) { - f := ctx.flags - bareStrings := f.HasFlags(FmtFlags(lexbase.EncBareStrings)) - if !bareStrings { - ctx.WriteByte('\'') - } - ctx.WriteString(d.Time.Format(timestampTZOutputFormat)) - _, offsetSecs := d.Time.Zone() +// FormatTimestampTZ formats the given timestamp with timezone into the provided +// buffer. +func FormatTimestampTZ(t time.Time, buf *bytes.Buffer) { + buf.WriteString(t.Format(timestampTZOutputFormat)) + _, offsetSecs := t.Zone() // Only output remaining seconds offsets if it is available. // This is to maintain backward compatibility with older CRDB versions, // where we only output HH:MM. @@ -2990,9 +2991,19 @@ func (d *DTimestampTZ) Format(ctx *FmtCtx) { if secondOffset < 0 { secondOffset = 60 + secondOffset } - ctx.WriteByte(':') - ctx.WriteString(fmt.Sprintf("%02d", secondOffset)) + buf.WriteByte(':') + buf.WriteString(fmt.Sprintf("%02d", secondOffset)) + } +} + +// Format implements the NodeFormatter interface. +func (d *DTimestampTZ) Format(ctx *FmtCtx) { + f := ctx.flags + bareStrings := f.HasFlags(FmtFlags(lexbase.EncBareStrings)) + if !bareStrings { + ctx.WriteByte('\'') } + FormatTimestampTZ(d.Time, &ctx.Buffer) if !bareStrings { ctx.WriteByte('\'') } @@ -5640,7 +5651,14 @@ func AdjustValueToType(typ *types.T, inVal Datum) (outVal Datum, err error) { } else if v, ok := inVal.(*DCollatedString); ok { sv = v.Contents } - sv = adjustStringValueToType(typ, sv) + switch typ.Oid() { + case oid.T_char: + // "char" is supposed to truncate long values. + sv = util.TruncateString(sv, 1) + case oid.T_bpchar: + // bpchar types truncate trailing whitespace. + sv = strings.TrimRight(sv, " ") + } if typ.Width() > 0 && utf8.RuneCountInString(sv) > int(typ.Width()) { return nil, pgerror.Newf(pgcode.StringDataRightTruncation, "value too long for type %s", @@ -5783,17 +5801,3 @@ func AdjustValueToType(typ *types.T, inVal Datum) (outVal Datum, err error) { } return inVal, nil } - -// adjustStringToType checks that the width for strings fits the -// specified column type. -func adjustStringValueToType(typ *types.T, sv string) string { - switch typ.Oid() { - case oid.T_char: - // "char" is supposed to truncate long values - return util.TruncateString(sv, 1) - case oid.T_bpchar: - // bpchar types truncate trailing whitespace. - return strings.TrimRight(sv, " ") - } - return sv -}