MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / doParseDTupleFromString

Function doParseDTupleFromString

pkg/sql/sem/tree/parse_tuple.go:188–238  ·  view source on GitHub ↗

doParseDTupleFromString does most of the work of ParseDTupleFromString, except the error it returns isn't prettified as a parsing error. The dependsOnContext return value indicates if we had to consult the ParseContext (either for the time or the local timezone).

(
	ctx ParseContext, s string, t *types.T,
)

Source from the content-addressed store, hash-verified

186// The dependsOnContext return value indicates if we had to consult the
187// ParseContext (either for the time or the local timezone).
188func doParseDTupleFromString(
189 ctx ParseContext, s string, t *types.T,
190) (_ *DTuple, dependsOnContext bool, _ error) {
191 if t.TupleContents() == nil {
192 return nil, false, errors.AssertionFailedf("not a tuple type %s", t.SQLStringForError())
193 }
194 if t.Identical(types.AnyTuple) {
195 return nil, false, unsupportedRecordError
196 }
197 parser := tupleParseState{
198 s: s,
199 ctx: ctx,
200 result: NewDTupleWithLen(t, len(t.TupleContents())),
201 t: t,
202 }
203
204 parser.eatWhitespace()
205 if parser.peek() != '(' {
206 return nil, false, enclosingRecordError
207 }
208 parser.advance()
209 if parser.peek() != ')' || len(t.TupleContents()) > 0 {
210 if err := parser.parseElement(); err != nil {
211 return nil, false, err
212 }
213 parser.eatWhitespace()
214 for parser.peek() == ',' {
215 parser.advance()
216 if err := parser.parseElement(); err != nil {
217 return nil, false, err
218 }
219 }
220 }
221 parser.eatWhitespace()
222 if parser.eof() {
223 return nil, false, enclosingRecordError
224 }
225 if parser.peek() != ')' {
226 return nil, false, malformedRecordError
227 }
228 if parser.tupleIdx < len(parser.t.TupleContents()) {
229 return nil, false, errors.WithDetail(malformedRecordError, "Too few columns.")
230 }
231 parser.advance()
232 parser.eatWhitespace()
233 if !parser.eof() {
234 return nil, false, extraTextRecordError
235 }
236
237 return parser.result, parser.dependsOnContext, nil
238}

Callers 1

ParseDTupleFromStringFunction · 0.85

Calls 9

eatWhitespaceMethod · 0.95
peekMethod · 0.95
advanceMethod · 0.95
parseElementMethod · 0.95
eofMethod · 0.95
NewDTupleWithLenFunction · 0.85
TupleContentsMethod · 0.80
SQLStringForErrorMethod · 0.80
IdenticalMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…