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

Method IsComposite

pkg/sql/sem/tree/datum.go:3998–4034  ·  view source on GitHub ↗

IsComposite implements the CompositeDatum interface.

()

Source from the content-addressed store, hash-verified

3996
3997// IsComposite implements the CompositeDatum interface.
3998func (d *DJSON) IsComposite() bool {
3999 switch d.JSON.Type() {
4000 case json.NumberJSONType:
4001 dec, ok := d.JSON.AsDecimal()
4002 if !ok {
4003 panic(errors.AssertionFailedf("could not convert into JSON Decimal"))
4004 }
4005 DDec := DDecimal{Decimal: *dec}
4006 return DDec.IsComposite()
4007 case json.ArrayJSONType:
4008 jsonArray, ok := d.AsArray()
4009 if !ok {
4010 panic(errors.AssertionFailedf("could not extract the JSON Array"))
4011 }
4012 for _, elem := range jsonArray {
4013 dJsonVal := DJSON{elem}
4014 if dJsonVal.IsComposite() {
4015 return true
4016 }
4017 }
4018 case json.ObjectJSONType:
4019 if it, err := d.ObjectIter(); it != nil && err == nil {
4020 // Assumption: no collated strings are present as JSON keys.
4021 // Thus, JSON keys are not being checked if they are
4022 // composite or not.
4023 for it.Next() {
4024 valDJSON := NewDJSON(it.Value())
4025 if valDJSON.IsComposite() {
4026 return true
4027 }
4028 }
4029 } else if err != nil {
4030 panic(errors.NewAssertionErrorWithWrappedErrf(err, "could not receive an ObjectKeyIterator"))
4031 }
4032 }
4033 return false
4034}
4035
4036// ParseDJSON takes a string of JSON and returns a DJSON value.
4037func ParseDJSON(s string) (Datum, error) {

Callers

nothing calls this directly

Calls 8

IsCompositeMethod · 0.95
NewDJSONFunction · 0.85
TypeMethod · 0.65
AsDecimalMethod · 0.65
AsArrayMethod · 0.65
ObjectIterMethod · 0.65
NextMethod · 0.65
ValueMethod · 0.45

Tested by

no test coverage detected