id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
4,100 | kennygrant/sanitize | sanitize.go | Name | func Name(s string) string {
// Start with lowercase string
fileName := strings.ToLower(s)
fileName = path.Clean(path.Base(fileName))
// Remove illegal characters for names, replacing some common separators with -
fileName = cleanString(fileName, illegalName)
// NB this may be of length 0, caller must check
return fileName
} | go | func Name(s string) string {
// Start with lowercase string
fileName := strings.ToLower(s)
fileName = path.Clean(path.Base(fileName))
// Remove illegal characters for names, replacing some common separators with -
fileName = cleanString(fileName, illegalName)
// NB this may be of length 0, caller must check
return fileName
} | [
"func",
"Name",
"(",
"s",
"string",
")",
"string",
"{",
"// Start with lowercase string",
"fileName",
":=",
"strings",
".",
"ToLower",
"(",
"s",
")",
"\n",
"fileName",
"=",
"path",
".",
"Clean",
"(",
"path",
".",
"Base",
"(",
"fileName",
")",
")",
"\n\n",
"// Remove illegal characters for names, replacing some common separators with -",
"fileName",
"=",
"cleanString",
"(",
"fileName",
",",
"illegalName",
")",
"\n\n",
"// NB this may be of length 0, caller must check",
"return",
"fileName",
"\n",
"}"
] | // Name makes a string safe to use in a file name by first finding the path basename, then replacing non-ascii characters. | [
"Name",
"makes",
"a",
"string",
"safe",
"to",
"use",
"in",
"a",
"file",
"name",
"by",
"first",
"finding",
"the",
"path",
"basename",
"then",
"replacing",
"non",
"-",
"ascii",
"characters",
"."
] | 06ec0d0dbcd497d01e5189b16f5263f712e61a8e | https://github.com/kennygrant/sanitize/blob/06ec0d0dbcd497d01e5189b16f5263f712e61a8e/sanitize.go#L187-L197 |
4,101 | kennygrant/sanitize | sanitize.go | Accents | func Accents(s string) string {
// Replace some common accent characters
b := bytes.NewBufferString("")
for _, c := range s {
// Check transliterations first
if val, ok := transliterations[c]; ok {
b.WriteString(val)
} else {
b.WriteRune(c)
}
}
return b.String()
} | go | func Accents(s string) string {
// Replace some common accent characters
b := bytes.NewBufferString("")
for _, c := range s {
// Check transliterations first
if val, ok := transliterations[c]; ok {
b.WriteString(val)
} else {
b.WriteRune(c)
}
}
return b.String()
} | [
"func",
"Accents",
"(",
"s",
"string",
")",
"string",
"{",
"// Replace some common accent characters",
"b",
":=",
"bytes",
".",
"NewBufferString",
"(",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"s",
"{",
"// Check transliterations first",
"if",
"val",
",",
"ok",
":=",
"transliterations",
"[",
"c",
"]",
";",
"ok",
"{",
"b",
".",
"WriteString",
"(",
"val",
")",
"\n",
"}",
"else",
"{",
"b",
".",
"WriteRune",
"(",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"b",
".",
"String",
"(",
")",
"\n",
"}"
] | // Accents replaces a set of accented characters with ascii equivalents. | [
"Accents",
"replaces",
"a",
"set",
"of",
"accented",
"characters",
"with",
"ascii",
"equivalents",
"."
] | 06ec0d0dbcd497d01e5189b16f5263f712e61a8e | https://github.com/kennygrant/sanitize/blob/06ec0d0dbcd497d01e5189b16f5263f712e61a8e/sanitize.go#L294-L306 |
4,102 | kennygrant/sanitize | sanitize.go | cleanAttributes | func cleanAttributes(a []parser.Attribute, allowed []string) []parser.Attribute {
if len(a) == 0 {
return a
}
var cleaned []parser.Attribute
for _, attr := range a {
if includes(allowed, attr.Key) {
val := strings.ToLower(attr.Val)
// Check for illegal attribute values
if illegalAttr.FindString(val) != "" {
attr.Val = ""
}
// Check for legal href values - / mailto:// http:// or https://
if attr.Key == "href" {
if legalHrefAttr.FindString(val) == "" {
attr.Val = ""
}
}
// If we still have an attribute, append it to the array
if attr.Val != "" {
cleaned = append(cleaned, attr)
}
}
}
return cleaned
} | go | func cleanAttributes(a []parser.Attribute, allowed []string) []parser.Attribute {
if len(a) == 0 {
return a
}
var cleaned []parser.Attribute
for _, attr := range a {
if includes(allowed, attr.Key) {
val := strings.ToLower(attr.Val)
// Check for illegal attribute values
if illegalAttr.FindString(val) != "" {
attr.Val = ""
}
// Check for legal href values - / mailto:// http:// or https://
if attr.Key == "href" {
if legalHrefAttr.FindString(val) == "" {
attr.Val = ""
}
}
// If we still have an attribute, append it to the array
if attr.Val != "" {
cleaned = append(cleaned, attr)
}
}
}
return cleaned
} | [
"func",
"cleanAttributes",
"(",
"a",
"[",
"]",
"parser",
".",
"Attribute",
",",
"allowed",
"[",
"]",
"string",
")",
"[",
"]",
"parser",
".",
"Attribute",
"{",
"if",
"len",
"(",
"a",
")",
"==",
"0",
"{",
"return",
"a",
"\n",
"}",
"\n\n",
"var",
"cleaned",
"[",
"]",
"parser",
".",
"Attribute",
"\n",
"for",
"_",
",",
"attr",
":=",
"range",
"a",
"{",
"if",
"includes",
"(",
"allowed",
",",
"attr",
".",
"Key",
")",
"{",
"val",
":=",
"strings",
".",
"ToLower",
"(",
"attr",
".",
"Val",
")",
"\n\n",
"// Check for illegal attribute values",
"if",
"illegalAttr",
".",
"FindString",
"(",
"val",
")",
"!=",
"\"",
"\"",
"{",
"attr",
".",
"Val",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// Check for legal href values - / mailto:// http:// or https://",
"if",
"attr",
".",
"Key",
"==",
"\"",
"\"",
"{",
"if",
"legalHrefAttr",
".",
"FindString",
"(",
"val",
")",
"==",
"\"",
"\"",
"{",
"attr",
".",
"Val",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n\n",
"// If we still have an attribute, append it to the array",
"if",
"attr",
".",
"Val",
"!=",
"\"",
"\"",
"{",
"cleaned",
"=",
"append",
"(",
"cleaned",
",",
"attr",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"cleaned",
"\n",
"}"
] | // cleanAttributes returns an array of attributes after removing malicious ones. | [
"cleanAttributes",
"returns",
"an",
"array",
"of",
"attributes",
"after",
"removing",
"malicious",
"ones",
"."
] | 06ec0d0dbcd497d01e5189b16f5263f712e61a8e | https://github.com/kennygrant/sanitize/blob/06ec0d0dbcd497d01e5189b16f5263f712e61a8e/sanitize.go#L319-L349 |
4,103 | kennygrant/sanitize | sanitize.go | cleanString | func cleanString(s string, r *regexp.Regexp) string {
// Remove any trailing space to avoid ending on -
s = strings.Trim(s, " ")
// Flatten accents first so that if we remove non-ascii we still get a legible name
s = Accents(s)
// Replace certain joining characters with a dash
s = separators.ReplaceAllString(s, "-")
// Remove all other unrecognised characters - NB we do allow any printable characters
s = r.ReplaceAllString(s, "")
// Remove any multiple dashes caused by replacements above
s = dashes.ReplaceAllString(s, "-")
return s
} | go | func cleanString(s string, r *regexp.Regexp) string {
// Remove any trailing space to avoid ending on -
s = strings.Trim(s, " ")
// Flatten accents first so that if we remove non-ascii we still get a legible name
s = Accents(s)
// Replace certain joining characters with a dash
s = separators.ReplaceAllString(s, "-")
// Remove all other unrecognised characters - NB we do allow any printable characters
s = r.ReplaceAllString(s, "")
// Remove any multiple dashes caused by replacements above
s = dashes.ReplaceAllString(s, "-")
return s
} | [
"func",
"cleanString",
"(",
"s",
"string",
",",
"r",
"*",
"regexp",
".",
"Regexp",
")",
"string",
"{",
"// Remove any trailing space to avoid ending on -",
"s",
"=",
"strings",
".",
"Trim",
"(",
"s",
",",
"\"",
"\"",
")",
"\n\n",
"// Flatten accents first so that if we remove non-ascii we still get a legible name",
"s",
"=",
"Accents",
"(",
"s",
")",
"\n\n",
"// Replace certain joining characters with a dash",
"s",
"=",
"separators",
".",
"ReplaceAllString",
"(",
"s",
",",
"\"",
"\"",
")",
"\n\n",
"// Remove all other unrecognised characters - NB we do allow any printable characters",
"s",
"=",
"r",
".",
"ReplaceAllString",
"(",
"s",
",",
"\"",
"\"",
")",
"\n\n",
"// Remove any multiple dashes caused by replacements above",
"s",
"=",
"dashes",
".",
"ReplaceAllString",
"(",
"s",
",",
"\"",
"\"",
")",
"\n\n",
"return",
"s",
"\n",
"}"
] | // cleanString replaces separators with - and removes characters listed in the regexp provided from string.
// Accents, spaces, and all characters not in A-Za-z0-9 are replaced. | [
"cleanString",
"replaces",
"separators",
"with",
"-",
"and",
"removes",
"characters",
"listed",
"in",
"the",
"regexp",
"provided",
"from",
"string",
".",
"Accents",
"spaces",
"and",
"all",
"characters",
"not",
"in",
"A",
"-",
"Za",
"-",
"z0",
"-",
"9",
"are",
"replaced",
"."
] | 06ec0d0dbcd497d01e5189b16f5263f712e61a8e | https://github.com/kennygrant/sanitize/blob/06ec0d0dbcd497d01e5189b16f5263f712e61a8e/sanitize.go#L360-L378 |
4,104 | uber-go/dosa | entity.go | String | func (ck ClusteringKey) String() string {
if ck.Descending {
return ck.Name + " DESC"
}
return ck.Name + " ASC"
} | go | func (ck ClusteringKey) String() string {
if ck.Descending {
return ck.Name + " DESC"
}
return ck.Name + " ASC"
} | [
"func",
"(",
"ck",
"ClusteringKey",
")",
"String",
"(",
")",
"string",
"{",
"if",
"ck",
".",
"Descending",
"{",
"return",
"ck",
".",
"Name",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"ck",
".",
"Name",
"+",
"\"",
"\"",
"\n",
"}"
] | // String takes a ClusteringKey and returns "column-name ASC|DESC" | [
"String",
"takes",
"a",
"ClusteringKey",
"and",
"returns",
"column",
"-",
"name",
"ASC|DESC"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L51-L56 |
4,105 | uber-go/dosa | entity.go | Clone | func (pk PrimaryKey) Clone() *PrimaryKey {
npk := &PrimaryKey{}
if pk.PartitionKeys != nil {
npk.PartitionKeys = make([]string, len(pk.PartitionKeys))
for i, k := range pk.PartitionKeys {
npk.PartitionKeys[i] = k
}
}
if pk.ClusteringKeys != nil {
npk.ClusteringKeys = make([]*ClusteringKey, len(pk.ClusteringKeys))
for i, c := range pk.ClusteringKeys {
npk.ClusteringKeys[i] = &ClusteringKey{
Name: c.Name,
Descending: c.Descending,
}
}
}
return npk
} | go | func (pk PrimaryKey) Clone() *PrimaryKey {
npk := &PrimaryKey{}
if pk.PartitionKeys != nil {
npk.PartitionKeys = make([]string, len(pk.PartitionKeys))
for i, k := range pk.PartitionKeys {
npk.PartitionKeys[i] = k
}
}
if pk.ClusteringKeys != nil {
npk.ClusteringKeys = make([]*ClusteringKey, len(pk.ClusteringKeys))
for i, c := range pk.ClusteringKeys {
npk.ClusteringKeys[i] = &ClusteringKey{
Name: c.Name,
Descending: c.Descending,
}
}
}
return npk
} | [
"func",
"(",
"pk",
"PrimaryKey",
")",
"Clone",
"(",
")",
"*",
"PrimaryKey",
"{",
"npk",
":=",
"&",
"PrimaryKey",
"{",
"}",
"\n",
"if",
"pk",
".",
"PartitionKeys",
"!=",
"nil",
"{",
"npk",
".",
"PartitionKeys",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"pk",
".",
"PartitionKeys",
")",
")",
"\n\n",
"for",
"i",
",",
"k",
":=",
"range",
"pk",
".",
"PartitionKeys",
"{",
"npk",
".",
"PartitionKeys",
"[",
"i",
"]",
"=",
"k",
"\n",
"}",
"\n\n",
"}",
"\n\n",
"if",
"pk",
".",
"ClusteringKeys",
"!=",
"nil",
"{",
"npk",
".",
"ClusteringKeys",
"=",
"make",
"(",
"[",
"]",
"*",
"ClusteringKey",
",",
"len",
"(",
"pk",
".",
"ClusteringKeys",
")",
")",
"\n",
"for",
"i",
",",
"c",
":=",
"range",
"pk",
".",
"ClusteringKeys",
"{",
"npk",
".",
"ClusteringKeys",
"[",
"i",
"]",
"=",
"&",
"ClusteringKey",
"{",
"Name",
":",
"c",
".",
"Name",
",",
"Descending",
":",
"c",
".",
"Descending",
",",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"npk",
"\n",
"}"
] | // Clone returns a deep copy of PrimaryKey | [
"Clone",
"returns",
"a",
"deep",
"copy",
"of",
"PrimaryKey"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L65-L87 |
4,106 | uber-go/dosa | entity.go | ClusteringKeySet | func (pk PrimaryKey) ClusteringKeySet() map[string]struct{} {
m := make(map[string]struct{})
for _, c := range pk.ClusteringKeys {
m[c.Name] = struct{}{}
}
return m
} | go | func (pk PrimaryKey) ClusteringKeySet() map[string]struct{} {
m := make(map[string]struct{})
for _, c := range pk.ClusteringKeys {
m[c.Name] = struct{}{}
}
return m
} | [
"func",
"(",
"pk",
"PrimaryKey",
")",
"ClusteringKeySet",
"(",
")",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"pk",
".",
"ClusteringKeys",
"{",
"m",
"[",
"c",
".",
"Name",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // ClusteringKeySet returns a set of all clustering keys. | [
"ClusteringKeySet",
"returns",
"a",
"set",
"of",
"all",
"clustering",
"keys",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L90-L96 |
4,107 | uber-go/dosa | entity.go | PartitionKeySet | func (pk PrimaryKey) PartitionKeySet() map[string]struct{} {
m := make(map[string]struct{})
for _, p := range pk.PartitionKeys {
m[p] = struct{}{}
}
return m
} | go | func (pk PrimaryKey) PartitionKeySet() map[string]struct{} {
m := make(map[string]struct{})
for _, p := range pk.PartitionKeys {
m[p] = struct{}{}
}
return m
} | [
"func",
"(",
"pk",
"PrimaryKey",
")",
"PartitionKeySet",
"(",
")",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"pk",
".",
"PartitionKeys",
"{",
"m",
"[",
"p",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // PartitionKeySet returns the set of partition keys | [
"PartitionKeySet",
"returns",
"the",
"set",
"of",
"partition",
"keys"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L99-L105 |
4,108 | uber-go/dosa | entity.go | PrimaryKeySet | func (pk PrimaryKey) PrimaryKeySet() map[string]struct{} {
m := pk.ClusteringKeySet()
for _, p := range pk.PartitionKeys {
m[p] = struct{}{}
}
return m
} | go | func (pk PrimaryKey) PrimaryKeySet() map[string]struct{} {
m := pk.ClusteringKeySet()
for _, p := range pk.PartitionKeys {
m[p] = struct{}{}
}
return m
} | [
"func",
"(",
"pk",
"PrimaryKey",
")",
"PrimaryKeySet",
"(",
")",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"m",
":=",
"pk",
".",
"ClusteringKeySet",
"(",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"pk",
".",
"PartitionKeys",
"{",
"m",
"[",
"p",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // PrimaryKeySet returns the union of the set of partition keys and clustering keys | [
"PrimaryKeySet",
"returns",
"the",
"union",
"of",
"the",
"set",
"of",
"partition",
"keys",
"and",
"clustering",
"keys"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L108-L114 |
4,109 | uber-go/dosa | entity.go | formatClusteringKeys | func formatClusteringKeys(keys []*ClusteringKey) string {
pieces := make([]string, len(keys))
for index, ck := range keys {
pieces[index] = ck.String()
}
return strings.Join(pieces, ", ")
} | go | func formatClusteringKeys(keys []*ClusteringKey) string {
pieces := make([]string, len(keys))
for index, ck := range keys {
pieces[index] = ck.String()
}
return strings.Join(pieces, ", ")
} | [
"func",
"formatClusteringKeys",
"(",
"keys",
"[",
"]",
"*",
"ClusteringKey",
")",
"string",
"{",
"pieces",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"keys",
")",
")",
"\n",
"for",
"index",
",",
"ck",
":=",
"range",
"keys",
"{",
"pieces",
"[",
"index",
"]",
"=",
"ck",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"pieces",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // formatClusteringKeys takes an array of ClusteringKeys and returns
// a string that shows all of them, separated by commas | [
"formatClusteringKeys",
"takes",
"an",
"array",
"of",
"ClusteringKeys",
"and",
"returns",
"a",
"string",
"that",
"shows",
"all",
"of",
"them",
"separated",
"by",
"commas"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L118-L124 |
4,110 | uber-go/dosa | entity.go | Clone | func (cd *ColumnDefinition) Clone() *ColumnDefinition {
// TODO: clone tag
return &ColumnDefinition{
Name: cd.Name,
Type: cd.Type,
}
} | go | func (cd *ColumnDefinition) Clone() *ColumnDefinition {
// TODO: clone tag
return &ColumnDefinition{
Name: cd.Name,
Type: cd.Type,
}
} | [
"func",
"(",
"cd",
"*",
"ColumnDefinition",
")",
"Clone",
"(",
")",
"*",
"ColumnDefinition",
"{",
"// TODO: clone tag",
"return",
"&",
"ColumnDefinition",
"{",
"Name",
":",
"cd",
".",
"Name",
",",
"Type",
":",
"cd",
".",
"Type",
",",
"}",
"\n",
"}"
] | // Clone returns a deep copy of ColumnDefinition | [
"Clone",
"returns",
"a",
"deep",
"copy",
"of",
"ColumnDefinition"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L159-L165 |
4,111 | uber-go/dosa | entity.go | Clone | func (e *EntityDefinition) Clone() *EntityDefinition {
newEd := &EntityDefinition{
Name: e.Name,
Key: e.Key.Clone(),
ETL: e.ETL,
}
if e.Columns != nil {
newEd.Columns = make([]*ColumnDefinition, len(e.Columns))
for i, col := range e.Columns {
newEd.Columns[i] = col.Clone()
}
}
if e.Indexes != nil {
newEd.Indexes = make(map[string]*IndexDefinition)
if e.Indexes == nil {
newEd.Indexes = nil
}
for k, index := range e.Indexes {
newEd.Indexes[k] = index.Clone()
}
}
return newEd
} | go | func (e *EntityDefinition) Clone() *EntityDefinition {
newEd := &EntityDefinition{
Name: e.Name,
Key: e.Key.Clone(),
ETL: e.ETL,
}
if e.Columns != nil {
newEd.Columns = make([]*ColumnDefinition, len(e.Columns))
for i, col := range e.Columns {
newEd.Columns[i] = col.Clone()
}
}
if e.Indexes != nil {
newEd.Indexes = make(map[string]*IndexDefinition)
if e.Indexes == nil {
newEd.Indexes = nil
}
for k, index := range e.Indexes {
newEd.Indexes[k] = index.Clone()
}
}
return newEd
} | [
"func",
"(",
"e",
"*",
"EntityDefinition",
")",
"Clone",
"(",
")",
"*",
"EntityDefinition",
"{",
"newEd",
":=",
"&",
"EntityDefinition",
"{",
"Name",
":",
"e",
".",
"Name",
",",
"Key",
":",
"e",
".",
"Key",
".",
"Clone",
"(",
")",
",",
"ETL",
":",
"e",
".",
"ETL",
",",
"}",
"\n\n",
"if",
"e",
".",
"Columns",
"!=",
"nil",
"{",
"newEd",
".",
"Columns",
"=",
"make",
"(",
"[",
"]",
"*",
"ColumnDefinition",
",",
"len",
"(",
"e",
".",
"Columns",
")",
")",
"\n",
"for",
"i",
",",
"col",
":=",
"range",
"e",
".",
"Columns",
"{",
"newEd",
".",
"Columns",
"[",
"i",
"]",
"=",
"col",
".",
"Clone",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"e",
".",
"Indexes",
"!=",
"nil",
"{",
"newEd",
".",
"Indexes",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"IndexDefinition",
")",
"\n",
"if",
"e",
".",
"Indexes",
"==",
"nil",
"{",
"newEd",
".",
"Indexes",
"=",
"nil",
"\n",
"}",
"\n",
"for",
"k",
",",
"index",
":=",
"range",
"e",
".",
"Indexes",
"{",
"newEd",
".",
"Indexes",
"[",
"k",
"]",
"=",
"index",
".",
"Clone",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"newEd",
"\n",
"}"
] | // Clone returns a deep copy of EntityDefinition | [
"Clone",
"returns",
"a",
"deep",
"copy",
"of",
"EntityDefinition"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L189-L214 |
4,112 | uber-go/dosa | entity.go | ColumnTypes | func (e *EntityDefinition) ColumnTypes() map[string]Type {
m := make(map[string]Type)
for _, c := range e.Columns {
m[c.Name] = c.Type
}
return m
} | go | func (e *EntityDefinition) ColumnTypes() map[string]Type {
m := make(map[string]Type)
for _, c := range e.Columns {
m[c.Name] = c.Type
}
return m
} | [
"func",
"(",
"e",
"*",
"EntityDefinition",
")",
"ColumnTypes",
"(",
")",
"map",
"[",
"string",
"]",
"Type",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"Type",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"e",
".",
"Columns",
"{",
"m",
"[",
"c",
".",
"Name",
"]",
"=",
"c",
".",
"Type",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // ColumnTypes returns a map of column name to column type for all columns. | [
"ColumnTypes",
"returns",
"a",
"map",
"of",
"column",
"name",
"to",
"column",
"type",
"for",
"all",
"columns",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L351-L357 |
4,113 | uber-go/dosa | entity.go | ColumnMap | func (e *EntityDefinition) ColumnMap() map[string]*ColumnDefinition {
m := make(map[string]*ColumnDefinition)
for _, c := range e.Columns {
m[c.Name] = c
}
return m
} | go | func (e *EntityDefinition) ColumnMap() map[string]*ColumnDefinition {
m := make(map[string]*ColumnDefinition)
for _, c := range e.Columns {
m[c.Name] = c
}
return m
} | [
"func",
"(",
"e",
"*",
"EntityDefinition",
")",
"ColumnMap",
"(",
")",
"map",
"[",
"string",
"]",
"*",
"ColumnDefinition",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"ColumnDefinition",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"e",
".",
"Columns",
"{",
"m",
"[",
"c",
".",
"Name",
"]",
"=",
"c",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // ColumnMap returns a map of column name to column definition for all columns. | [
"ColumnMap",
"returns",
"a",
"map",
"of",
"column",
"name",
"to",
"column",
"definition",
"for",
"all",
"columns",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L360-L366 |
4,114 | uber-go/dosa | entity.go | PartitionKeySet | func (e *EntityDefinition) PartitionKeySet() map[string]struct{} {
m := make(map[string]struct{})
for _, p := range e.Key.PartitionKeys {
m[p] = struct{}{}
}
return m
} | go | func (e *EntityDefinition) PartitionKeySet() map[string]struct{} {
m := make(map[string]struct{})
for _, p := range e.Key.PartitionKeys {
m[p] = struct{}{}
}
return m
} | [
"func",
"(",
"e",
"*",
"EntityDefinition",
")",
"PartitionKeySet",
"(",
")",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"e",
".",
"Key",
".",
"PartitionKeys",
"{",
"m",
"[",
"p",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // PartitionKeySet returns a set of all partition keys. | [
"PartitionKeySet",
"returns",
"a",
"set",
"of",
"all",
"partition",
"keys",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L369-L375 |
4,115 | uber-go/dosa | entity.go | KeySet | func (e *EntityDefinition) KeySet() map[string]struct{} {
m := e.Key.ClusteringKeySet()
pks := e.PartitionKeySet()
for p := range pks {
m[p] = struct{}{}
}
return m
} | go | func (e *EntityDefinition) KeySet() map[string]struct{} {
m := e.Key.ClusteringKeySet()
pks := e.PartitionKeySet()
for p := range pks {
m[p] = struct{}{}
}
return m
} | [
"func",
"(",
"e",
"*",
"EntityDefinition",
")",
"KeySet",
"(",
")",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"m",
":=",
"e",
".",
"Key",
".",
"ClusteringKeySet",
"(",
")",
"\n",
"pks",
":=",
"e",
".",
"PartitionKeySet",
"(",
")",
"\n",
"for",
"p",
":=",
"range",
"pks",
"{",
"m",
"[",
"p",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // KeySet returns a set of all keys, including partition keys and clustering keys. | [
"KeySet",
"returns",
"a",
"set",
"of",
"all",
"keys",
"including",
"partition",
"keys",
"and",
"clustering",
"keys",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L378-L385 |
4,116 | uber-go/dosa | entity.go | FindColumnDefinition | func (e *EntityDefinition) FindColumnDefinition(name string) *ColumnDefinition {
for _, cd := range e.Columns {
if cd.Name == name {
return cd
}
}
return nil
} | go | func (e *EntityDefinition) FindColumnDefinition(name string) *ColumnDefinition {
for _, cd := range e.Columns {
if cd.Name == name {
return cd
}
}
return nil
} | [
"func",
"(",
"e",
"*",
"EntityDefinition",
")",
"FindColumnDefinition",
"(",
"name",
"string",
")",
"*",
"ColumnDefinition",
"{",
"for",
"_",
",",
"cd",
":=",
"range",
"e",
".",
"Columns",
"{",
"if",
"cd",
".",
"Name",
"==",
"name",
"{",
"return",
"cd",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // FindColumnDefinition finds the column definition by the column name | [
"FindColumnDefinition",
"finds",
"the",
"column",
"definition",
"by",
"the",
"column",
"name"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L455-L462 |
4,117 | uber-go/dosa | entity.go | UniqueKey | func (e *EntityDefinition) UniqueKey(oldKey *PrimaryKey) *PrimaryKey {
indexHas := oldKey.PrimaryKeySet()
result := *oldKey
// look for missing primary keys
for _, key := range e.Key.PartitionKeys {
if _, ok := indexHas[key]; !ok {
result.ClusteringKeys = append(result.ClusteringKeys, &ClusteringKey{
Name: key})
}
}
// look for missing clustering keys
for _, key := range e.Key.ClusteringKeys {
if _, ok := indexHas[key.Name]; !ok {
result.ClusteringKeys = append(result.ClusteringKeys, &ClusteringKey{
Name: key.Name})
}
}
return &result
} | go | func (e *EntityDefinition) UniqueKey(oldKey *PrimaryKey) *PrimaryKey {
indexHas := oldKey.PrimaryKeySet()
result := *oldKey
// look for missing primary keys
for _, key := range e.Key.PartitionKeys {
if _, ok := indexHas[key]; !ok {
result.ClusteringKeys = append(result.ClusteringKeys, &ClusteringKey{
Name: key})
}
}
// look for missing clustering keys
for _, key := range e.Key.ClusteringKeys {
if _, ok := indexHas[key.Name]; !ok {
result.ClusteringKeys = append(result.ClusteringKeys, &ClusteringKey{
Name: key.Name})
}
}
return &result
} | [
"func",
"(",
"e",
"*",
"EntityDefinition",
")",
"UniqueKey",
"(",
"oldKey",
"*",
"PrimaryKey",
")",
"*",
"PrimaryKey",
"{",
"indexHas",
":=",
"oldKey",
".",
"PrimaryKeySet",
"(",
")",
"\n",
"result",
":=",
"*",
"oldKey",
"\n\n",
"// look for missing primary keys",
"for",
"_",
",",
"key",
":=",
"range",
"e",
".",
"Key",
".",
"PartitionKeys",
"{",
"if",
"_",
",",
"ok",
":=",
"indexHas",
"[",
"key",
"]",
";",
"!",
"ok",
"{",
"result",
".",
"ClusteringKeys",
"=",
"append",
"(",
"result",
".",
"ClusteringKeys",
",",
"&",
"ClusteringKey",
"{",
"Name",
":",
"key",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// look for missing clustering keys",
"for",
"_",
",",
"key",
":=",
"range",
"e",
".",
"Key",
".",
"ClusteringKeys",
"{",
"if",
"_",
",",
"ok",
":=",
"indexHas",
"[",
"key",
".",
"Name",
"]",
";",
"!",
"ok",
"{",
"result",
".",
"ClusteringKeys",
"=",
"append",
"(",
"result",
".",
"ClusteringKeys",
",",
"&",
"ClusteringKey",
"{",
"Name",
":",
"key",
".",
"Name",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"result",
"\n",
"}"
] | // UniqueKey adds any missing keys from the entity's primary key to the keys
// specified in the index, to guarantee that the returned key is unique
// This method is used to create materialized views | [
"UniqueKey",
"adds",
"any",
"missing",
"keys",
"from",
"the",
"entity",
"s",
"primary",
"key",
"to",
"the",
"keys",
"specified",
"in",
"the",
"index",
"to",
"guarantee",
"that",
"the",
"returned",
"key",
"is",
"unique",
"This",
"method",
"is",
"used",
"to",
"create",
"materialized",
"views"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity.go#L467-L488 |
4,118 | uber-go/dosa | connectors/memory/memory.go | remove | func (pr *partitionRange) remove() {
partitionRef := pr.entityRef[pr.partitionKey]
pr.entityRef[pr.partitionKey] = append(partitionRef[:pr.start], partitionRef[pr.end+1:]...)
pr.entityRef = nil
pr.partitionKey = ""
pr.start = 0
pr.end = 0
} | go | func (pr *partitionRange) remove() {
partitionRef := pr.entityRef[pr.partitionKey]
pr.entityRef[pr.partitionKey] = append(partitionRef[:pr.start], partitionRef[pr.end+1:]...)
pr.entityRef = nil
pr.partitionKey = ""
pr.start = 0
pr.end = 0
} | [
"func",
"(",
"pr",
"*",
"partitionRange",
")",
"remove",
"(",
")",
"{",
"partitionRef",
":=",
"pr",
".",
"entityRef",
"[",
"pr",
".",
"partitionKey",
"]",
"\n",
"pr",
".",
"entityRef",
"[",
"pr",
".",
"partitionKey",
"]",
"=",
"append",
"(",
"partitionRef",
"[",
":",
"pr",
".",
"start",
"]",
",",
"partitionRef",
"[",
"pr",
".",
"end",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"pr",
".",
"entityRef",
"=",
"nil",
"\n",
"pr",
".",
"partitionKey",
"=",
"\"",
"\"",
"\n",
"pr",
".",
"start",
"=",
"0",
"\n",
"pr",
".",
"end",
"=",
"0",
"\n",
"}"
] | // remove deletes the values referenced by the partitionRange. Since this function modifies
// the data stored in the in-memory connector, a write lock must be held when calling
// this function.
//
// Note this function can't be called more than once. Calling it more than once will cause a panic. | [
"remove",
"deletes",
"the",
"values",
"referenced",
"by",
"the",
"partitionRange",
".",
"Since",
"this",
"function",
"modifies",
"the",
"data",
"stored",
"in",
"the",
"in",
"-",
"memory",
"connector",
"a",
"write",
"lock",
"must",
"be",
"held",
"when",
"calling",
"this",
"function",
".",
"Note",
"this",
"function",
"can",
"t",
"be",
"called",
"more",
"than",
"once",
".",
"Calling",
"it",
"more",
"than",
"once",
"will",
"cause",
"a",
"panic",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L74-L81 |
4,119 | uber-go/dosa | connectors/memory/memory.go | values | func (pr *partitionRange) values() []map[string]dosa.FieldValue {
return pr.entityRef[pr.partitionKey][pr.start : pr.end+1]
} | go | func (pr *partitionRange) values() []map[string]dosa.FieldValue {
return pr.entityRef[pr.partitionKey][pr.start : pr.end+1]
} | [
"func",
"(",
"pr",
"*",
"partitionRange",
")",
"values",
"(",
")",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"{",
"return",
"pr",
".",
"entityRef",
"[",
"pr",
".",
"partitionKey",
"]",
"[",
"pr",
".",
"start",
":",
"pr",
".",
"end",
"+",
"1",
"]",
"\n",
"}"
] | // values returns all the values in the partition range | [
"values",
"returns",
"all",
"the",
"values",
"in",
"the",
"partition",
"range"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L84-L86 |
4,120 | uber-go/dosa | connectors/memory/memory.go | findInsertionPoint | func findInsertionPoint(pk *dosa.PrimaryKey, data []map[string]dosa.FieldValue, insertMe map[string]dosa.FieldValue) (found bool, idx int) {
found = false
idx = sort.Search(len(data), func(offset int) bool {
cmp := compareRows(pk, data[offset], insertMe)
if cmp == 0 {
found = true
}
return cmp >= 0
})
return
} | go | func findInsertionPoint(pk *dosa.PrimaryKey, data []map[string]dosa.FieldValue, insertMe map[string]dosa.FieldValue) (found bool, idx int) {
found = false
idx = sort.Search(len(data), func(offset int) bool {
cmp := compareRows(pk, data[offset], insertMe)
if cmp == 0 {
found = true
}
return cmp >= 0
})
return
} | [
"func",
"findInsertionPoint",
"(",
"pk",
"*",
"dosa",
".",
"PrimaryKey",
",",
"data",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"insertMe",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"(",
"found",
"bool",
",",
"idx",
"int",
")",
"{",
"found",
"=",
"false",
"\n",
"idx",
"=",
"sort",
".",
"Search",
"(",
"len",
"(",
"data",
")",
",",
"func",
"(",
"offset",
"int",
")",
"bool",
"{",
"cmp",
":=",
"compareRows",
"(",
"pk",
",",
"data",
"[",
"offset",
"]",
",",
"insertMe",
")",
"\n",
"if",
"cmp",
"==",
"0",
"{",
"found",
"=",
"true",
"\n",
"}",
"\n",
"return",
"cmp",
">=",
"0",
"\n",
"}",
")",
"\n",
"return",
"\n",
"}"
] | // findInsertionPoint locates the place within a partition where the data belongs.
// It inspects the clustering key values found in the insertMe value and figures out
// where they go in the data slice. It doesn't change anything, but it does let you
// know if it found an exact match or if it's just not there. When it's not there,
// it indicates where it is supposed to get inserted | [
"findInsertionPoint",
"locates",
"the",
"place",
"within",
"a",
"partition",
"where",
"the",
"data",
"belongs",
".",
"It",
"inspects",
"the",
"clustering",
"key",
"values",
"found",
"in",
"the",
"insertMe",
"value",
"and",
"figures",
"out",
"where",
"they",
"go",
"in",
"the",
"data",
"slice",
".",
"It",
"doesn",
"t",
"change",
"anything",
"but",
"it",
"does",
"let",
"you",
"know",
"if",
"it",
"found",
"an",
"exact",
"match",
"or",
"if",
"it",
"s",
"just",
"not",
"there",
".",
"When",
"it",
"s",
"not",
"there",
"it",
"indicates",
"where",
"it",
"is",
"supposed",
"to",
"get",
"inserted"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L110-L120 |
4,121 | uber-go/dosa | connectors/memory/memory.go | compareRows | func compareRows(pk *dosa.PrimaryKey, v1 map[string]dosa.FieldValue, v2 map[string]dosa.FieldValue) (cmp int8) {
keys := pk.ClusteringKeys
for _, key := range keys {
d1 := v1[key.Name]
d2 := v2[key.Name]
cmp = compareType(d1, d2)
if key.Descending {
cmp = -cmp
}
if cmp != 0 {
return cmp
}
}
return cmp
} | go | func compareRows(pk *dosa.PrimaryKey, v1 map[string]dosa.FieldValue, v2 map[string]dosa.FieldValue) (cmp int8) {
keys := pk.ClusteringKeys
for _, key := range keys {
d1 := v1[key.Name]
d2 := v2[key.Name]
cmp = compareType(d1, d2)
if key.Descending {
cmp = -cmp
}
if cmp != 0 {
return cmp
}
}
return cmp
} | [
"func",
"compareRows",
"(",
"pk",
"*",
"dosa",
".",
"PrimaryKey",
",",
"v1",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"v2",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"(",
"cmp",
"int8",
")",
"{",
"keys",
":=",
"pk",
".",
"ClusteringKeys",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"keys",
"{",
"d1",
":=",
"v1",
"[",
"key",
".",
"Name",
"]",
"\n",
"d2",
":=",
"v2",
"[",
"key",
".",
"Name",
"]",
"\n",
"cmp",
"=",
"compareType",
"(",
"d1",
",",
"d2",
")",
"\n",
"if",
"key",
".",
"Descending",
"{",
"cmp",
"=",
"-",
"cmp",
"\n",
"}",
"\n",
"if",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"cmp",
"\n",
"}"
] | // compareRows compares two maps of row data based on clustering keys. | [
"compareRows",
"compares",
"two",
"maps",
"of",
"row",
"data",
"based",
"on",
"clustering",
"keys",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L123-L137 |
4,122 | uber-go/dosa | connectors/memory/memory.go | copyRows | func copyRows(rows []map[string]dosa.FieldValue) []map[string]dosa.FieldValue {
copied := make([]map[string]dosa.FieldValue, len(rows))
for i, row := range rows {
copied[i] = copyRow(row)
}
return copied
} | go | func copyRows(rows []map[string]dosa.FieldValue) []map[string]dosa.FieldValue {
copied := make([]map[string]dosa.FieldValue, len(rows))
for i, row := range rows {
copied[i] = copyRow(row)
}
return copied
} | [
"func",
"copyRows",
"(",
"rows",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"{",
"copied",
":=",
"make",
"(",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"len",
"(",
"rows",
")",
")",
"\n",
"for",
"i",
",",
"row",
":=",
"range",
"rows",
"{",
"copied",
"[",
"i",
"]",
"=",
"copyRow",
"(",
"row",
")",
"\n",
"}",
"\n",
"return",
"copied",
"\n",
"}"
] | // copyRows copies all the rows in the given slice and returns a new slice with copies
// of each row. Order is maintained. | [
"copyRows",
"copies",
"all",
"the",
"rows",
"in",
"the",
"given",
"slice",
"and",
"returns",
"a",
"new",
"slice",
"with",
"copies",
"of",
"each",
"row",
".",
"Order",
"is",
"maintained",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L141-L147 |
4,123 | uber-go/dosa | connectors/memory/memory.go | copyRow | func copyRow(row map[string]dosa.FieldValue) map[string]dosa.FieldValue {
copied := make(map[string]dosa.FieldValue, len(row))
for k, v := range row {
copied[k] = v
}
return copied
} | go | func copyRow(row map[string]dosa.FieldValue) map[string]dosa.FieldValue {
copied := make(map[string]dosa.FieldValue, len(row))
for k, v := range row {
copied[k] = v
}
return copied
} | [
"func",
"copyRow",
"(",
"row",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"{",
"copied",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"len",
"(",
"row",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"row",
"{",
"copied",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"copied",
"\n",
"}"
] | // copyRow takes in a given "row" and returns a new map containing all of the same
// values that were in the given row. | [
"copyRow",
"takes",
"in",
"a",
"given",
"row",
"and",
"returns",
"a",
"new",
"map",
"containing",
"all",
"of",
"the",
"same",
"values",
"that",
"were",
"in",
"the",
"given",
"row",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L151-L157 |
4,124 | uber-go/dosa | connectors/memory/memory.go | compareType | func compareType(d1 dosa.FieldValue, d2 dosa.FieldValue) int8 {
switch d1 := d1.(type) {
case dosa.UUID:
u1 := uuid.FromStringOrNil(string(d1))
u2 := uuid.FromStringOrNil(string(d2.(dosa.UUID)))
if u1.Version() != u2.Version() {
if u1.Version() < u2.Version() {
return -1
}
return 1
}
if u1.Version() == 1 {
// compare time UUIDs
t1, _ := uuid.TimestampFromV1(u1)
t2, _ := uuid.TimestampFromV1(u2)
if t1 == t2 {
return 0
}
if t1 < t2 {
return -1
}
return 1
}
// version
if string(d1) == string(d2.(dosa.UUID)) {
return 0
}
if string(d1) < string(d2.(dosa.UUID)) {
return -1
}
return 1
case string:
if d1 == d2.(string) {
return 0
}
if d1 < d2.(string) {
return -1
}
return 1
case int64:
if d1 == d2.(int64) {
return 0
}
if d1 < d2.(int64) {
return -1
}
return 1
case int32:
if d1 == d2.(int32) {
return 0
}
if d1 < d2.(int32) {
return -1
}
return 1
case float64:
if d1 == d2.(float64) {
return 0
}
if d1 < d2.(float64) {
return -1
}
return 1
case []byte:
c := bytes.Compare(d1, d2.([]byte))
if c == 0 {
return 0
}
if c < 0 {
return -1
}
return 1
case time.Time:
if d1.Equal(d2.(time.Time)) {
return 0
}
if d1.Before(d2.(time.Time)) {
return -1
}
return 1
case bool:
if d1 == d2.(bool) {
return 0
}
if d1 == false {
return -1
}
return 1
}
panic(d1)
} | go | func compareType(d1 dosa.FieldValue, d2 dosa.FieldValue) int8 {
switch d1 := d1.(type) {
case dosa.UUID:
u1 := uuid.FromStringOrNil(string(d1))
u2 := uuid.FromStringOrNil(string(d2.(dosa.UUID)))
if u1.Version() != u2.Version() {
if u1.Version() < u2.Version() {
return -1
}
return 1
}
if u1.Version() == 1 {
// compare time UUIDs
t1, _ := uuid.TimestampFromV1(u1)
t2, _ := uuid.TimestampFromV1(u2)
if t1 == t2 {
return 0
}
if t1 < t2 {
return -1
}
return 1
}
// version
if string(d1) == string(d2.(dosa.UUID)) {
return 0
}
if string(d1) < string(d2.(dosa.UUID)) {
return -1
}
return 1
case string:
if d1 == d2.(string) {
return 0
}
if d1 < d2.(string) {
return -1
}
return 1
case int64:
if d1 == d2.(int64) {
return 0
}
if d1 < d2.(int64) {
return -1
}
return 1
case int32:
if d1 == d2.(int32) {
return 0
}
if d1 < d2.(int32) {
return -1
}
return 1
case float64:
if d1 == d2.(float64) {
return 0
}
if d1 < d2.(float64) {
return -1
}
return 1
case []byte:
c := bytes.Compare(d1, d2.([]byte))
if c == 0 {
return 0
}
if c < 0 {
return -1
}
return 1
case time.Time:
if d1.Equal(d2.(time.Time)) {
return 0
}
if d1.Before(d2.(time.Time)) {
return -1
}
return 1
case bool:
if d1 == d2.(bool) {
return 0
}
if d1 == false {
return -1
}
return 1
}
panic(d1)
} | [
"func",
"compareType",
"(",
"d1",
"dosa",
".",
"FieldValue",
",",
"d2",
"dosa",
".",
"FieldValue",
")",
"int8",
"{",
"switch",
"d1",
":=",
"d1",
".",
"(",
"type",
")",
"{",
"case",
"dosa",
".",
"UUID",
":",
"u1",
":=",
"uuid",
".",
"FromStringOrNil",
"(",
"string",
"(",
"d1",
")",
")",
"\n",
"u2",
":=",
"uuid",
".",
"FromStringOrNil",
"(",
"string",
"(",
"d2",
".",
"(",
"dosa",
".",
"UUID",
")",
")",
")",
"\n",
"if",
"u1",
".",
"Version",
"(",
")",
"!=",
"u2",
".",
"Version",
"(",
")",
"{",
"if",
"u1",
".",
"Version",
"(",
")",
"<",
"u2",
".",
"Version",
"(",
")",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"}",
"\n",
"if",
"u1",
".",
"Version",
"(",
")",
"==",
"1",
"{",
"// compare time UUIDs",
"t1",
",",
"_",
":=",
"uuid",
".",
"TimestampFromV1",
"(",
"u1",
")",
"\n",
"t2",
",",
"_",
":=",
"uuid",
".",
"TimestampFromV1",
"(",
"u2",
")",
"\n",
"if",
"t1",
"==",
"t2",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"t1",
"<",
"t2",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"}",
"\n\n",
"// version",
"if",
"string",
"(",
"d1",
")",
"==",
"string",
"(",
"d2",
".",
"(",
"dosa",
".",
"UUID",
")",
")",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"string",
"(",
"d1",
")",
"<",
"string",
"(",
"d2",
".",
"(",
"dosa",
".",
"UUID",
")",
")",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"case",
"string",
":",
"if",
"d1",
"==",
"d2",
".",
"(",
"string",
")",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"d1",
"<",
"d2",
".",
"(",
"string",
")",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"case",
"int64",
":",
"if",
"d1",
"==",
"d2",
".",
"(",
"int64",
")",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"d1",
"<",
"d2",
".",
"(",
"int64",
")",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"case",
"int32",
":",
"if",
"d1",
"==",
"d2",
".",
"(",
"int32",
")",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"d1",
"<",
"d2",
".",
"(",
"int32",
")",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"case",
"float64",
":",
"if",
"d1",
"==",
"d2",
".",
"(",
"float64",
")",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"d1",
"<",
"d2",
".",
"(",
"float64",
")",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"case",
"[",
"]",
"byte",
":",
"c",
":=",
"bytes",
".",
"Compare",
"(",
"d1",
",",
"d2",
".",
"(",
"[",
"]",
"byte",
")",
")",
"\n",
"if",
"c",
"==",
"0",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"c",
"<",
"0",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"case",
"time",
".",
"Time",
":",
"if",
"d1",
".",
"Equal",
"(",
"d2",
".",
"(",
"time",
".",
"Time",
")",
")",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"d1",
".",
"Before",
"(",
"d2",
".",
"(",
"time",
".",
"Time",
")",
")",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"case",
"bool",
":",
"if",
"d1",
"==",
"d2",
".",
"(",
"bool",
")",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"d1",
"==",
"false",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"}",
"\n",
"panic",
"(",
"d1",
")",
"\n",
"}"
] | // compareType compares a single DOSA field based on the type. This code assumes the types of each
// of the columns are the same, or it will panic | [
"compareType",
"compares",
"a",
"single",
"DOSA",
"field",
"based",
"on",
"the",
"type",
".",
"This",
"code",
"assumes",
"the",
"types",
"of",
"each",
"of",
"the",
"columns",
"are",
"the",
"same",
"or",
"it",
"will",
"panic"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L161-L252 |
4,125 | uber-go/dosa | connectors/memory/memory.go | Read | func (c *Connector) Read(_ context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue, minimumFields []string) (map[string]dosa.FieldValue, error) {
c.lock.RLock()
defer c.lock.RUnlock()
entityRef := c.data[ei.Def.Name]
encodedPartitionKey, err := partitionKeyBuilder(ei.Def.Key, values)
if err != nil {
return nil, errors.Wrapf(err, "Cannot build partition key for entity %q", ei.Def.Name)
}
if c.data[ei.Def.Name] == nil {
return nil, &dosa.ErrNotFound{}
}
partitionRef := entityRef[encodedPartitionKey]
// no data in this partition? easy out!
if len(partitionRef) == 0 {
return nil, &dosa.ErrNotFound{}
}
if len(ei.Def.Key.ClusteringKeySet()) == 0 {
return copyRow(partitionRef[0]), nil
}
// clustering key, search for the value in the set
found, inx := findInsertionPoint(ei.Def.Key, partitionRef, values)
if !found {
return nil, &dosa.ErrNotFound{}
}
return copyRow(partitionRef[inx]), nil
} | go | func (c *Connector) Read(_ context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue, minimumFields []string) (map[string]dosa.FieldValue, error) {
c.lock.RLock()
defer c.lock.RUnlock()
entityRef := c.data[ei.Def.Name]
encodedPartitionKey, err := partitionKeyBuilder(ei.Def.Key, values)
if err != nil {
return nil, errors.Wrapf(err, "Cannot build partition key for entity %q", ei.Def.Name)
}
if c.data[ei.Def.Name] == nil {
return nil, &dosa.ErrNotFound{}
}
partitionRef := entityRef[encodedPartitionKey]
// no data in this partition? easy out!
if len(partitionRef) == 0 {
return nil, &dosa.ErrNotFound{}
}
if len(ei.Def.Key.ClusteringKeySet()) == 0 {
return copyRow(partitionRef[0]), nil
}
// clustering key, search for the value in the set
found, inx := findInsertionPoint(ei.Def.Key, partitionRef, values)
if !found {
return nil, &dosa.ErrNotFound{}
}
return copyRow(partitionRef[inx]), nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Read",
"(",
"_",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"values",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"minimumFields",
"[",
"]",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"error",
")",
"{",
"c",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"entityRef",
":=",
"c",
".",
"data",
"[",
"ei",
".",
"Def",
".",
"Name",
"]",
"\n",
"encodedPartitionKey",
",",
"err",
":=",
"partitionKeyBuilder",
"(",
"ei",
".",
"Def",
".",
"Key",
",",
"values",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"ei",
".",
"Def",
".",
"Name",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"data",
"[",
"ei",
".",
"Def",
".",
"Name",
"]",
"==",
"nil",
"{",
"return",
"nil",
",",
"&",
"dosa",
".",
"ErrNotFound",
"{",
"}",
"\n",
"}",
"\n",
"partitionRef",
":=",
"entityRef",
"[",
"encodedPartitionKey",
"]",
"\n",
"// no data in this partition? easy out!",
"if",
"len",
"(",
"partitionRef",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"&",
"dosa",
".",
"ErrNotFound",
"{",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"ei",
".",
"Def",
".",
"Key",
".",
"ClusteringKeySet",
"(",
")",
")",
"==",
"0",
"{",
"return",
"copyRow",
"(",
"partitionRef",
"[",
"0",
"]",
")",
",",
"nil",
"\n",
"}",
"\n",
"// clustering key, search for the value in the set",
"found",
",",
"inx",
":=",
"findInsertionPoint",
"(",
"ei",
".",
"Def",
".",
"Key",
",",
"partitionRef",
",",
"values",
")",
"\n",
"if",
"!",
"found",
"{",
"return",
"nil",
",",
"&",
"dosa",
".",
"ErrNotFound",
"{",
"}",
"\n",
"}",
"\n",
"return",
"copyRow",
"(",
"partitionRef",
"[",
"inx",
"]",
")",
",",
"nil",
"\n",
"}"
] | // Read searches for a row. First, it finds the partition, then it searches in the partition for
// the data, and returns it when it finds it. Again, sort.Search does most of the heavy lifting
// within a partition | [
"Read",
"searches",
"for",
"a",
"row",
".",
"First",
"it",
"finds",
"the",
"partition",
"then",
"it",
"searches",
"in",
"the",
"partition",
"for",
"the",
"data",
"and",
"returns",
"it",
"when",
"it",
"finds",
"it",
".",
"Again",
"sort",
".",
"Search",
"does",
"most",
"of",
"the",
"heavy",
"lifting",
"within",
"a",
"partition"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L281-L307 |
4,126 | uber-go/dosa | connectors/memory/memory.go | MultiRead | func (c *Connector) MultiRead(ctx context.Context, ei *dosa.EntityInfo, values []map[string]dosa.FieldValue, minimumFields []string) ([]*dosa.FieldValuesOrError, error) {
var fvoes []*dosa.FieldValuesOrError
for _, v := range values {
fieldValue, err := c.Read(ctx, ei, v, minimumFields)
fvoe := &dosa.FieldValuesOrError{}
if err != nil {
fvoe.Error = err
} else {
fvoe.Values = fieldValue
}
fvoes = append(fvoes, fvoe)
}
return fvoes, nil
} | go | func (c *Connector) MultiRead(ctx context.Context, ei *dosa.EntityInfo, values []map[string]dosa.FieldValue, minimumFields []string) ([]*dosa.FieldValuesOrError, error) {
var fvoes []*dosa.FieldValuesOrError
for _, v := range values {
fieldValue, err := c.Read(ctx, ei, v, minimumFields)
fvoe := &dosa.FieldValuesOrError{}
if err != nil {
fvoe.Error = err
} else {
fvoe.Values = fieldValue
}
fvoes = append(fvoes, fvoe)
}
return fvoes, nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"MultiRead",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"values",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"minimumFields",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"dosa",
".",
"FieldValuesOrError",
",",
"error",
")",
"{",
"var",
"fvoes",
"[",
"]",
"*",
"dosa",
".",
"FieldValuesOrError",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"values",
"{",
"fieldValue",
",",
"err",
":=",
"c",
".",
"Read",
"(",
"ctx",
",",
"ei",
",",
"v",
",",
"minimumFields",
")",
"\n",
"fvoe",
":=",
"&",
"dosa",
".",
"FieldValuesOrError",
"{",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fvoe",
".",
"Error",
"=",
"err",
"\n",
"}",
"else",
"{",
"fvoe",
".",
"Values",
"=",
"fieldValue",
"\n",
"}",
"\n\n",
"fvoes",
"=",
"append",
"(",
"fvoes",
",",
"fvoe",
")",
"\n",
"}",
"\n\n",
"return",
"fvoes",
",",
"nil",
"\n",
"}"
] | // MultiRead fetches a series of values at once. | [
"MultiRead",
"fetches",
"a",
"series",
"of",
"values",
"at",
"once",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L310-L325 |
4,127 | uber-go/dosa | connectors/memory/memory.go | MultiUpsert | func (c *Connector) MultiUpsert(ctx context.Context, ei *dosa.EntityInfo, values []map[string]dosa.FieldValue) ([]error, error) {
// Note we do not lock here. This is representative of the behavior one would see in a deployed environment
var errs []error
for _, v := range values {
errs = append(errs, c.Upsert(ctx, ei, v))
}
return errs, nil
} | go | func (c *Connector) MultiUpsert(ctx context.Context, ei *dosa.EntityInfo, values []map[string]dosa.FieldValue) ([]error, error) {
// Note we do not lock here. This is representative of the behavior one would see in a deployed environment
var errs []error
for _, v := range values {
errs = append(errs, c.Upsert(ctx, ei, v))
}
return errs, nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"MultiUpsert",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"values",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"(",
"[",
"]",
"error",
",",
"error",
")",
"{",
"// Note we do not lock here. This is representative of the behavior one would see in a deployed environment",
"var",
"errs",
"[",
"]",
"error",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"values",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"c",
".",
"Upsert",
"(",
"ctx",
",",
"ei",
",",
"v",
")",
")",
"\n",
"}",
"\n\n",
"return",
"errs",
",",
"nil",
"\n",
"}"
] | // MultiUpsert upserts a series of values at once. | [
"MultiUpsert",
"upserts",
"a",
"series",
"of",
"values",
"at",
"once",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L328-L336 |
4,128 | uber-go/dosa | connectors/memory/memory.go | MultiRemove | func (c *Connector) MultiRemove(ctx context.Context, ei *dosa.EntityInfo, multiValues []map[string]dosa.FieldValue) ([]error, error) {
// Note we do not lock here. This is representative of the behavior one would see in a deployed environment
var errs []error
for _, v := range multiValues {
errs = append(errs, c.Remove(ctx, ei, v))
}
return errs, nil
} | go | func (c *Connector) MultiRemove(ctx context.Context, ei *dosa.EntityInfo, multiValues []map[string]dosa.FieldValue) ([]error, error) {
// Note we do not lock here. This is representative of the behavior one would see in a deployed environment
var errs []error
for _, v := range multiValues {
errs = append(errs, c.Remove(ctx, ei, v))
}
return errs, nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"MultiRemove",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"multiValues",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"(",
"[",
"]",
"error",
",",
"error",
")",
"{",
"// Note we do not lock here. This is representative of the behavior one would see in a deployed environment",
"var",
"errs",
"[",
"]",
"error",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"multiValues",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"c",
".",
"Remove",
"(",
"ctx",
",",
"ei",
",",
"v",
")",
")",
"\n",
"}",
"\n\n",
"return",
"errs",
",",
"nil",
"\n",
"}"
] | // MultiRemove removes a series of values at once. | [
"MultiRemove",
"removes",
"a",
"series",
"of",
"values",
"at",
"once",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L339-L347 |
4,129 | uber-go/dosa | connectors/memory/memory.go | Upsert | func (c *Connector) Upsert(_ context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error {
c.lock.Lock()
defer c.lock.Unlock()
valsCopy := copyRow(values)
var oldValues map[string]dosa.FieldValue
var err error
if oldValues, err = c.mergedInsert(ei.Def.Name, ei.Def.Key, valsCopy, overwriteValuesFunc, true); err != nil {
return err
}
for iName, iDef := range ei.Def.Indexes {
if oldValues != nil {
c.removeItem(iName, ei.Def.UniqueKey(iDef.Key), oldValues)
}
_, _ = c.mergedInsert(iName, ei.Def.UniqueKey(iDef.Key), valsCopy, overwriteValuesFunc, false)
}
return nil
} | go | func (c *Connector) Upsert(_ context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error {
c.lock.Lock()
defer c.lock.Unlock()
valsCopy := copyRow(values)
var oldValues map[string]dosa.FieldValue
var err error
if oldValues, err = c.mergedInsert(ei.Def.Name, ei.Def.Key, valsCopy, overwriteValuesFunc, true); err != nil {
return err
}
for iName, iDef := range ei.Def.Indexes {
if oldValues != nil {
c.removeItem(iName, ei.Def.UniqueKey(iDef.Key), oldValues)
}
_, _ = c.mergedInsert(iName, ei.Def.UniqueKey(iDef.Key), valsCopy, overwriteValuesFunc, false)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Upsert",
"(",
"_",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"values",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"error",
"{",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"valsCopy",
":=",
"copyRow",
"(",
"values",
")",
"\n",
"var",
"oldValues",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"\n",
"var",
"err",
"error",
"\n",
"if",
"oldValues",
",",
"err",
"=",
"c",
".",
"mergedInsert",
"(",
"ei",
".",
"Def",
".",
"Name",
",",
"ei",
".",
"Def",
".",
"Key",
",",
"valsCopy",
",",
"overwriteValuesFunc",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"iName",
",",
"iDef",
":=",
"range",
"ei",
".",
"Def",
".",
"Indexes",
"{",
"if",
"oldValues",
"!=",
"nil",
"{",
"c",
".",
"removeItem",
"(",
"iName",
",",
"ei",
".",
"Def",
".",
"UniqueKey",
"(",
"iDef",
".",
"Key",
")",
",",
"oldValues",
")",
"\n",
"}",
"\n",
"_",
",",
"_",
"=",
"c",
".",
"mergedInsert",
"(",
"iName",
",",
"ei",
".",
"Def",
".",
"UniqueKey",
"(",
"iDef",
".",
"Key",
")",
",",
"valsCopy",
",",
"overwriteValuesFunc",
",",
"false",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Upsert works a lot like CreateIfNotExists but merges the data when it finds an existing row | [
"Upsert",
"works",
"a",
"lot",
"like",
"CreateIfNotExists",
"but",
"merges",
"the",
"data",
"when",
"it",
"finds",
"an",
"existing",
"row"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L357-L375 |
4,130 | uber-go/dosa | connectors/memory/memory.go | Remove | func (c *Connector) Remove(_ context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error {
c.lock.Lock()
defer c.lock.Unlock()
if c.data[ei.Def.Name] == nil {
return nil
}
removedValues := c.removeItem(ei.Def.Name, ei.Def.Key, values)
if removedValues != nil {
for iName, iDef := range ei.Def.Indexes {
c.removeItem(iName, ei.Def.UniqueKey(iDef.Key), removedValues)
}
}
return nil
} | go | func (c *Connector) Remove(_ context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error {
c.lock.Lock()
defer c.lock.Unlock()
if c.data[ei.Def.Name] == nil {
return nil
}
removedValues := c.removeItem(ei.Def.Name, ei.Def.Key, values)
if removedValues != nil {
for iName, iDef := range ei.Def.Indexes {
c.removeItem(iName, ei.Def.UniqueKey(iDef.Key), removedValues)
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Remove",
"(",
"_",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"values",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"error",
"{",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"c",
".",
"data",
"[",
"ei",
".",
"Def",
".",
"Name",
"]",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"removedValues",
":=",
"c",
".",
"removeItem",
"(",
"ei",
".",
"Def",
".",
"Name",
",",
"ei",
".",
"Def",
".",
"Key",
",",
"values",
")",
"\n",
"if",
"removedValues",
"!=",
"nil",
"{",
"for",
"iName",
",",
"iDef",
":=",
"range",
"ei",
".",
"Def",
".",
"Indexes",
"{",
"c",
".",
"removeItem",
"(",
"iName",
",",
"ei",
".",
"Def",
".",
"UniqueKey",
"(",
"iDef",
".",
"Key",
")",
",",
"removedValues",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Remove deletes a single row
// There's no way to return an error from this method | [
"Remove",
"deletes",
"a",
"single",
"row",
"There",
"s",
"no",
"way",
"to",
"return",
"an",
"error",
"from",
"this",
"method"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L428-L441 |
4,131 | uber-go/dosa | connectors/memory/memory.go | RemoveRange | func (c *Connector) RemoveRange(_ context.Context, ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition) error {
c.lock.Lock()
defer c.lock.Unlock()
partitionRange, _, err := c.findRange(ei, columnConditions, false)
if err != nil {
return err
}
if partitionRange != nil {
for iName, iDef := range ei.Def.Indexes {
for _, vals := range partitionRange.values() {
c.removeItem(iName, ei.Def.UniqueKey(iDef.Key), vals)
}
}
partitionRange.remove()
}
return nil
} | go | func (c *Connector) RemoveRange(_ context.Context, ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition) error {
c.lock.Lock()
defer c.lock.Unlock()
partitionRange, _, err := c.findRange(ei, columnConditions, false)
if err != nil {
return err
}
if partitionRange != nil {
for iName, iDef := range ei.Def.Indexes {
for _, vals := range partitionRange.values() {
c.removeItem(iName, ei.Def.UniqueKey(iDef.Key), vals)
}
}
partitionRange.remove()
}
return nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"RemoveRange",
"(",
"_",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"columnConditions",
"map",
"[",
"string",
"]",
"[",
"]",
"*",
"dosa",
".",
"Condition",
")",
"error",
"{",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"partitionRange",
",",
"_",
",",
"err",
":=",
"c",
".",
"findRange",
"(",
"ei",
",",
"columnConditions",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"partitionRange",
"!=",
"nil",
"{",
"for",
"iName",
",",
"iDef",
":=",
"range",
"ei",
".",
"Def",
".",
"Indexes",
"{",
"for",
"_",
",",
"vals",
":=",
"range",
"partitionRange",
".",
"values",
"(",
")",
"{",
"c",
".",
"removeItem",
"(",
"iName",
",",
"ei",
".",
"Def",
".",
"UniqueKey",
"(",
"iDef",
".",
"Key",
")",
",",
"vals",
")",
"\n",
"}",
"\n",
"}",
"\n",
"partitionRange",
".",
"remove",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // RemoveRange removes all of the elements in the range specified by the entity info and the column conditions. | [
"RemoveRange",
"removes",
"all",
"of",
"the",
"elements",
"in",
"the",
"range",
"specified",
"by",
"the",
"entity",
"info",
"and",
"the",
"column",
"conditions",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L473-L491 |
4,132 | uber-go/dosa | connectors/memory/memory.go | Range | func (c *Connector) Range(_ context.Context, ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition, minimumFields []string, token string, limit int) ([]map[string]dosa.FieldValue, string, error) {
c.lock.RLock()
defer c.lock.RUnlock()
partitionRange, key, err := c.findRange(ei, columnConditions, true)
if err != nil {
return nil, "", errors.Wrap(err, "Invalid range conditions")
}
if partitionRange == nil {
return []map[string]dosa.FieldValue{}, "", nil
}
if token != "" {
// if we have a token, use it to determine the offset to start from
values, err := decodeToken(token)
if err != nil {
return nil, "", errors.Wrapf(err, "Invalid token %q", token)
}
found, offset := findInsertionPoint(key, partitionRange.values(), values)
if found {
partitionRange.start += offset + 1
} else {
partitionRange.start += offset
}
}
if limit == dosa.AdaptiveRangeLimit {
limit = defaultRangeLimit
}
slice := partitionRange.values()
token = ""
if len(slice) > limit {
token = makeToken(slice[limit-1])
slice = slice[:limit]
}
return copyRows(slice), token, nil
} | go | func (c *Connector) Range(_ context.Context, ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition, minimumFields []string, token string, limit int) ([]map[string]dosa.FieldValue, string, error) {
c.lock.RLock()
defer c.lock.RUnlock()
partitionRange, key, err := c.findRange(ei, columnConditions, true)
if err != nil {
return nil, "", errors.Wrap(err, "Invalid range conditions")
}
if partitionRange == nil {
return []map[string]dosa.FieldValue{}, "", nil
}
if token != "" {
// if we have a token, use it to determine the offset to start from
values, err := decodeToken(token)
if err != nil {
return nil, "", errors.Wrapf(err, "Invalid token %q", token)
}
found, offset := findInsertionPoint(key, partitionRange.values(), values)
if found {
partitionRange.start += offset + 1
} else {
partitionRange.start += offset
}
}
if limit == dosa.AdaptiveRangeLimit {
limit = defaultRangeLimit
}
slice := partitionRange.values()
token = ""
if len(slice) > limit {
token = makeToken(slice[limit-1])
slice = slice[:limit]
}
return copyRows(slice), token, nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Range",
"(",
"_",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"columnConditions",
"map",
"[",
"string",
"]",
"[",
"]",
"*",
"dosa",
".",
"Condition",
",",
"minimumFields",
"[",
"]",
"string",
",",
"token",
"string",
",",
"limit",
"int",
")",
"(",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"string",
",",
"error",
")",
"{",
"c",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"partitionRange",
",",
"key",
",",
"err",
":=",
"c",
".",
"findRange",
"(",
"ei",
",",
"columnConditions",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"partitionRange",
"==",
"nil",
"{",
"return",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"{",
"}",
",",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"token",
"!=",
"\"",
"\"",
"{",
"// if we have a token, use it to determine the offset to start from",
"values",
",",
"err",
":=",
"decodeToken",
"(",
"token",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"token",
")",
"\n",
"}",
"\n",
"found",
",",
"offset",
":=",
"findInsertionPoint",
"(",
"key",
",",
"partitionRange",
".",
"values",
"(",
")",
",",
"values",
")",
"\n",
"if",
"found",
"{",
"partitionRange",
".",
"start",
"+=",
"offset",
"+",
"1",
"\n",
"}",
"else",
"{",
"partitionRange",
".",
"start",
"+=",
"offset",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"limit",
"==",
"dosa",
".",
"AdaptiveRangeLimit",
"{",
"limit",
"=",
"defaultRangeLimit",
"\n",
"}",
"\n\n",
"slice",
":=",
"partitionRange",
".",
"values",
"(",
")",
"\n",
"token",
"=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"slice",
")",
">",
"limit",
"{",
"token",
"=",
"makeToken",
"(",
"slice",
"[",
"limit",
"-",
"1",
"]",
")",
"\n",
"slice",
"=",
"slice",
"[",
":",
"limit",
"]",
"\n",
"}",
"\n\n",
"return",
"copyRows",
"(",
"slice",
")",
",",
"token",
",",
"nil",
"\n",
"}"
] | // Range returns a slice of data from the datastore | [
"Range",
"returns",
"a",
"slice",
"of",
"data",
"from",
"the",
"datastore"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L494-L532 |
4,133 | uber-go/dosa | connectors/memory/memory.go | findRange | func (c *Connector) findRange(ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition, searchIndexes bool) (*partitionRange, *dosa.PrimaryKey, error) {
// no data at all, fine
if c.data[ei.Def.Name] == nil {
return nil, nil, nil
}
// find the equals conditions on each of the partition keys
values := make(map[string]dosa.FieldValue)
// figure out which "table" or "index" to use based on the supplied conditions
name, key, err := ei.IndexFromConditions(columnConditions, searchIndexes)
if err != nil {
return nil, nil, err
}
for _, pk := range key.PartitionKeys {
values[pk] = columnConditions[pk][0].Value
}
entityRef := c.data[name]
// an error is impossible here, since the partition keys must be set from IndexFromConditions
encodedPartitionKey, _ := partitionKeyBuilder(key, values)
partitionRef := entityRef[encodedPartitionKey]
// no data in this partition? easy out!
if len(partitionRef) == 0 {
return nil, nil, nil
}
// hunt through the partitionRef and return values that match search criteria
// TODO: This can be done much faster using a binary search
startinx, endinx := 0, len(partitionRef)-1
for startinx < len(partitionRef) && !matchesClusteringConditions(key, columnConditions, partitionRef[startinx]) {
startinx++
}
for endinx >= startinx && !matchesClusteringConditions(key, columnConditions, partitionRef[endinx]) {
endinx--
}
if endinx < startinx {
return nil, nil, nil
}
return &partitionRange{
entityRef: entityRef,
partitionKey: encodedPartitionKey,
start: startinx,
end: endinx,
}, key, nil
} | go | func (c *Connector) findRange(ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition, searchIndexes bool) (*partitionRange, *dosa.PrimaryKey, error) {
// no data at all, fine
if c.data[ei.Def.Name] == nil {
return nil, nil, nil
}
// find the equals conditions on each of the partition keys
values := make(map[string]dosa.FieldValue)
// figure out which "table" or "index" to use based on the supplied conditions
name, key, err := ei.IndexFromConditions(columnConditions, searchIndexes)
if err != nil {
return nil, nil, err
}
for _, pk := range key.PartitionKeys {
values[pk] = columnConditions[pk][0].Value
}
entityRef := c.data[name]
// an error is impossible here, since the partition keys must be set from IndexFromConditions
encodedPartitionKey, _ := partitionKeyBuilder(key, values)
partitionRef := entityRef[encodedPartitionKey]
// no data in this partition? easy out!
if len(partitionRef) == 0 {
return nil, nil, nil
}
// hunt through the partitionRef and return values that match search criteria
// TODO: This can be done much faster using a binary search
startinx, endinx := 0, len(partitionRef)-1
for startinx < len(partitionRef) && !matchesClusteringConditions(key, columnConditions, partitionRef[startinx]) {
startinx++
}
for endinx >= startinx && !matchesClusteringConditions(key, columnConditions, partitionRef[endinx]) {
endinx--
}
if endinx < startinx {
return nil, nil, nil
}
return &partitionRange{
entityRef: entityRef,
partitionKey: encodedPartitionKey,
start: startinx,
end: endinx,
}, key, nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"findRange",
"(",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"columnConditions",
"map",
"[",
"string",
"]",
"[",
"]",
"*",
"dosa",
".",
"Condition",
",",
"searchIndexes",
"bool",
")",
"(",
"*",
"partitionRange",
",",
"*",
"dosa",
".",
"PrimaryKey",
",",
"error",
")",
"{",
"// no data at all, fine",
"if",
"c",
".",
"data",
"[",
"ei",
".",
"Def",
".",
"Name",
"]",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"// find the equals conditions on each of the partition keys",
"values",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"\n\n",
"// figure out which \"table\" or \"index\" to use based on the supplied conditions",
"name",
",",
"key",
",",
"err",
":=",
"ei",
".",
"IndexFromConditions",
"(",
"columnConditions",
",",
"searchIndexes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"pk",
":=",
"range",
"key",
".",
"PartitionKeys",
"{",
"values",
"[",
"pk",
"]",
"=",
"columnConditions",
"[",
"pk",
"]",
"[",
"0",
"]",
".",
"Value",
"\n",
"}",
"\n\n",
"entityRef",
":=",
"c",
".",
"data",
"[",
"name",
"]",
"\n",
"// an error is impossible here, since the partition keys must be set from IndexFromConditions",
"encodedPartitionKey",
",",
"_",
":=",
"partitionKeyBuilder",
"(",
"key",
",",
"values",
")",
"\n",
"partitionRef",
":=",
"entityRef",
"[",
"encodedPartitionKey",
"]",
"\n",
"// no data in this partition? easy out!",
"if",
"len",
"(",
"partitionRef",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"// hunt through the partitionRef and return values that match search criteria",
"// TODO: This can be done much faster using a binary search",
"startinx",
",",
"endinx",
":=",
"0",
",",
"len",
"(",
"partitionRef",
")",
"-",
"1",
"\n",
"for",
"startinx",
"<",
"len",
"(",
"partitionRef",
")",
"&&",
"!",
"matchesClusteringConditions",
"(",
"key",
",",
"columnConditions",
",",
"partitionRef",
"[",
"startinx",
"]",
")",
"{",
"startinx",
"++",
"\n",
"}",
"\n",
"for",
"endinx",
">=",
"startinx",
"&&",
"!",
"matchesClusteringConditions",
"(",
"key",
",",
"columnConditions",
",",
"partitionRef",
"[",
"endinx",
"]",
")",
"{",
"endinx",
"--",
"\n",
"}",
"\n",
"if",
"endinx",
"<",
"startinx",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"&",
"partitionRange",
"{",
"entityRef",
":",
"entityRef",
",",
"partitionKey",
":",
"encodedPartitionKey",
",",
"start",
":",
"startinx",
",",
"end",
":",
"endinx",
",",
"}",
",",
"key",
",",
"nil",
"\n",
"}"
] | // findRange finds the partitionRange specified by the given entity info and column conditions.
// In the case that no entities are found an empty partitionRange with a nil partition field will be returned.
//
// Note that this function reads from the connector's data map. Any calling functions should hold
// at least a read lock on the map. | [
"findRange",
"finds",
"the",
"partitionRange",
"specified",
"by",
"the",
"given",
"entity",
"info",
"and",
"column",
"conditions",
".",
"In",
"the",
"case",
"that",
"no",
"entities",
"are",
"found",
"an",
"empty",
"partitionRange",
"with",
"a",
"nil",
"partition",
"field",
"will",
"be",
"returned",
".",
"Note",
"that",
"this",
"function",
"reads",
"from",
"the",
"connector",
"s",
"data",
"map",
".",
"Any",
"calling",
"functions",
"should",
"hold",
"at",
"least",
"a",
"read",
"lock",
"on",
"the",
"map",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L561-L607 |
4,134 | uber-go/dosa | connectors/memory/memory.go | matchesClusteringConditions | func matchesClusteringConditions(key *dosa.PrimaryKey, columnConditions map[string][]*dosa.Condition, data map[string]dosa.FieldValue) bool {
for _, col := range key.ClusteringKeys {
if conds, ok := columnConditions[col.Name]; ok {
// conditions exist on this clustering key
for _, cond := range conds {
if !passCol(data[col.Name], cond) {
return false
}
}
}
}
return true
} | go | func matchesClusteringConditions(key *dosa.PrimaryKey, columnConditions map[string][]*dosa.Condition, data map[string]dosa.FieldValue) bool {
for _, col := range key.ClusteringKeys {
if conds, ok := columnConditions[col.Name]; ok {
// conditions exist on this clustering key
for _, cond := range conds {
if !passCol(data[col.Name], cond) {
return false
}
}
}
}
return true
} | [
"func",
"matchesClusteringConditions",
"(",
"key",
"*",
"dosa",
".",
"PrimaryKey",
",",
"columnConditions",
"map",
"[",
"string",
"]",
"[",
"]",
"*",
"dosa",
".",
"Condition",
",",
"data",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"bool",
"{",
"for",
"_",
",",
"col",
":=",
"range",
"key",
".",
"ClusteringKeys",
"{",
"if",
"conds",
",",
"ok",
":=",
"columnConditions",
"[",
"col",
".",
"Name",
"]",
";",
"ok",
"{",
"// conditions exist on this clustering key",
"for",
"_",
",",
"cond",
":=",
"range",
"conds",
"{",
"if",
"!",
"passCol",
"(",
"data",
"[",
"col",
".",
"Name",
"]",
",",
"cond",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // matchesClusteringConditions checks if a data row matches the conditions in the columnConditions that apply to
// clustering columns. If a condition does NOT match, it returns false, otherwise true
// This function is pretty fast if there are no conditions on the clustering columns | [
"matchesClusteringConditions",
"checks",
"if",
"a",
"data",
"row",
"matches",
"the",
"conditions",
"in",
"the",
"columnConditions",
"that",
"apply",
"to",
"clustering",
"columns",
".",
"If",
"a",
"condition",
"does",
"NOT",
"match",
"it",
"returns",
"false",
"otherwise",
"true",
"This",
"function",
"is",
"pretty",
"fast",
"if",
"there",
"are",
"no",
"conditions",
"on",
"the",
"clustering",
"columns"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L612-L624 |
4,135 | uber-go/dosa | connectors/memory/memory.go | passCol | func passCol(data dosa.FieldValue, cond *dosa.Condition) bool {
cmp := compareType(data, cond.Value)
switch cond.Op {
case dosa.Eq:
return cmp == 0
case dosa.Gt:
return cmp > 0
case dosa.GtOrEq:
return cmp >= 0
case dosa.Lt:
return cmp < 0
case dosa.LtOrEq:
return cmp <= 0
}
panic("invalid operator " + cond.Op.String())
} | go | func passCol(data dosa.FieldValue, cond *dosa.Condition) bool {
cmp := compareType(data, cond.Value)
switch cond.Op {
case dosa.Eq:
return cmp == 0
case dosa.Gt:
return cmp > 0
case dosa.GtOrEq:
return cmp >= 0
case dosa.Lt:
return cmp < 0
case dosa.LtOrEq:
return cmp <= 0
}
panic("invalid operator " + cond.Op.String())
} | [
"func",
"passCol",
"(",
"data",
"dosa",
".",
"FieldValue",
",",
"cond",
"*",
"dosa",
".",
"Condition",
")",
"bool",
"{",
"cmp",
":=",
"compareType",
"(",
"data",
",",
"cond",
".",
"Value",
")",
"\n",
"switch",
"cond",
".",
"Op",
"{",
"case",
"dosa",
".",
"Eq",
":",
"return",
"cmp",
"==",
"0",
"\n",
"case",
"dosa",
".",
"Gt",
":",
"return",
"cmp",
">",
"0",
"\n",
"case",
"dosa",
".",
"GtOrEq",
":",
"return",
"cmp",
">=",
"0",
"\n",
"case",
"dosa",
".",
"Lt",
":",
"return",
"cmp",
"<",
"0",
"\n",
"case",
"dosa",
".",
"LtOrEq",
":",
"return",
"cmp",
"<=",
"0",
"\n",
"}",
"\n",
"panic",
"(",
"\"",
"\"",
"+",
"cond",
".",
"Op",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // passCol checks if a column passes a specific condition | [
"passCol",
"checks",
"if",
"a",
"column",
"passes",
"a",
"specific",
"condition"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L627-L642 |
4,136 | uber-go/dosa | connectors/memory/memory.go | Scan | func (c *Connector) Scan(_ context.Context, ei *dosa.EntityInfo, minimumFields []string, token string, limit int) ([]map[string]dosa.FieldValue, string, error) {
c.lock.RLock()
defer c.lock.RUnlock()
if c.data[ei.Def.Name] == nil {
return []map[string]dosa.FieldValue{}, "", nil
}
entityRef := c.data[ei.Def.Name]
allTheThings := make([]map[string]dosa.FieldValue, 0)
// in order for Scan to be deterministic and continuable, we have
// to sort the primary key references
keys := make([]string, 0, len(entityRef))
for key := range entityRef {
keys = append(keys, key)
}
sort.Strings(keys)
// if there was a token, decode it so we can determine the starting
// partition key
startPartKey, start, err := getStartingPoint(ei, token)
if err != nil {
return nil, "", errors.Wrapf(err, "Invalid token %s", token)
}
for _, key := range keys {
if startPartKey != "" {
// had a token, so we need to either partially skip or fully skip
// depending on whether we found the token's partition key yet
if key == startPartKey {
// we reached the starting partition key, so stop skipping
// future values, and add a portion of this one to the set
startPartKey = ""
found, offset := findInsertionPoint(ei.Def.Key, entityRef[key], start)
if found {
offset++
}
allTheThings = append(allTheThings, entityRef[key][offset:]...)
} // else keep looking for this partition key
continue
}
allTheThings = append(allTheThings, entityRef[key]...)
}
if len(allTheThings) == 0 {
return []map[string]dosa.FieldValue{}, "", nil
}
// see if we need a token to return
token = ""
if len(allTheThings) > limit {
token = makeToken(allTheThings[limit-1])
allTheThings = allTheThings[:limit]
}
return copyRows(allTheThings), token, nil
} | go | func (c *Connector) Scan(_ context.Context, ei *dosa.EntityInfo, minimumFields []string, token string, limit int) ([]map[string]dosa.FieldValue, string, error) {
c.lock.RLock()
defer c.lock.RUnlock()
if c.data[ei.Def.Name] == nil {
return []map[string]dosa.FieldValue{}, "", nil
}
entityRef := c.data[ei.Def.Name]
allTheThings := make([]map[string]dosa.FieldValue, 0)
// in order for Scan to be deterministic and continuable, we have
// to sort the primary key references
keys := make([]string, 0, len(entityRef))
for key := range entityRef {
keys = append(keys, key)
}
sort.Strings(keys)
// if there was a token, decode it so we can determine the starting
// partition key
startPartKey, start, err := getStartingPoint(ei, token)
if err != nil {
return nil, "", errors.Wrapf(err, "Invalid token %s", token)
}
for _, key := range keys {
if startPartKey != "" {
// had a token, so we need to either partially skip or fully skip
// depending on whether we found the token's partition key yet
if key == startPartKey {
// we reached the starting partition key, so stop skipping
// future values, and add a portion of this one to the set
startPartKey = ""
found, offset := findInsertionPoint(ei.Def.Key, entityRef[key], start)
if found {
offset++
}
allTheThings = append(allTheThings, entityRef[key][offset:]...)
} // else keep looking for this partition key
continue
}
allTheThings = append(allTheThings, entityRef[key]...)
}
if len(allTheThings) == 0 {
return []map[string]dosa.FieldValue{}, "", nil
}
// see if we need a token to return
token = ""
if len(allTheThings) > limit {
token = makeToken(allTheThings[limit-1])
allTheThings = allTheThings[:limit]
}
return copyRows(allTheThings), token, nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Scan",
"(",
"_",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"minimumFields",
"[",
"]",
"string",
",",
"token",
"string",
",",
"limit",
"int",
")",
"(",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"string",
",",
"error",
")",
"{",
"c",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"c",
".",
"data",
"[",
"ei",
".",
"Def",
".",
"Name",
"]",
"==",
"nil",
"{",
"return",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"{",
"}",
",",
"\"",
"\"",
",",
"nil",
"\n\n",
"}",
"\n",
"entityRef",
":=",
"c",
".",
"data",
"[",
"ei",
".",
"Def",
".",
"Name",
"]",
"\n",
"allTheThings",
":=",
"make",
"(",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"0",
")",
"\n\n",
"// in order for Scan to be deterministic and continuable, we have",
"// to sort the primary key references",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"entityRef",
")",
")",
"\n",
"for",
"key",
":=",
"range",
"entityRef",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"key",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"keys",
")",
"\n\n",
"// if there was a token, decode it so we can determine the starting",
"// partition key",
"startPartKey",
",",
"start",
",",
"err",
":=",
"getStartingPoint",
"(",
"ei",
",",
"token",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"token",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"key",
":=",
"range",
"keys",
"{",
"if",
"startPartKey",
"!=",
"\"",
"\"",
"{",
"// had a token, so we need to either partially skip or fully skip",
"// depending on whether we found the token's partition key yet",
"if",
"key",
"==",
"startPartKey",
"{",
"// we reached the starting partition key, so stop skipping",
"// future values, and add a portion of this one to the set",
"startPartKey",
"=",
"\"",
"\"",
"\n",
"found",
",",
"offset",
":=",
"findInsertionPoint",
"(",
"ei",
".",
"Def",
".",
"Key",
",",
"entityRef",
"[",
"key",
"]",
",",
"start",
")",
"\n",
"if",
"found",
"{",
"offset",
"++",
"\n",
"}",
"\n",
"allTheThings",
"=",
"append",
"(",
"allTheThings",
",",
"entityRef",
"[",
"key",
"]",
"[",
"offset",
":",
"]",
"...",
")",
"\n",
"}",
"// else keep looking for this partition key",
"\n",
"continue",
"\n",
"}",
"\n",
"allTheThings",
"=",
"append",
"(",
"allTheThings",
",",
"entityRef",
"[",
"key",
"]",
"...",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"allTheThings",
")",
"==",
"0",
"{",
"return",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"{",
"}",
",",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"// see if we need a token to return",
"token",
"=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"allTheThings",
")",
">",
"limit",
"{",
"token",
"=",
"makeToken",
"(",
"allTheThings",
"[",
"limit",
"-",
"1",
"]",
")",
"\n",
"allTheThings",
"=",
"allTheThings",
"[",
":",
"limit",
"]",
"\n",
"}",
"\n",
"return",
"copyRows",
"(",
"allTheThings",
")",
",",
"token",
",",
"nil",
"\n",
"}"
] | // Scan returns all the rows | [
"Scan",
"returns",
"all",
"the",
"rows"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L645-L698 |
4,137 | uber-go/dosa | connectors/memory/memory.go | getStartingPoint | func getStartingPoint(ei *dosa.EntityInfo, token string) (start string, startPartKey map[string]dosa.FieldValue, err error) {
if token == "" {
return "", map[string]dosa.FieldValue{}, nil
}
startPartKey, err = decodeToken(token)
if err != nil {
return "", map[string]dosa.FieldValue{}, errors.Wrapf(err, "Invalid token %q", token)
}
start, err = partitionKeyBuilder(ei.Def.Key, startPartKey)
if err != nil {
return "", map[string]dosa.FieldValue{}, errors.Wrapf(err, "Can't build partition key for %q", ei.Def.Name)
}
return start, startPartKey, nil
} | go | func getStartingPoint(ei *dosa.EntityInfo, token string) (start string, startPartKey map[string]dosa.FieldValue, err error) {
if token == "" {
return "", map[string]dosa.FieldValue{}, nil
}
startPartKey, err = decodeToken(token)
if err != nil {
return "", map[string]dosa.FieldValue{}, errors.Wrapf(err, "Invalid token %q", token)
}
start, err = partitionKeyBuilder(ei.Def.Key, startPartKey)
if err != nil {
return "", map[string]dosa.FieldValue{}, errors.Wrapf(err, "Can't build partition key for %q", ei.Def.Name)
}
return start, startPartKey, nil
} | [
"func",
"getStartingPoint",
"(",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"token",
"string",
")",
"(",
"start",
"string",
",",
"startPartKey",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"err",
"error",
")",
"{",
"if",
"token",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n",
"startPartKey",
",",
"err",
"=",
"decodeToken",
"(",
"token",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"{",
"}",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"token",
")",
"\n",
"}",
"\n",
"start",
",",
"err",
"=",
"partitionKeyBuilder",
"(",
"ei",
".",
"Def",
".",
"Key",
",",
"startPartKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"{",
"}",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"ei",
".",
"Def",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"start",
",",
"startPartKey",
",",
"nil",
"\n",
"}"
] | // getStartingPoint determines the partition key of the starting point to resume a scan
// when a token is provided | [
"getStartingPoint",
"determines",
"the",
"partition",
"key",
"of",
"the",
"starting",
"point",
"to",
"resume",
"a",
"scan",
"when",
"a",
"token",
"is",
"provided"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L702-L715 |
4,138 | uber-go/dosa | connectors/memory/memory.go | Shutdown | func (c *Connector) Shutdown() error {
c.lock.Lock()
defer c.lock.Unlock()
c.data = nil
return nil
} | go | func (c *Connector) Shutdown() error {
c.lock.Lock()
defer c.lock.Unlock()
c.data = nil
return nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Shutdown",
"(",
")",
"error",
"{",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"data",
"=",
"nil",
"\n",
"return",
"nil",
"\n",
"}"
] | // Shutdown deletes all the data | [
"Shutdown",
"deletes",
"all",
"the",
"data"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L724-L729 |
4,139 | uber-go/dosa | connectors/memory/memory.go | NewConnector | func NewConnector() *Connector {
c := Connector{}
c.data = make(map[string]map[string][]map[string]dosa.FieldValue)
return &c
} | go | func NewConnector() *Connector {
c := Connector{}
c.data = make(map[string]map[string][]map[string]dosa.FieldValue)
return &c
} | [
"func",
"NewConnector",
"(",
")",
"*",
"Connector",
"{",
"c",
":=",
"Connector",
"{",
"}",
"\n",
"c",
".",
"data",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"\n",
"return",
"&",
"c",
"\n",
"}"
] | // NewConnector creates a new in-memory connector | [
"NewConnector",
"creates",
"a",
"new",
"in",
"-",
"memory",
"connector"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/memory/memory.go#L732-L736 |
4,140 | uber-go/dosa | connectors/redis/redis.go | NewConnector | func NewConnector(config Config, scope metrics.Scope) dosa.Connector {
return &Connector{
client: NewRedigoClient(config.ServerSettings, scope),
ttl: config.TTL,
stats: metrics.CheckIfNilStats(scope),
keyPrefix: config.KeyPrefix,
}
} | go | func NewConnector(config Config, scope metrics.Scope) dosa.Connector {
return &Connector{
client: NewRedigoClient(config.ServerSettings, scope),
ttl: config.TTL,
stats: metrics.CheckIfNilStats(scope),
keyPrefix: config.KeyPrefix,
}
} | [
"func",
"NewConnector",
"(",
"config",
"Config",
",",
"scope",
"metrics",
".",
"Scope",
")",
"dosa",
".",
"Connector",
"{",
"return",
"&",
"Connector",
"{",
"client",
":",
"NewRedigoClient",
"(",
"config",
".",
"ServerSettings",
",",
"scope",
")",
",",
"ttl",
":",
"config",
".",
"TTL",
",",
"stats",
":",
"metrics",
".",
"CheckIfNilStats",
"(",
"scope",
")",
",",
"keyPrefix",
":",
"config",
".",
"KeyPrefix",
",",
"}",
"\n",
"}"
] | // NewConnector initializes a Redis Connector | [
"NewConnector",
"initializes",
"a",
"Redis",
"Connector"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/redis/redis.go#L97-L104 |
4,141 | uber-go/dosa | connectors/redis/redis.go | MultiRead | func (c *Connector) MultiRead(ctx context.Context, ei *dosa.EntityInfo, keys []map[string]dosa.FieldValue, minimumFields []string) (results []*dosa.FieldValuesOrError, err error) {
return nil, new(ErrNotImplemented)
} | go | func (c *Connector) MultiRead(ctx context.Context, ei *dosa.EntityInfo, keys []map[string]dosa.FieldValue, minimumFields []string) (results []*dosa.FieldValuesOrError, err error) {
return nil, new(ErrNotImplemented)
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"MultiRead",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"keys",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"minimumFields",
"[",
"]",
"string",
")",
"(",
"results",
"[",
"]",
"*",
"dosa",
".",
"FieldValuesOrError",
",",
"err",
"error",
")",
"{",
"return",
"nil",
",",
"new",
"(",
"ErrNotImplemented",
")",
"\n",
"}"
] | // MultiRead not implemented | [
"MultiRead",
"not",
"implemented"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/redis/redis.go#L121-L123 |
4,142 | uber-go/dosa | connectors/redis/redis.go | MultiUpsert | func (c *Connector) MultiUpsert(ctx context.Context, ei *dosa.EntityInfo, multiValues []map[string]dosa.FieldValue) (result []error, err error) {
return nil, new(ErrNotImplemented)
} | go | func (c *Connector) MultiUpsert(ctx context.Context, ei *dosa.EntityInfo, multiValues []map[string]dosa.FieldValue) (result []error, err error) {
return nil, new(ErrNotImplemented)
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"MultiUpsert",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"multiValues",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"(",
"result",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"return",
"nil",
",",
"new",
"(",
"ErrNotImplemented",
")",
"\n",
"}"
] | // MultiUpsert not implemented | [
"MultiUpsert",
"not",
"implemented"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/redis/redis.go#L126-L128 |
4,143 | uber-go/dosa | connectors/redis/redis.go | Scan | func (c *Connector) Scan(ctx context.Context, ei *dosa.EntityInfo, minimumFields []string, token string, limit int) (multiValues []map[string]dosa.FieldValue, nextToken string, err error) {
return nil, "", new(ErrNotImplemented)
} | go | func (c *Connector) Scan(ctx context.Context, ei *dosa.EntityInfo, minimumFields []string, token string, limit int) (multiValues []map[string]dosa.FieldValue, nextToken string, err error) {
return nil, "", new(ErrNotImplemented)
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Scan",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"minimumFields",
"[",
"]",
"string",
",",
"token",
"string",
",",
"limit",
"int",
")",
"(",
"multiValues",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"nextToken",
"string",
",",
"err",
"error",
")",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"new",
"(",
"ErrNotImplemented",
")",
"\n",
"}"
] | // Scan not implemented. | [
"Scan",
"not",
"implemented",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/redis/redis.go#L146-L148 |
4,144 | uber-go/dosa | connectors/redis/redis.go | Shutdown | func (c *Connector) Shutdown() error {
err := c.client.Shutdown()
c.logCallCount("Shutdown", err)
return err
} | go | func (c *Connector) Shutdown() error {
err := c.client.Shutdown()
c.logCallCount("Shutdown", err)
return err
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Shutdown",
"(",
")",
"error",
"{",
"err",
":=",
"c",
".",
"client",
".",
"Shutdown",
"(",
")",
"\n",
"c",
".",
"logCallCount",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Shutdown not implemented | [
"Shutdown",
"not",
"implemented"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/redis/redis.go#L151-L155 |
4,145 | uber-go/dosa | connectors/redis/redis.go | Read | func (c *Connector) Read(ctx context.Context, ei *dosa.EntityInfo, keys map[string]dosa.FieldValue, fieldsToRead []string) (map[string]dosa.FieldValue, error) {
err := validateSchema(ei)
if err != nil {
return nil, err
}
keyName, valueName := nameOfKeyValue(ei)
cacheKey, err := buildKey(c.keyPrefix, ei.Ref.Scope, ei.Ref.NamePrefix, ei.Def.Name, keys[keyName])
if err != nil {
return nil, err
}
cacheValue, err := c.client.Get(cacheKey)
c.logHitRate("Read", err)
if err != nil {
return nil, err
}
result := make(map[string]dosa.FieldValue)
// Copy original keys into response
for k, v := range keys {
result[k] = v
}
result[valueName] = cacheValue
return result, nil
} | go | func (c *Connector) Read(ctx context.Context, ei *dosa.EntityInfo, keys map[string]dosa.FieldValue, fieldsToRead []string) (map[string]dosa.FieldValue, error) {
err := validateSchema(ei)
if err != nil {
return nil, err
}
keyName, valueName := nameOfKeyValue(ei)
cacheKey, err := buildKey(c.keyPrefix, ei.Ref.Scope, ei.Ref.NamePrefix, ei.Def.Name, keys[keyName])
if err != nil {
return nil, err
}
cacheValue, err := c.client.Get(cacheKey)
c.logHitRate("Read", err)
if err != nil {
return nil, err
}
result := make(map[string]dosa.FieldValue)
// Copy original keys into response
for k, v := range keys {
result[k] = v
}
result[valueName] = cacheValue
return result, nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Read",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"keys",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"fieldsToRead",
"[",
"]",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"error",
")",
"{",
"err",
":=",
"validateSchema",
"(",
"ei",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"keyName",
",",
"valueName",
":=",
"nameOfKeyValue",
"(",
"ei",
")",
"\n\n",
"cacheKey",
",",
"err",
":=",
"buildKey",
"(",
"c",
".",
"keyPrefix",
",",
"ei",
".",
"Ref",
".",
"Scope",
",",
"ei",
".",
"Ref",
".",
"NamePrefix",
",",
"ei",
".",
"Def",
".",
"Name",
",",
"keys",
"[",
"keyName",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cacheValue",
",",
"err",
":=",
"c",
".",
"client",
".",
"Get",
"(",
"cacheKey",
")",
"\n",
"c",
".",
"logHitRate",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"\n",
"// Copy original keys into response",
"for",
"k",
",",
"v",
":=",
"range",
"keys",
"{",
"result",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"result",
"[",
"valueName",
"]",
"=",
"cacheValue",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // Read reads an object based on primary key | [
"Read",
"reads",
"an",
"object",
"based",
"on",
"primary",
"key"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/redis/redis.go#L158-L184 |
4,146 | uber-go/dosa | connectors/redis/redis.go | Upsert | func (c *Connector) Upsert(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error {
err := validateSchema(ei)
if err != nil {
return err
}
keyName, valueName := nameOfKeyValue(ei)
cacheValue, ok := values[valueName]
if !ok || cacheValue == nil {
return NewErrInvalidEntity("No value specified.")
}
cacheValueBytes := cacheValue.([]byte)
if len(cacheValueBytes) == 0 {
return NewErrInvalidEntity("No value specified.")
}
cacheKey, err := buildKey(c.keyPrefix, ei.Ref.Scope, ei.Ref.NamePrefix, ei.Def.Name, values[keyName])
if err != nil {
return err
}
err = c.client.SetEx(cacheKey, cacheValueBytes, c.ttl)
c.logCallCount("Upsert", err)
return err
} | go | func (c *Connector) Upsert(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error {
err := validateSchema(ei)
if err != nil {
return err
}
keyName, valueName := nameOfKeyValue(ei)
cacheValue, ok := values[valueName]
if !ok || cacheValue == nil {
return NewErrInvalidEntity("No value specified.")
}
cacheValueBytes := cacheValue.([]byte)
if len(cacheValueBytes) == 0 {
return NewErrInvalidEntity("No value specified.")
}
cacheKey, err := buildKey(c.keyPrefix, ei.Ref.Scope, ei.Ref.NamePrefix, ei.Def.Name, values[keyName])
if err != nil {
return err
}
err = c.client.SetEx(cacheKey, cacheValueBytes, c.ttl)
c.logCallCount("Upsert", err)
return err
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Upsert",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"values",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"error",
"{",
"err",
":=",
"validateSchema",
"(",
"ei",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"keyName",
",",
"valueName",
":=",
"nameOfKeyValue",
"(",
"ei",
")",
"\n\n",
"cacheValue",
",",
"ok",
":=",
"values",
"[",
"valueName",
"]",
"\n",
"if",
"!",
"ok",
"||",
"cacheValue",
"==",
"nil",
"{",
"return",
"NewErrInvalidEntity",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"cacheValueBytes",
":=",
"cacheValue",
".",
"(",
"[",
"]",
"byte",
")",
"\n",
"if",
"len",
"(",
"cacheValueBytes",
")",
"==",
"0",
"{",
"return",
"NewErrInvalidEntity",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"cacheKey",
",",
"err",
":=",
"buildKey",
"(",
"c",
".",
"keyPrefix",
",",
"ei",
".",
"Ref",
".",
"Scope",
",",
"ei",
".",
"Ref",
".",
"NamePrefix",
",",
"ei",
".",
"Def",
".",
"Name",
",",
"values",
"[",
"keyName",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"c",
".",
"client",
".",
"SetEx",
"(",
"cacheKey",
",",
"cacheValueBytes",
",",
"c",
".",
"ttl",
")",
"\n",
"c",
".",
"logCallCount",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Upsert means update an existing object or create a new object | [
"Upsert",
"means",
"update",
"an",
"existing",
"object",
"or",
"create",
"a",
"new",
"object"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/redis/redis.go#L187-L213 |
4,147 | uber-go/dosa | connectors/redis/redis.go | Remove | func (c *Connector) Remove(ctx context.Context, ei *dosa.EntityInfo, keys map[string]dosa.FieldValue) error {
err := validateSchema(ei)
if err != nil {
return err
}
keyName, _ := nameOfKeyValue(ei)
cacheKey, err := buildKey(c.keyPrefix, ei.Ref.Scope, ei.Ref.NamePrefix, ei.Def.Name, keys[keyName])
if err != nil {
return err
}
err = c.client.Del(cacheKey)
c.logCallCount("Remove", err)
return err
} | go | func (c *Connector) Remove(ctx context.Context, ei *dosa.EntityInfo, keys map[string]dosa.FieldValue) error {
err := validateSchema(ei)
if err != nil {
return err
}
keyName, _ := nameOfKeyValue(ei)
cacheKey, err := buildKey(c.keyPrefix, ei.Ref.Scope, ei.Ref.NamePrefix, ei.Def.Name, keys[keyName])
if err != nil {
return err
}
err = c.client.Del(cacheKey)
c.logCallCount("Remove", err)
return err
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Remove",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"keys",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"error",
"{",
"err",
":=",
"validateSchema",
"(",
"ei",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"keyName",
",",
"_",
":=",
"nameOfKeyValue",
"(",
"ei",
")",
"\n",
"cacheKey",
",",
"err",
":=",
"buildKey",
"(",
"c",
".",
"keyPrefix",
",",
"ei",
".",
"Ref",
".",
"Scope",
",",
"ei",
".",
"Ref",
".",
"NamePrefix",
",",
"ei",
".",
"Def",
".",
"Name",
",",
"keys",
"[",
"keyName",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"c",
".",
"client",
".",
"Del",
"(",
"cacheKey",
")",
"\n",
"c",
".",
"logCallCount",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Remove deletes a key | [
"Remove",
"deletes",
"a",
"key"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/redis/redis.go#L216-L230 |
4,148 | uber-go/dosa | connectors/redis/redis.go | nameOfKeyValue | func nameOfKeyValue(ei *dosa.EntityInfo) (string, string) {
keyName := ei.Def.Key.PartitionKeys[0]
cols := ei.Def.Columns
if cols[0].Name == keyName {
return keyName, cols[1].Name
}
return keyName, cols[0].Name
} | go | func nameOfKeyValue(ei *dosa.EntityInfo) (string, string) {
keyName := ei.Def.Key.PartitionKeys[0]
cols := ei.Def.Columns
if cols[0].Name == keyName {
return keyName, cols[1].Name
}
return keyName, cols[0].Name
} | [
"func",
"nameOfKeyValue",
"(",
"ei",
"*",
"dosa",
".",
"EntityInfo",
")",
"(",
"string",
",",
"string",
")",
"{",
"keyName",
":=",
"ei",
".",
"Def",
".",
"Key",
".",
"PartitionKeys",
"[",
"0",
"]",
"\n",
"cols",
":=",
"ei",
".",
"Def",
".",
"Columns",
"\n",
"if",
"cols",
"[",
"0",
"]",
".",
"Name",
"==",
"keyName",
"{",
"return",
"keyName",
",",
"cols",
"[",
"1",
"]",
".",
"Name",
"\n",
"}",
"\n",
"return",
"keyName",
",",
"cols",
"[",
"0",
"]",
".",
"Name",
"\n",
"}"
] | // return order is key, value | [
"return",
"order",
"is",
"key",
"value"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/redis/redis.go#L253-L260 |
4,149 | uber-go/dosa | cmd/dosa/query.go | Execute | func (c *QueryRead) Execute(args []string) error {
return c.doQueryOp(ShellQueryClient.Read, c.Args.EntityName, c.Args.Queries, 1)
} | go | func (c *QueryRead) Execute(args []string) error {
return c.doQueryOp(ShellQueryClient.Read, c.Args.EntityName, c.Args.Queries, 1)
} | [
"func",
"(",
"c",
"*",
"QueryRead",
")",
"Execute",
"(",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"return",
"c",
".",
"doQueryOp",
"(",
"ShellQueryClient",
".",
"Read",
",",
"c",
".",
"Args",
".",
"EntityName",
",",
"c",
".",
"Args",
".",
"Queries",
",",
"1",
")",
"\n",
"}"
] | // Execute executes a read query command | [
"Execute",
"executes",
"a",
"read",
"query",
"command"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/query.go#L130-L132 |
4,150 | uber-go/dosa | cmd/dosa/query.go | Execute | func (c *QueryRange) Execute(args []string) error {
return c.doQueryOp(ShellQueryClient.Range, c.Args.EntityName, c.Args.Queries, c.Limit)
} | go | func (c *QueryRange) Execute(args []string) error {
return c.doQueryOp(ShellQueryClient.Range, c.Args.EntityName, c.Args.Queries, c.Limit)
} | [
"func",
"(",
"c",
"*",
"QueryRange",
")",
"Execute",
"(",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"return",
"c",
".",
"doQueryOp",
"(",
"ShellQueryClient",
".",
"Range",
",",
"c",
".",
"Args",
".",
"EntityName",
",",
"c",
".",
"Args",
".",
"Queries",
",",
"c",
".",
"Limit",
")",
"\n",
"}"
] | // Execute executes a range query command | [
"Execute",
"executes",
"a",
"range",
"query",
"command"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/query.go#L153-L155 |
4,151 | uber-go/dosa | cmd/dosa/util.go | parseQuery | func parseQuery(exps []string) ([]*queryObj, error) {
queries := make([]*queryObj, len(exps))
for idx, exp := range exps {
strs := strings.SplitN(exp, ":", 3)
if len(strs) != 3 {
return nil, errors.Errorf("query expression should be in the form field:op:value")
}
queries[idx] = newQueryObj(strs[0], strs[1], strs[2])
}
return queries, nil
} | go | func parseQuery(exps []string) ([]*queryObj, error) {
queries := make([]*queryObj, len(exps))
for idx, exp := range exps {
strs := strings.SplitN(exp, ":", 3)
if len(strs) != 3 {
return nil, errors.Errorf("query expression should be in the form field:op:value")
}
queries[idx] = newQueryObj(strs[0], strs[1], strs[2])
}
return queries, nil
} | [
"func",
"parseQuery",
"(",
"exps",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"queryObj",
",",
"error",
")",
"{",
"queries",
":=",
"make",
"(",
"[",
"]",
"*",
"queryObj",
",",
"len",
"(",
"exps",
")",
")",
"\n",
"for",
"idx",
",",
"exp",
":=",
"range",
"exps",
"{",
"strs",
":=",
"strings",
".",
"SplitN",
"(",
"exp",
",",
"\"",
"\"",
",",
"3",
")",
"\n",
"if",
"len",
"(",
"strs",
")",
"!=",
"3",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"queries",
"[",
"idx",
"]",
"=",
"newQueryObj",
"(",
"strs",
"[",
"0",
"]",
",",
"strs",
"[",
"1",
"]",
",",
"strs",
"[",
"2",
"]",
")",
"\n",
"}",
"\n",
"return",
"queries",
",",
"nil",
"\n",
"}"
] | // parseQuery parses the input query expressions | [
"parseQuery",
"parses",
"the",
"input",
"query",
"expressions"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/util.go#L38-L48 |
4,152 | uber-go/dosa | cmd/dosa/util.go | setQueryFieldValues | func setQueryFieldValues(queries []*queryObj, re *dosa.RegisteredEntity) ([]*queryObj, error) {
cts := re.EntityDefinition().ColumnTypes()
for _, query := range queries {
// convert field name to column name, ColumnNames method will return error if field name not found
cols, err := re.ColumnNames([]string{query.fieldName})
if err != nil {
return nil, err
}
query.colName = cols[0]
if typ, ok := cts[cols[0]]; ok {
fv, err := strToFieldValue(typ, query.valueStr)
if err != nil {
return nil, err
}
query.value = fv
} else {
return nil, errors.Errorf("cannot find the type of column %s", cols[0])
}
}
return queries, nil
} | go | func setQueryFieldValues(queries []*queryObj, re *dosa.RegisteredEntity) ([]*queryObj, error) {
cts := re.EntityDefinition().ColumnTypes()
for _, query := range queries {
// convert field name to column name, ColumnNames method will return error if field name not found
cols, err := re.ColumnNames([]string{query.fieldName})
if err != nil {
return nil, err
}
query.colName = cols[0]
if typ, ok := cts[cols[0]]; ok {
fv, err := strToFieldValue(typ, query.valueStr)
if err != nil {
return nil, err
}
query.value = fv
} else {
return nil, errors.Errorf("cannot find the type of column %s", cols[0])
}
}
return queries, nil
} | [
"func",
"setQueryFieldValues",
"(",
"queries",
"[",
"]",
"*",
"queryObj",
",",
"re",
"*",
"dosa",
".",
"RegisteredEntity",
")",
"(",
"[",
"]",
"*",
"queryObj",
",",
"error",
")",
"{",
"cts",
":=",
"re",
".",
"EntityDefinition",
"(",
")",
".",
"ColumnTypes",
"(",
")",
"\n",
"for",
"_",
",",
"query",
":=",
"range",
"queries",
"{",
"// convert field name to column name, ColumnNames method will return error if field name not found",
"cols",
",",
"err",
":=",
"re",
".",
"ColumnNames",
"(",
"[",
"]",
"string",
"{",
"query",
".",
"fieldName",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"query",
".",
"colName",
"=",
"cols",
"[",
"0",
"]",
"\n",
"if",
"typ",
",",
"ok",
":=",
"cts",
"[",
"cols",
"[",
"0",
"]",
"]",
";",
"ok",
"{",
"fv",
",",
"err",
":=",
"strToFieldValue",
"(",
"typ",
",",
"query",
".",
"valueStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"query",
".",
"value",
"=",
"fv",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cols",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"queries",
",",
"nil",
"\n",
"}"
] | // setQueryFieldValues sets the value field of queryObj | [
"setQueryFieldValues",
"sets",
"the",
"value",
"field",
"of",
"queryObj"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/util.go#L51-L71 |
4,153 | uber-go/dosa | cmd/dosa/util.go | strToFieldValue | func strToFieldValue(t dosa.Type, s string) (dosa.FieldValue, error) {
switch t {
case dosa.Int32:
i, err := strconv.ParseInt(s, 10, 32)
if err != nil {
return nil, err
}
return dosa.FieldValue(int32(i)), nil
case dosa.Int64:
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return nil, err
}
return dosa.FieldValue(int64(i)), nil
case dosa.Bool:
b, err := strconv.ParseBool(s)
if err != nil {
return nil, err
}
return dosa.FieldValue(b), nil
case dosa.String:
return dosa.FieldValue(s), nil
case dosa.Double:
d, err := strconv.ParseFloat(s, 64)
if err != nil {
return nil, err
}
return dosa.FieldValue(d), nil
case dosa.Timestamp:
t, err := time.Parse(time.RFC3339Nano, s)
if err != nil {
// check if the input is a unix epoch timestamp
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return nil, errors.Wrapf(err, "timestamp should be in form 2006-01-02T15:04:05.1Z (RFC3339Nano) or Unix epoch time in millisecond")
}
if i < 0 {
return nil, errors.Errorf("timestamp should not be negative")
}
return dosa.FieldValue(time.Unix(0, i*int64(time.Millisecond)).UTC()), nil
}
return dosa.FieldValue(t), nil
case dosa.TUUID:
u := dosa.UUID(s)
return dosa.FieldValue(u), nil
case dosa.Blob:
// TODO: support query with binary arrays
return nil, errors.Errorf("blob query not supported for now")
default:
return nil, errors.Errorf("unsupported type")
}
} | go | func strToFieldValue(t dosa.Type, s string) (dosa.FieldValue, error) {
switch t {
case dosa.Int32:
i, err := strconv.ParseInt(s, 10, 32)
if err != nil {
return nil, err
}
return dosa.FieldValue(int32(i)), nil
case dosa.Int64:
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return nil, err
}
return dosa.FieldValue(int64(i)), nil
case dosa.Bool:
b, err := strconv.ParseBool(s)
if err != nil {
return nil, err
}
return dosa.FieldValue(b), nil
case dosa.String:
return dosa.FieldValue(s), nil
case dosa.Double:
d, err := strconv.ParseFloat(s, 64)
if err != nil {
return nil, err
}
return dosa.FieldValue(d), nil
case dosa.Timestamp:
t, err := time.Parse(time.RFC3339Nano, s)
if err != nil {
// check if the input is a unix epoch timestamp
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return nil, errors.Wrapf(err, "timestamp should be in form 2006-01-02T15:04:05.1Z (RFC3339Nano) or Unix epoch time in millisecond")
}
if i < 0 {
return nil, errors.Errorf("timestamp should not be negative")
}
return dosa.FieldValue(time.Unix(0, i*int64(time.Millisecond)).UTC()), nil
}
return dosa.FieldValue(t), nil
case dosa.TUUID:
u := dosa.UUID(s)
return dosa.FieldValue(u), nil
case dosa.Blob:
// TODO: support query with binary arrays
return nil, errors.Errorf("blob query not supported for now")
default:
return nil, errors.Errorf("unsupported type")
}
} | [
"func",
"strToFieldValue",
"(",
"t",
"dosa",
".",
"Type",
",",
"s",
"string",
")",
"(",
"dosa",
".",
"FieldValue",
",",
"error",
")",
"{",
"switch",
"t",
"{",
"case",
"dosa",
".",
"Int32",
":",
"i",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"s",
",",
"10",
",",
"32",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"dosa",
".",
"FieldValue",
"(",
"int32",
"(",
"i",
")",
")",
",",
"nil",
"\n",
"case",
"dosa",
".",
"Int64",
":",
"i",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"s",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"dosa",
".",
"FieldValue",
"(",
"int64",
"(",
"i",
")",
")",
",",
"nil",
"\n",
"case",
"dosa",
".",
"Bool",
":",
"b",
",",
"err",
":=",
"strconv",
".",
"ParseBool",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"dosa",
".",
"FieldValue",
"(",
"b",
")",
",",
"nil",
"\n",
"case",
"dosa",
".",
"String",
":",
"return",
"dosa",
".",
"FieldValue",
"(",
"s",
")",
",",
"nil",
"\n",
"case",
"dosa",
".",
"Double",
":",
"d",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"(",
"s",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"dosa",
".",
"FieldValue",
"(",
"d",
")",
",",
"nil",
"\n",
"case",
"dosa",
".",
"Timestamp",
":",
"t",
",",
"err",
":=",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC3339Nano",
",",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// check if the input is a unix epoch timestamp",
"i",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"s",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"i",
"<",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"dosa",
".",
"FieldValue",
"(",
"time",
".",
"Unix",
"(",
"0",
",",
"i",
"*",
"int64",
"(",
"time",
".",
"Millisecond",
")",
")",
".",
"UTC",
"(",
")",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"dosa",
".",
"FieldValue",
"(",
"t",
")",
",",
"nil",
"\n",
"case",
"dosa",
".",
"TUUID",
":",
"u",
":=",
"dosa",
".",
"UUID",
"(",
"s",
")",
"\n",
"return",
"dosa",
".",
"FieldValue",
"(",
"u",
")",
",",
"nil",
"\n",
"case",
"dosa",
".",
"Blob",
":",
"// TODO: support query with binary arrays",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // strToFieldValue converts the 'value' of input query expression from string
// to dosa.FieldValue | [
"strToFieldValue",
"converts",
"the",
"value",
"of",
"input",
"query",
"expression",
"from",
"string",
"to",
"dosa",
".",
"FieldValue"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/util.go#L75-L126 |
4,154 | uber-go/dosa | schema/cql/cql.go | typeMap | func typeMap(t dosa.Type) string {
switch t {
case dosa.String:
return "text"
case dosa.Blob:
return "blob"
case dosa.Bool:
return "boolean"
case dosa.Double:
return "double"
case dosa.Int32:
return "int"
case dosa.Int64:
return "bigint"
case dosa.Timestamp:
return "timestamp"
case dosa.TUUID:
return "uuid"
}
return "unknown"
} | go | func typeMap(t dosa.Type) string {
switch t {
case dosa.String:
return "text"
case dosa.Blob:
return "blob"
case dosa.Bool:
return "boolean"
case dosa.Double:
return "double"
case dosa.Int32:
return "int"
case dosa.Int64:
return "bigint"
case dosa.Timestamp:
return "timestamp"
case dosa.TUUID:
return "uuid"
}
return "unknown"
} | [
"func",
"typeMap",
"(",
"t",
"dosa",
".",
"Type",
")",
"string",
"{",
"switch",
"t",
"{",
"case",
"dosa",
".",
"String",
":",
"return",
"\"",
"\"",
"\n",
"case",
"dosa",
".",
"Blob",
":",
"return",
"\"",
"\"",
"\n",
"case",
"dosa",
".",
"Bool",
":",
"return",
"\"",
"\"",
"\n",
"case",
"dosa",
".",
"Double",
":",
"return",
"\"",
"\"",
"\n",
"case",
"dosa",
".",
"Int32",
":",
"return",
"\"",
"\"",
"\n",
"case",
"dosa",
".",
"Int64",
":",
"return",
"\"",
"\"",
"\n",
"case",
"dosa",
".",
"Timestamp",
":",
"return",
"\"",
"\"",
"\n",
"case",
"dosa",
".",
"TUUID",
":",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // typeMap returns the CQL type associated with the given dosa.Type,
// used in the template | [
"typeMap",
"returns",
"the",
"CQL",
"type",
"associated",
"with",
"the",
"given",
"dosa",
".",
"Type",
"used",
"in",
"the",
"template"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/schema/cql/cql.go#L36-L56 |
4,155 | uber-go/dosa | schema/cql/cql.go | ToCQL | func ToCQL(e *dosa.EntityDefinition) string {
var buf bytes.Buffer
// errors are ignored here, they can only happen from an invalid template, which will get caught in tests
err := cqlCreateTableTemplate.Execute(&buf, e)
if err != nil {
panic(err)
}
return buf.String()
} | go | func ToCQL(e *dosa.EntityDefinition) string {
var buf bytes.Buffer
// errors are ignored here, they can only happen from an invalid template, which will get caught in tests
err := cqlCreateTableTemplate.Execute(&buf, e)
if err != nil {
panic(err)
}
return buf.String()
} | [
"func",
"ToCQL",
"(",
"e",
"*",
"dosa",
".",
"EntityDefinition",
")",
"string",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"// errors are ignored here, they can only happen from an invalid template, which will get caught in tests",
"err",
":=",
"cqlCreateTableTemplate",
".",
"Execute",
"(",
"&",
"buf",
",",
"e",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] | // ToCQL generates CQL from an EntityDefinition | [
"ToCQL",
"generates",
"CQL",
"from",
"an",
"EntityDefinition"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/schema/cql/cql.go#L72-L80 |
4,156 | uber-go/dosa | connectors/cache/fallback.go | WithSkipWriteInvalidateEntities | func WithSkipWriteInvalidateEntities(entities ...dosa.DomainObject) Options {
return func(c *Connector) error {
c.skipWriteInvalidateEntitiesMap = createSkipWriteCacheInvalidateSet(entities)
return nil
}
} | go | func WithSkipWriteInvalidateEntities(entities ...dosa.DomainObject) Options {
return func(c *Connector) error {
c.skipWriteInvalidateEntitiesMap = createSkipWriteCacheInvalidateSet(entities)
return nil
}
} | [
"func",
"WithSkipWriteInvalidateEntities",
"(",
"entities",
"...",
"dosa",
".",
"DomainObject",
")",
"Options",
"{",
"return",
"func",
"(",
"c",
"*",
"Connector",
")",
"error",
"{",
"c",
".",
"skipWriteInvalidateEntitiesMap",
"=",
"createSkipWriteCacheInvalidateSet",
"(",
"entities",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithSkipWriteInvalidateEntities provides the option for client to set the entites | [
"WithSkipWriteInvalidateEntities",
"provides",
"the",
"option",
"for",
"client",
"to",
"set",
"the",
"entites"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/cache/fallback.go#L56-L61 |
4,157 | uber-go/dosa | connectors/cache/fallback.go | NewConnector | func NewConnector(origin, fallback dosa.Connector, scope metrics.Scope, entities []dosa.DomainObject, options ...Options) *Connector {
c := newConnector(origin, fallback, scope, encoding.NewGobEncoder(), entities)
for _, option := range options {
err := option(c)
if err != nil {
// It's a no-op when getting an error now
continue
}
}
return c
} | go | func NewConnector(origin, fallback dosa.Connector, scope metrics.Scope, entities []dosa.DomainObject, options ...Options) *Connector {
c := newConnector(origin, fallback, scope, encoding.NewGobEncoder(), entities)
for _, option := range options {
err := option(c)
if err != nil {
// It's a no-op when getting an error now
continue
}
}
return c
} | [
"func",
"NewConnector",
"(",
"origin",
",",
"fallback",
"dosa",
".",
"Connector",
",",
"scope",
"metrics",
".",
"Scope",
",",
"entities",
"[",
"]",
"dosa",
".",
"DomainObject",
",",
"options",
"...",
"Options",
")",
"*",
"Connector",
"{",
"c",
":=",
"newConnector",
"(",
"origin",
",",
"fallback",
",",
"scope",
",",
"encoding",
".",
"NewGobEncoder",
"(",
")",
",",
"entities",
")",
"\n",
"for",
"_",
",",
"option",
":=",
"range",
"options",
"{",
"err",
":=",
"option",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// It's a no-op when getting an error now",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"c",
"\n",
"}"
] | // NewConnector creates a fallback cache connector | [
"NewConnector",
"creates",
"a",
"fallback",
"cache",
"connector"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/cache/fallback.go#L64-L74 |
4,158 | uber-go/dosa | connectors/cache/fallback.go | read | func (c *Connector) read(
ctx context.Context,
ei *dosa.EntityInfo,
keys map[string]dosa.FieldValue,
source map[string]dosa.FieldValue,
sourceErr error,
methodName string,
) (values map[string]dosa.FieldValue, err error) {
if dosa.ErrorIsNotFound(sourceErr) {
return source, sourceErr
}
ckey := createCacheKey(ei, keys)
value, err := c.getValueFromFallback(ctx, ei, ckey)
c.logFallback(methodName, ei.Def.Name, err)
if err != nil {
return source, sourceErr
}
result := map[string]dosa.FieldValue{}
err = c.encoder.Decode(value, &result)
if err != nil {
return source, sourceErr
}
return rawRowAsPointers(ei, result), err
} | go | func (c *Connector) read(
ctx context.Context,
ei *dosa.EntityInfo,
keys map[string]dosa.FieldValue,
source map[string]dosa.FieldValue,
sourceErr error,
methodName string,
) (values map[string]dosa.FieldValue, err error) {
if dosa.ErrorIsNotFound(sourceErr) {
return source, sourceErr
}
ckey := createCacheKey(ei, keys)
value, err := c.getValueFromFallback(ctx, ei, ckey)
c.logFallback(methodName, ei.Def.Name, err)
if err != nil {
return source, sourceErr
}
result := map[string]dosa.FieldValue{}
err = c.encoder.Decode(value, &result)
if err != nil {
return source, sourceErr
}
return rawRowAsPointers(ei, result), err
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"read",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"keys",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"source",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"sourceErr",
"error",
",",
"methodName",
"string",
",",
")",
"(",
"values",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"err",
"error",
")",
"{",
"if",
"dosa",
".",
"ErrorIsNotFound",
"(",
"sourceErr",
")",
"{",
"return",
"source",
",",
"sourceErr",
"\n",
"}",
"\n\n",
"ckey",
":=",
"createCacheKey",
"(",
"ei",
",",
"keys",
")",
"\n",
"value",
",",
"err",
":=",
"c",
".",
"getValueFromFallback",
"(",
"ctx",
",",
"ei",
",",
"ckey",
")",
"\n",
"c",
".",
"logFallback",
"(",
"methodName",
",",
"ei",
".",
"Def",
".",
"Name",
",",
"err",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"source",
",",
"sourceErr",
"\n",
"}",
"\n",
"result",
":=",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"{",
"}",
"\n",
"err",
"=",
"c",
".",
"encoder",
".",
"Decode",
"(",
"value",
",",
"&",
"result",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"source",
",",
"sourceErr",
"\n",
"}",
"\n",
"return",
"rawRowAsPointers",
"(",
"ei",
",",
"result",
")",
",",
"err",
"\n",
"}"
] | // if source of truth fails, try the fallback. If the fallback fails, return the original error | [
"if",
"source",
"of",
"truth",
"fails",
"try",
"the",
"fallback",
".",
"If",
"the",
"fallback",
"fails",
"return",
"the",
"original",
"error"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/cache/fallback.go#L138-L162 |
4,159 | uber-go/dosa | connectors/cache/fallback.go | Range | func (c *Connector) Range(ctx context.Context, ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition, minimumFields []string, token string, limit int) ([]map[string]dosa.FieldValue, string, error) {
sourceRows, sourceToken, sourceErr := c.Next.Range(ctx, ei, columnConditions, dosa.All(), token, limit)
if !c.isCacheable(ei) || dosa.ErrorIsNotFound(sourceErr) {
return sourceRows, sourceToken, sourceErr
}
cacheKey := rangeQuery{
Conditions: dosa.NormalizeConditions(columnConditions),
Token: token,
Limit: limit,
}
rangeResult := rangeResults{
TokenNext: sourceToken,
Rows: sourceRows,
}
if sourceErr == nil {
w := func() error {
return c.writeKeyValueToFallback(ctx, ei, cacheKey, rangeResult)
}
_ = c.cacheWrite(w)
return sourceRows, sourceToken, sourceErr
}
value, err := c.getValueFromFallback(ctx, ei, cacheKey)
c.logFallback("RANGE", ei.Def.Name, err)
if err != nil {
return sourceRows, sourceToken, sourceErr
}
unpack := rangeResults{}
err = c.encoder.Decode(value, &unpack)
if err != nil {
return sourceRows, sourceToken, sourceErr
}
return rawRowsAsPointers(ei, unpack.Rows), unpack.TokenNext, err
} | go | func (c *Connector) Range(ctx context.Context, ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition, minimumFields []string, token string, limit int) ([]map[string]dosa.FieldValue, string, error) {
sourceRows, sourceToken, sourceErr := c.Next.Range(ctx, ei, columnConditions, dosa.All(), token, limit)
if !c.isCacheable(ei) || dosa.ErrorIsNotFound(sourceErr) {
return sourceRows, sourceToken, sourceErr
}
cacheKey := rangeQuery{
Conditions: dosa.NormalizeConditions(columnConditions),
Token: token,
Limit: limit,
}
rangeResult := rangeResults{
TokenNext: sourceToken,
Rows: sourceRows,
}
if sourceErr == nil {
w := func() error {
return c.writeKeyValueToFallback(ctx, ei, cacheKey, rangeResult)
}
_ = c.cacheWrite(w)
return sourceRows, sourceToken, sourceErr
}
value, err := c.getValueFromFallback(ctx, ei, cacheKey)
c.logFallback("RANGE", ei.Def.Name, err)
if err != nil {
return sourceRows, sourceToken, sourceErr
}
unpack := rangeResults{}
err = c.encoder.Decode(value, &unpack)
if err != nil {
return sourceRows, sourceToken, sourceErr
}
return rawRowsAsPointers(ei, unpack.Rows), unpack.TokenNext, err
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Range",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"columnConditions",
"map",
"[",
"string",
"]",
"[",
"]",
"*",
"dosa",
".",
"Condition",
",",
"minimumFields",
"[",
"]",
"string",
",",
"token",
"string",
",",
"limit",
"int",
")",
"(",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"string",
",",
"error",
")",
"{",
"sourceRows",
",",
"sourceToken",
",",
"sourceErr",
":=",
"c",
".",
"Next",
".",
"Range",
"(",
"ctx",
",",
"ei",
",",
"columnConditions",
",",
"dosa",
".",
"All",
"(",
")",
",",
"token",
",",
"limit",
")",
"\n",
"if",
"!",
"c",
".",
"isCacheable",
"(",
"ei",
")",
"||",
"dosa",
".",
"ErrorIsNotFound",
"(",
"sourceErr",
")",
"{",
"return",
"sourceRows",
",",
"sourceToken",
",",
"sourceErr",
"\n",
"}",
"\n",
"cacheKey",
":=",
"rangeQuery",
"{",
"Conditions",
":",
"dosa",
".",
"NormalizeConditions",
"(",
"columnConditions",
")",
",",
"Token",
":",
"token",
",",
"Limit",
":",
"limit",
",",
"}",
"\n",
"rangeResult",
":=",
"rangeResults",
"{",
"TokenNext",
":",
"sourceToken",
",",
"Rows",
":",
"sourceRows",
",",
"}",
"\n\n",
"if",
"sourceErr",
"==",
"nil",
"{",
"w",
":=",
"func",
"(",
")",
"error",
"{",
"return",
"c",
".",
"writeKeyValueToFallback",
"(",
"ctx",
",",
"ei",
",",
"cacheKey",
",",
"rangeResult",
")",
"\n",
"}",
"\n",
"_",
"=",
"c",
".",
"cacheWrite",
"(",
"w",
")",
"\n\n",
"return",
"sourceRows",
",",
"sourceToken",
",",
"sourceErr",
"\n",
"}",
"\n\n",
"value",
",",
"err",
":=",
"c",
".",
"getValueFromFallback",
"(",
"ctx",
",",
"ei",
",",
"cacheKey",
")",
"\n",
"c",
".",
"logFallback",
"(",
"\"",
"\"",
",",
"ei",
".",
"Def",
".",
"Name",
",",
"err",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"sourceRows",
",",
"sourceToken",
",",
"sourceErr",
"\n",
"}",
"\n",
"unpack",
":=",
"rangeResults",
"{",
"}",
"\n",
"err",
"=",
"c",
".",
"encoder",
".",
"Decode",
"(",
"value",
",",
"&",
"unpack",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"sourceRows",
",",
"sourceToken",
",",
"sourceErr",
"\n",
"}",
"\n\n",
"return",
"rawRowsAsPointers",
"(",
"ei",
",",
"unpack",
".",
"Rows",
")",
",",
"unpack",
".",
"TokenNext",
",",
"err",
"\n",
"}"
] | // Range returns range from origin, reverts to fallback if origin fails | [
"Range",
"returns",
"range",
"from",
"origin",
"reverts",
"to",
"fallback",
"if",
"origin",
"fails"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/cache/fallback.go#L170-L206 |
4,160 | uber-go/dosa | connectors/cache/fallback.go | Remove | func (c *Connector) Remove(ctx context.Context, ei *dosa.EntityInfo, keys map[string]dosa.FieldValue) error {
if c.isCacheable(ei) {
w := func() error {
return c.removeValueFromFallback(ctx, ei, createCacheKey(ei, keys))
}
_ = c.cacheWrite(w)
}
return c.Next.Remove(ctx, ei, keys)
} | go | func (c *Connector) Remove(ctx context.Context, ei *dosa.EntityInfo, keys map[string]dosa.FieldValue) error {
if c.isCacheable(ei) {
w := func() error {
return c.removeValueFromFallback(ctx, ei, createCacheKey(ei, keys))
}
_ = c.cacheWrite(w)
}
return c.Next.Remove(ctx, ei, keys)
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"Remove",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"keys",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"error",
"{",
"if",
"c",
".",
"isCacheable",
"(",
"ei",
")",
"{",
"w",
":=",
"func",
"(",
")",
"error",
"{",
"return",
"c",
".",
"removeValueFromFallback",
"(",
"ctx",
",",
"ei",
",",
"createCacheKey",
"(",
"ei",
",",
"keys",
")",
")",
"\n",
"}",
"\n",
"_",
"=",
"c",
".",
"cacheWrite",
"(",
"w",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"Next",
".",
"Remove",
"(",
"ctx",
",",
"ei",
",",
"keys",
")",
"\n",
"}"
] | // Remove deletes an entry | [
"Remove",
"deletes",
"an",
"entry"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/cache/fallback.go#L291-L300 |
4,161 | uber-go/dosa | connectors/cache/fallback.go | MultiUpsert | func (c *Connector) MultiUpsert(ctx context.Context, ei *dosa.EntityInfo, multiValues []map[string]dosa.FieldValue) (result []error, err error) {
if c.isCacheable(ei) {
w := func() error {
for _, values := range multiValues {
_ = c.removeValueFromFallback(ctx, ei, createCacheKey(ei, values))
}
return nil
}
_ = c.cacheWrite(w)
}
return c.Next.MultiUpsert(ctx, ei, multiValues)
} | go | func (c *Connector) MultiUpsert(ctx context.Context, ei *dosa.EntityInfo, multiValues []map[string]dosa.FieldValue) (result []error, err error) {
if c.isCacheable(ei) {
w := func() error {
for _, values := range multiValues {
_ = c.removeValueFromFallback(ctx, ei, createCacheKey(ei, values))
}
return nil
}
_ = c.cacheWrite(w)
}
return c.Next.MultiUpsert(ctx, ei, multiValues)
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"MultiUpsert",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"multiValues",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"(",
"result",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"if",
"c",
".",
"isCacheable",
"(",
"ei",
")",
"{",
"w",
":=",
"func",
"(",
")",
"error",
"{",
"for",
"_",
",",
"values",
":=",
"range",
"multiValues",
"{",
"_",
"=",
"c",
".",
"removeValueFromFallback",
"(",
"ctx",
",",
"ei",
",",
"createCacheKey",
"(",
"ei",
",",
"values",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"_",
"=",
"c",
".",
"cacheWrite",
"(",
"w",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"Next",
".",
"MultiUpsert",
"(",
"ctx",
",",
"ei",
",",
"multiValues",
")",
"\n",
"}"
] | // MultiUpsert deletes the entries getting upserted from the fallback if the entity is not in the skipWriteInvalidateEntitiesMap | [
"MultiUpsert",
"deletes",
"the",
"entries",
"getting",
"upserted",
"from",
"the",
"fallback",
"if",
"the",
"entity",
"is",
"not",
"in",
"the",
"skipWriteInvalidateEntitiesMap"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/cache/fallback.go#L303-L314 |
4,162 | uber-go/dosa | connectors/cache/fallback.go | MultiRemove | func (c *Connector) MultiRemove(ctx context.Context, ei *dosa.EntityInfo, multiKeys []map[string]dosa.FieldValue) (result []error, err error) {
if c.isCacheable(ei) {
w := func() error {
for _, keys := range multiKeys {
_ = c.removeValueFromFallback(ctx, ei, createCacheKey(ei, keys))
}
return nil
}
_ = c.cacheWrite(w)
}
return c.Next.MultiRemove(ctx, ei, multiKeys)
} | go | func (c *Connector) MultiRemove(ctx context.Context, ei *dosa.EntityInfo, multiKeys []map[string]dosa.FieldValue) (result []error, err error) {
if c.isCacheable(ei) {
w := func() error {
for _, keys := range multiKeys {
_ = c.removeValueFromFallback(ctx, ei, createCacheKey(ei, keys))
}
return nil
}
_ = c.cacheWrite(w)
}
return c.Next.MultiRemove(ctx, ei, multiKeys)
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"MultiRemove",
"(",
"ctx",
"context",
".",
"Context",
",",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"multiKeys",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"(",
"result",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"if",
"c",
".",
"isCacheable",
"(",
"ei",
")",
"{",
"w",
":=",
"func",
"(",
")",
"error",
"{",
"for",
"_",
",",
"keys",
":=",
"range",
"multiKeys",
"{",
"_",
"=",
"c",
".",
"removeValueFromFallback",
"(",
"ctx",
",",
"ei",
",",
"createCacheKey",
"(",
"ei",
",",
"keys",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"_",
"=",
"c",
".",
"cacheWrite",
"(",
"w",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"Next",
".",
"MultiRemove",
"(",
"ctx",
",",
"ei",
",",
"multiKeys",
")",
"\n",
"}"
] | // MultiRemove deletes multiple entries from the fallback | [
"MultiRemove",
"deletes",
"multiple",
"entries",
"from",
"the",
"fallback"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/cache/fallback.go#L317-L329 |
4,163 | uber-go/dosa | connectors/cache/fallback.go | adaptToKeyValue | func adaptToKeyValue(ei *dosa.EntityInfo) *dosa.EntityInfo {
adaptedEi := &dosa.EntityInfo{}
adaptedEi.Ref = ei.Ref
adaptedEi.Def = &dosa.EntityDefinition{
Name: ei.Def.Name,
Key: &dosa.PrimaryKey{
PartitionKeys: []string{key},
},
Columns: []*dosa.ColumnDefinition{
{Name: value, Type: dosa.Blob},
{Name: key, Type: dosa.Blob},
},
}
return adaptedEi
} | go | func adaptToKeyValue(ei *dosa.EntityInfo) *dosa.EntityInfo {
adaptedEi := &dosa.EntityInfo{}
adaptedEi.Ref = ei.Ref
adaptedEi.Def = &dosa.EntityDefinition{
Name: ei.Def.Name,
Key: &dosa.PrimaryKey{
PartitionKeys: []string{key},
},
Columns: []*dosa.ColumnDefinition{
{Name: value, Type: dosa.Blob},
{Name: key, Type: dosa.Blob},
},
}
return adaptedEi
} | [
"func",
"adaptToKeyValue",
"(",
"ei",
"*",
"dosa",
".",
"EntityInfo",
")",
"*",
"dosa",
".",
"EntityInfo",
"{",
"adaptedEi",
":=",
"&",
"dosa",
".",
"EntityInfo",
"{",
"}",
"\n",
"adaptedEi",
".",
"Ref",
"=",
"ei",
".",
"Ref",
"\n",
"adaptedEi",
".",
"Def",
"=",
"&",
"dosa",
".",
"EntityDefinition",
"{",
"Name",
":",
"ei",
".",
"Def",
".",
"Name",
",",
"Key",
":",
"&",
"dosa",
".",
"PrimaryKey",
"{",
"PartitionKeys",
":",
"[",
"]",
"string",
"{",
"key",
"}",
",",
"}",
",",
"Columns",
":",
"[",
"]",
"*",
"dosa",
".",
"ColumnDefinition",
"{",
"{",
"Name",
":",
"value",
",",
"Type",
":",
"dosa",
".",
"Blob",
"}",
",",
"{",
"Name",
":",
"key",
",",
"Type",
":",
"dosa",
".",
"Blob",
"}",
",",
"}",
",",
"}",
"\n",
"return",
"adaptedEi",
"\n",
"}"
] | // new entity info is being derived from the original to support the structure of a caching connector | [
"new",
"entity",
"info",
"is",
"being",
"derived",
"from",
"the",
"original",
"to",
"support",
"the",
"structure",
"of",
"a",
"caching",
"connector"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/cache/fallback.go#L447-L461 |
4,164 | uber-go/dosa | connectors/cache/fallback.go | rawRowAsPointers | func rawRowAsPointers(ei *dosa.EntityInfo, values map[string]dosa.FieldValue) map[string]dosa.FieldValue {
convertedValues := map[string]dosa.FieldValue{}
// Using the type of the column as source of truth, convert from an interface{} back
// to its native type before taking the address.
// Values from the cache with a type mismatch will not be included in the results
for colName, colType := range ei.Def.ColumnTypes() {
if val, ok := values[colName]; ok {
switch colType {
case dosa.Blob:
// do nothing with byte arrays
convertedValues[colName] = val
case dosa.TUUID:
if u, ok := val.(dosa.UUID); ok {
convertedValues[colName] = &u
}
case dosa.String:
if s, ok := val.(string); ok {
convertedValues[colName] = &s
}
case dosa.Int32:
if i, ok := val.(int32); ok {
convertedValues[colName] = &i
}
case dosa.Int64:
if i, ok := val.(int64); ok {
convertedValues[colName] = &i
}
case dosa.Double:
if d, ok := val.(float64); ok {
convertedValues[colName] = &d
}
case dosa.Timestamp:
if t, ok := val.(time.Time); ok {
convertedValues[colName] = &t
}
case dosa.Bool:
if b, ok := val.(bool); ok {
convertedValues[colName] = &b
}
default:
convertedValues[colName] = &val
}
}
}
return convertedValues
} | go | func rawRowAsPointers(ei *dosa.EntityInfo, values map[string]dosa.FieldValue) map[string]dosa.FieldValue {
convertedValues := map[string]dosa.FieldValue{}
// Using the type of the column as source of truth, convert from an interface{} back
// to its native type before taking the address.
// Values from the cache with a type mismatch will not be included in the results
for colName, colType := range ei.Def.ColumnTypes() {
if val, ok := values[colName]; ok {
switch colType {
case dosa.Blob:
// do nothing with byte arrays
convertedValues[colName] = val
case dosa.TUUID:
if u, ok := val.(dosa.UUID); ok {
convertedValues[colName] = &u
}
case dosa.String:
if s, ok := val.(string); ok {
convertedValues[colName] = &s
}
case dosa.Int32:
if i, ok := val.(int32); ok {
convertedValues[colName] = &i
}
case dosa.Int64:
if i, ok := val.(int64); ok {
convertedValues[colName] = &i
}
case dosa.Double:
if d, ok := val.(float64); ok {
convertedValues[colName] = &d
}
case dosa.Timestamp:
if t, ok := val.(time.Time); ok {
convertedValues[colName] = &t
}
case dosa.Bool:
if b, ok := val.(bool); ok {
convertedValues[colName] = &b
}
default:
convertedValues[colName] = &val
}
}
}
return convertedValues
} | [
"func",
"rawRowAsPointers",
"(",
"ei",
"*",
"dosa",
".",
"EntityInfo",
",",
"values",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"{",
"convertedValues",
":=",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
"{",
"}",
"\n",
"// Using the type of the column as source of truth, convert from an interface{} back",
"// to its native type before taking the address.",
"// Values from the cache with a type mismatch will not be included in the results",
"for",
"colName",
",",
"colType",
":=",
"range",
"ei",
".",
"Def",
".",
"ColumnTypes",
"(",
")",
"{",
"if",
"val",
",",
"ok",
":=",
"values",
"[",
"colName",
"]",
";",
"ok",
"{",
"switch",
"colType",
"{",
"case",
"dosa",
".",
"Blob",
":",
"// do nothing with byte arrays",
"convertedValues",
"[",
"colName",
"]",
"=",
"val",
"\n",
"case",
"dosa",
".",
"TUUID",
":",
"if",
"u",
",",
"ok",
":=",
"val",
".",
"(",
"dosa",
".",
"UUID",
")",
";",
"ok",
"{",
"convertedValues",
"[",
"colName",
"]",
"=",
"&",
"u",
"\n",
"}",
"\n",
"case",
"dosa",
".",
"String",
":",
"if",
"s",
",",
"ok",
":=",
"val",
".",
"(",
"string",
")",
";",
"ok",
"{",
"convertedValues",
"[",
"colName",
"]",
"=",
"&",
"s",
"\n",
"}",
"\n",
"case",
"dosa",
".",
"Int32",
":",
"if",
"i",
",",
"ok",
":=",
"val",
".",
"(",
"int32",
")",
";",
"ok",
"{",
"convertedValues",
"[",
"colName",
"]",
"=",
"&",
"i",
"\n",
"}",
"\n",
"case",
"dosa",
".",
"Int64",
":",
"if",
"i",
",",
"ok",
":=",
"val",
".",
"(",
"int64",
")",
";",
"ok",
"{",
"convertedValues",
"[",
"colName",
"]",
"=",
"&",
"i",
"\n",
"}",
"\n",
"case",
"dosa",
".",
"Double",
":",
"if",
"d",
",",
"ok",
":=",
"val",
".",
"(",
"float64",
")",
";",
"ok",
"{",
"convertedValues",
"[",
"colName",
"]",
"=",
"&",
"d",
"\n",
"}",
"\n",
"case",
"dosa",
".",
"Timestamp",
":",
"if",
"t",
",",
"ok",
":=",
"val",
".",
"(",
"time",
".",
"Time",
")",
";",
"ok",
"{",
"convertedValues",
"[",
"colName",
"]",
"=",
"&",
"t",
"\n",
"}",
"\n",
"case",
"dosa",
".",
"Bool",
":",
"if",
"b",
",",
"ok",
":=",
"val",
".",
"(",
"bool",
")",
";",
"ok",
"{",
"convertedValues",
"[",
"colName",
"]",
"=",
"&",
"b",
"\n",
"}",
"\n",
"default",
":",
"convertedValues",
"[",
"colName",
"]",
"=",
"&",
"val",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"convertedValues",
"\n",
"}"
] | // Convert the values returned from Read calls into pointers to those values.
// Everything read from cache is always the absolute value and not a pointer to the value.
// Dosa's registry.go uses reflection to set values onto a dosa entity.
// It works better to de-reference a pointer instead of trying to get the address of a value
// as some things are not easily addressable | [
"Convert",
"the",
"values",
"returned",
"from",
"Read",
"calls",
"into",
"pointers",
"to",
"those",
"values",
".",
"Everything",
"read",
"from",
"cache",
"is",
"always",
"the",
"absolute",
"value",
"and",
"not",
"a",
"pointer",
"to",
"the",
"value",
".",
"Dosa",
"s",
"registry",
".",
"go",
"uses",
"reflection",
"to",
"set",
"values",
"onto",
"a",
"dosa",
"entity",
".",
"It",
"works",
"better",
"to",
"de",
"-",
"reference",
"a",
"pointer",
"instead",
"of",
"trying",
"to",
"get",
"the",
"address",
"of",
"a",
"value",
"as",
"some",
"things",
"are",
"not",
"easily",
"addressable"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/cache/fallback.go#L491-L536 |
4,165 | uber-go/dosa | connectors/cache/fallback.go | populateValuesWithKeys | func populateValuesWithKeys(keys map[string]dosa.FieldValue, values map[string]dosa.FieldValue) {
if values != nil {
for k, v := range keys {
values[k] = v
}
}
} | go | func populateValuesWithKeys(keys map[string]dosa.FieldValue, values map[string]dosa.FieldValue) {
if values != nil {
for k, v := range keys {
values[k] = v
}
}
} | [
"func",
"populateValuesWithKeys",
"(",
"keys",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"values",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"{",
"if",
"values",
"!=",
"nil",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"keys",
"{",
"values",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Add keys into values map. This mutates the values argument | [
"Add",
"keys",
"into",
"values",
"map",
".",
"This",
"mutates",
"the",
"values",
"argument"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/cache/fallback.go#L547-L553 |
4,166 | uber-go/dosa | mocks/connector.go | NewMockConnector | func NewMockConnector(ctrl *gomock.Controller) *MockConnector {
mock := &MockConnector{ctrl: ctrl}
mock.recorder = &MockConnectorMockRecorder{mock}
return mock
} | go | func NewMockConnector(ctrl *gomock.Controller) *MockConnector {
mock := &MockConnector{ctrl: ctrl}
mock.recorder = &MockConnectorMockRecorder{mock}
return mock
} | [
"func",
"NewMockConnector",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockConnector",
"{",
"mock",
":=",
"&",
"MockConnector",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockConnectorMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockConnector creates a new mock instance | [
"NewMockConnector",
"creates",
"a",
"new",
"mock",
"instance"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/mocks/connector.go#L47-L51 |
4,167 | uber-go/dosa | mocks/connector.go | CanUpsertSchema | func (mr *MockConnectorMockRecorder) CanUpsertSchema(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CanUpsertSchema", reflect.TypeOf((*MockConnector)(nil).CanUpsertSchema), arg0, arg1, arg2, arg3)
} | go | func (mr *MockConnectorMockRecorder) CanUpsertSchema(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CanUpsertSchema", reflect.TypeOf((*MockConnector)(nil).CanUpsertSchema), arg0, arg1, arg2, arg3)
} | [
"func",
"(",
"mr",
"*",
"MockConnectorMockRecorder",
")",
"CanUpsertSchema",
"(",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockConnector",
")",
"(",
"nil",
")",
".",
"CanUpsertSchema",
")",
",",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
")",
"\n",
"}"
] | // CanUpsertSchema indicates an expected call of CanUpsertSchema | [
"CanUpsertSchema",
"indicates",
"an",
"expected",
"call",
"of",
"CanUpsertSchema"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/mocks/connector.go#L67-L69 |
4,168 | uber-go/dosa | mocks/connector.go | GetEntitySchema | func (m *MockConnector) GetEntitySchema(arg0 context.Context, arg1, arg2, arg3 string, arg4 int32) (*dosa.EntityDefinition, error) {
ret := m.ctrl.Call(m, "GetEntitySchema", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].(*dosa.EntityDefinition)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockConnector) GetEntitySchema(arg0 context.Context, arg1, arg2, arg3 string, arg4 int32) (*dosa.EntityDefinition, error) {
ret := m.ctrl.Call(m, "GetEntitySchema", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].(*dosa.EntityDefinition)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockConnector",
")",
"GetEntitySchema",
"(",
"arg0",
"context",
".",
"Context",
",",
"arg1",
",",
"arg2",
",",
"arg3",
"string",
",",
"arg4",
"int32",
")",
"(",
"*",
"dosa",
".",
"EntityDefinition",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"arg4",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"dosa",
".",
"EntityDefinition",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // GetEntitySchema mocks base method | [
"GetEntitySchema",
"mocks",
"base",
"method"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/mocks/connector.go#L134-L139 |
4,169 | uber-go/dosa | mocks/connector.go | Scan | func (m *MockConnector) Scan(arg0 context.Context, arg1 *dosa.EntityInfo, arg2 []string, arg3 string, arg4 int) ([]map[string]dosa.FieldValue, string, error) {
ret := m.ctrl.Call(m, "Scan", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].([]map[string]dosa.FieldValue)
ret1, _ := ret[1].(string)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
} | go | func (m *MockConnector) Scan(arg0 context.Context, arg1 *dosa.EntityInfo, arg2 []string, arg3 string, arg4 int) ([]map[string]dosa.FieldValue, string, error) {
ret := m.ctrl.Call(m, "Scan", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].([]map[string]dosa.FieldValue)
ret1, _ := ret[1].(string)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
} | [
"func",
"(",
"m",
"*",
"MockConnector",
")",
"Scan",
"(",
"arg0",
"context",
".",
"Context",
",",
"arg1",
"*",
"dosa",
".",
"EntityInfo",
",",
"arg2",
"[",
"]",
"string",
",",
"arg3",
"string",
",",
"arg4",
"int",
")",
"(",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"string",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"arg4",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"string",
")",
"\n",
"ret2",
",",
"_",
":=",
"ret",
"[",
"2",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
",",
"ret2",
"\n",
"}"
] | // Scan mocks base method | [
"Scan",
"mocks",
"base",
"method"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/mocks/connector.go#L237-L243 |
4,170 | uber-go/dosa | mocks/connector.go | ScopeExists | func (m *MockConnector) ScopeExists(arg0 context.Context, arg1 string) (bool, error) {
ret := m.ctrl.Call(m, "ScopeExists", arg0, arg1)
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockConnector) ScopeExists(arg0 context.Context, arg1 string) (bool, error) {
ret := m.ctrl.Call(m, "ScopeExists", arg0, arg1)
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockConnector",
")",
"ScopeExists",
"(",
"arg0",
"context",
".",
"Context",
",",
"arg1",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"bool",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // ScopeExists mocks base method | [
"ScopeExists",
"mocks",
"base",
"method"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/mocks/connector.go#L251-L256 |
4,171 | uber-go/dosa | mocks/connector.go | TruncateScope | func (m *MockConnector) TruncateScope(arg0 context.Context, arg1 string) error {
ret := m.ctrl.Call(m, "TruncateScope", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockConnector) TruncateScope(arg0 context.Context, arg1 string) error {
ret := m.ctrl.Call(m, "TruncateScope", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockConnector",
")",
"TruncateScope",
"(",
"arg0",
"context",
".",
"Context",
",",
"arg1",
"string",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // TruncateScope mocks base method | [
"TruncateScope",
"mocks",
"base",
"method"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/mocks/connector.go#L276-L280 |
4,172 | uber-go/dosa | cmd/dosa/range.go | Range | func (c *shellQueryClient) Range(ctx context.Context, ops []*queryObj, fields []string, limit int) ([]map[string]dosa.FieldValue, error) {
// look up the entity in the registry
re, _ := c.registrar.Find(&dosa.Entity{})
// build range operator with expressions and limit number
r, err := buildRangeOp(ops, limit)
if err != nil {
return nil, err
}
// now convert the client range columns to server side column conditions structure
columnConditions, err := dosa.ConvertConditions(r.Conditions(), re.Table())
if err != nil {
return nil, err
}
// convert the field names to column names
columns, err := re.ColumnNames(fields)
if err != nil {
return nil, err
}
// call the server side method
values, _, err := c.connector.Range(ctx, re.EntityInfo(), columnConditions, columns, "", r.LimitRows())
if err != nil {
return nil, err
}
return convertColToField(values, re.Table().ColToField), err
} | go | func (c *shellQueryClient) Range(ctx context.Context, ops []*queryObj, fields []string, limit int) ([]map[string]dosa.FieldValue, error) {
// look up the entity in the registry
re, _ := c.registrar.Find(&dosa.Entity{})
// build range operator with expressions and limit number
r, err := buildRangeOp(ops, limit)
if err != nil {
return nil, err
}
// now convert the client range columns to server side column conditions structure
columnConditions, err := dosa.ConvertConditions(r.Conditions(), re.Table())
if err != nil {
return nil, err
}
// convert the field names to column names
columns, err := re.ColumnNames(fields)
if err != nil {
return nil, err
}
// call the server side method
values, _, err := c.connector.Range(ctx, re.EntityInfo(), columnConditions, columns, "", r.LimitRows())
if err != nil {
return nil, err
}
return convertColToField(values, re.Table().ColToField), err
} | [
"func",
"(",
"c",
"*",
"shellQueryClient",
")",
"Range",
"(",
"ctx",
"context",
".",
"Context",
",",
"ops",
"[",
"]",
"*",
"queryObj",
",",
"fields",
"[",
"]",
"string",
",",
"limit",
"int",
")",
"(",
"[",
"]",
"map",
"[",
"string",
"]",
"dosa",
".",
"FieldValue",
",",
"error",
")",
"{",
"// look up the entity in the registry",
"re",
",",
"_",
":=",
"c",
".",
"registrar",
".",
"Find",
"(",
"&",
"dosa",
".",
"Entity",
"{",
"}",
")",
"\n\n",
"// build range operator with expressions and limit number",
"r",
",",
"err",
":=",
"buildRangeOp",
"(",
"ops",
",",
"limit",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// now convert the client range columns to server side column conditions structure",
"columnConditions",
",",
"err",
":=",
"dosa",
".",
"ConvertConditions",
"(",
"r",
".",
"Conditions",
"(",
")",
",",
"re",
".",
"Table",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// convert the field names to column names",
"columns",
",",
"err",
":=",
"re",
".",
"ColumnNames",
"(",
"fields",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// call the server side method",
"values",
",",
"_",
",",
"err",
":=",
"c",
".",
"connector",
".",
"Range",
"(",
"ctx",
",",
"re",
".",
"EntityInfo",
"(",
")",
",",
"columnConditions",
",",
"columns",
",",
"\"",
"\"",
",",
"r",
".",
"LimitRows",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"convertColToField",
"(",
"values",
",",
"re",
".",
"Table",
"(",
")",
".",
"ColToField",
")",
",",
"err",
"\n",
"}"
] | // Range uses the connector to fetch rows for a given range | [
"Range",
"uses",
"the",
"connector",
"to",
"fetch",
"rows",
"for",
"a",
"given",
"range"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/range.go#L31-L60 |
4,173 | uber-go/dosa | cmd/dosa/main.go | Execute | func (b BuildInfo) Execute(args []string) error {
fmt.Printf("%s\n", b)
return nil
} | go | func (b BuildInfo) Execute(args []string) error {
fmt.Printf("%s\n", b)
return nil
} | [
"func",
"(",
"b",
"BuildInfo",
")",
"Execute",
"(",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"b",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Execute is ran for the version subcommand | [
"Execute",
"is",
"ran",
"for",
"the",
"version",
"subcommand"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/main.go#L64-L67 |
4,174 | uber-go/dosa | cmd/dosa/main.go | main | func main() {
buildInfo := &BuildInfo{}
OptionsParser := flags.NewParser(&options, flags.PassAfterNonOption|flags.HelpFlag)
OptionsParser.ShortDescription = "DOSA CLI - The command-line tool for your DOSA client"
OptionsParser.LongDescription = `
dosa manages your schema both in production and development scopes`
c, _ := OptionsParser.AddCommand("version", "display build info", "display build info", &BuildInfo{})
c, _ = OptionsParser.AddCommand("scope", "commands to manage scope", "create, drop, or truncate development scopes", &ScopeOptions{})
_, _ = c.AddCommand("create", "Create scope", "creates a new scope", newScopeCreate(provideAdminClient))
_, _ = c.AddCommand("drop", "Drop scope", "drops a scope", newScopeDrop(provideAdminClient))
_, _ = c.AddCommand("truncate", "Truncate scope", "truncates a scope", newScopeTruncate(provideAdminClient))
_, _ = c.AddCommand("list", "List scopes", "lists scopes", newScopeList(provideMDClient))
_, _ = c.AddCommand("show", "Show scope MD", "show scope metadata", newScopeShow(provideMDClient))
c, _ = OptionsParser.AddCommand("schema", "commands to manage schemas", "check or update schemas", &SchemaOptions{})
_, _ = c.AddCommand("check", "Check schema", "check the schema", newSchemaCheck(provideAdminClient))
_, _ = c.AddCommand("upsert", "Upsert schema", "insert or update the schema", newSchemaUpsert(provideAdminClient))
_, _ = c.AddCommand("dump", "Dump schema", "display the schema in a given format", &SchemaDump{})
_, _ = c.AddCommand("status", "Check schema status", "Check application status of schema", newSchemaStatus(provideAdminClient))
c, _ = OptionsParser.AddCommand("query", "commands to do query", "fetch one or multiple rows", &QueryOptions{})
_, _ = c.AddCommand("read", "Read query", "read a row by primary keys", newQueryRead(provideShellQueryClient))
_, _ = c.AddCommand("range", "Range query", "read rows with range of primary keys and indexes", newQueryRange(provideShellQueryClient))
// TODO: implement admin subcommand
// c, _ = OptionsParser.AddCommand("admin", "commands to administrate", "", &AdminOptions{})
_, err := OptionsParser.Parse()
if options.Version {
_, _ = fmt.Fprintf(os.Stdout, "%s\n", buildInfo.String())
options.Version = false // for tests, we leak state between runs
exit(0)
}
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Error: %s\n", err)
exit(1)
return
}
exit(0)
} | go | func main() {
buildInfo := &BuildInfo{}
OptionsParser := flags.NewParser(&options, flags.PassAfterNonOption|flags.HelpFlag)
OptionsParser.ShortDescription = "DOSA CLI - The command-line tool for your DOSA client"
OptionsParser.LongDescription = `
dosa manages your schema both in production and development scopes`
c, _ := OptionsParser.AddCommand("version", "display build info", "display build info", &BuildInfo{})
c, _ = OptionsParser.AddCommand("scope", "commands to manage scope", "create, drop, or truncate development scopes", &ScopeOptions{})
_, _ = c.AddCommand("create", "Create scope", "creates a new scope", newScopeCreate(provideAdminClient))
_, _ = c.AddCommand("drop", "Drop scope", "drops a scope", newScopeDrop(provideAdminClient))
_, _ = c.AddCommand("truncate", "Truncate scope", "truncates a scope", newScopeTruncate(provideAdminClient))
_, _ = c.AddCommand("list", "List scopes", "lists scopes", newScopeList(provideMDClient))
_, _ = c.AddCommand("show", "Show scope MD", "show scope metadata", newScopeShow(provideMDClient))
c, _ = OptionsParser.AddCommand("schema", "commands to manage schemas", "check or update schemas", &SchemaOptions{})
_, _ = c.AddCommand("check", "Check schema", "check the schema", newSchemaCheck(provideAdminClient))
_, _ = c.AddCommand("upsert", "Upsert schema", "insert or update the schema", newSchemaUpsert(provideAdminClient))
_, _ = c.AddCommand("dump", "Dump schema", "display the schema in a given format", &SchemaDump{})
_, _ = c.AddCommand("status", "Check schema status", "Check application status of schema", newSchemaStatus(provideAdminClient))
c, _ = OptionsParser.AddCommand("query", "commands to do query", "fetch one or multiple rows", &QueryOptions{})
_, _ = c.AddCommand("read", "Read query", "read a row by primary keys", newQueryRead(provideShellQueryClient))
_, _ = c.AddCommand("range", "Range query", "read rows with range of primary keys and indexes", newQueryRange(provideShellQueryClient))
// TODO: implement admin subcommand
// c, _ = OptionsParser.AddCommand("admin", "commands to administrate", "", &AdminOptions{})
_, err := OptionsParser.Parse()
if options.Version {
_, _ = fmt.Fprintf(os.Stdout, "%s\n", buildInfo.String())
options.Version = false // for tests, we leak state between runs
exit(0)
}
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Error: %s\n", err)
exit(1)
return
}
exit(0)
} | [
"func",
"main",
"(",
")",
"{",
"buildInfo",
":=",
"&",
"BuildInfo",
"{",
"}",
"\n",
"OptionsParser",
":=",
"flags",
".",
"NewParser",
"(",
"&",
"options",
",",
"flags",
".",
"PassAfterNonOption",
"|",
"flags",
".",
"HelpFlag",
")",
"\n",
"OptionsParser",
".",
"ShortDescription",
"=",
"\"",
"\"",
"\n",
"OptionsParser",
".",
"LongDescription",
"=",
"`\ndosa manages your schema both in production and development scopes`",
"\n\n",
"c",
",",
"_",
":=",
"OptionsParser",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"&",
"BuildInfo",
"{",
"}",
")",
"\n\n",
"c",
",",
"_",
"=",
"OptionsParser",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"&",
"ScopeOptions",
"{",
"}",
")",
"\n",
"_",
",",
"_",
"=",
"c",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"newScopeCreate",
"(",
"provideAdminClient",
")",
")",
"\n",
"_",
",",
"_",
"=",
"c",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"newScopeDrop",
"(",
"provideAdminClient",
")",
")",
"\n",
"_",
",",
"_",
"=",
"c",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"newScopeTruncate",
"(",
"provideAdminClient",
")",
")",
"\n\n",
"_",
",",
"_",
"=",
"c",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"newScopeList",
"(",
"provideMDClient",
")",
")",
"\n",
"_",
",",
"_",
"=",
"c",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"newScopeShow",
"(",
"provideMDClient",
")",
")",
"\n\n",
"c",
",",
"_",
"=",
"OptionsParser",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"&",
"SchemaOptions",
"{",
"}",
")",
"\n",
"_",
",",
"_",
"=",
"c",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"newSchemaCheck",
"(",
"provideAdminClient",
")",
")",
"\n",
"_",
",",
"_",
"=",
"c",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"newSchemaUpsert",
"(",
"provideAdminClient",
")",
")",
"\n",
"_",
",",
"_",
"=",
"c",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"&",
"SchemaDump",
"{",
"}",
")",
"\n",
"_",
",",
"_",
"=",
"c",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"newSchemaStatus",
"(",
"provideAdminClient",
")",
")",
"\n\n",
"c",
",",
"_",
"=",
"OptionsParser",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"&",
"QueryOptions",
"{",
"}",
")",
"\n",
"_",
",",
"_",
"=",
"c",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"newQueryRead",
"(",
"provideShellQueryClient",
")",
")",
"\n",
"_",
",",
"_",
"=",
"c",
".",
"AddCommand",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"newQueryRange",
"(",
"provideShellQueryClient",
")",
")",
"\n\n",
"// TODO: implement admin subcommand",
"// c, _ = OptionsParser.AddCommand(\"admin\", \"commands to administrate\", \"\", &AdminOptions{})",
"_",
",",
"err",
":=",
"OptionsParser",
".",
"Parse",
"(",
")",
"\n\n",
"if",
"options",
".",
"Version",
"{",
"_",
",",
"_",
"=",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stdout",
",",
"\"",
"\\n",
"\"",
",",
"buildInfo",
".",
"String",
"(",
")",
")",
"\n",
"options",
".",
"Version",
"=",
"false",
"// for tests, we leak state between runs",
"\n",
"exit",
"(",
"0",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"_",
",",
"_",
"=",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"exit",
"(",
"1",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"exit",
"(",
"0",
")",
"\n",
"}"
] | // OptionsParser holds the global parser | [
"OptionsParser",
"holds",
"the",
"global",
"parser"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/main.go#L86-L131 |
4,175 | uber-go/dosa | entity_parser.go | parseClusteringKeys | func parseClusteringKeys(ckStr string) ([]*ClusteringKey, error) {
ckStr = strings.TrimSpace(ckStr)
cks := strings.Split(ckStr, ",")
var clusteringKeys []*ClusteringKey
for _, ck := range cks {
fields := strings.Fields(ck)
if len(fields) == 0 {
continue
}
if len(fields) > 2 {
return nil, fmt.Errorf("Clustering key definition %q should look like \"name[ asc/desc]\"",
ck)
}
descending := false
if len(fields) == 2 {
switch strings.ToLower(fields[1]) {
case desc:
descending = true
case asc:
descending = false
default:
return nil, fmt.Errorf("invalid clustering key order %q in %q", fields[1], ck)
}
}
clusteringKeys = append(clusteringKeys, &ClusteringKey{Name: strings.TrimSpace(fields[0]), Descending: descending})
}
return clusteringKeys, nil
} | go | func parseClusteringKeys(ckStr string) ([]*ClusteringKey, error) {
ckStr = strings.TrimSpace(ckStr)
cks := strings.Split(ckStr, ",")
var clusteringKeys []*ClusteringKey
for _, ck := range cks {
fields := strings.Fields(ck)
if len(fields) == 0 {
continue
}
if len(fields) > 2 {
return nil, fmt.Errorf("Clustering key definition %q should look like \"name[ asc/desc]\"",
ck)
}
descending := false
if len(fields) == 2 {
switch strings.ToLower(fields[1]) {
case desc:
descending = true
case asc:
descending = false
default:
return nil, fmt.Errorf("invalid clustering key order %q in %q", fields[1], ck)
}
}
clusteringKeys = append(clusteringKeys, &ClusteringKey{Name: strings.TrimSpace(fields[0]), Descending: descending})
}
return clusteringKeys, nil
} | [
"func",
"parseClusteringKeys",
"(",
"ckStr",
"string",
")",
"(",
"[",
"]",
"*",
"ClusteringKey",
",",
"error",
")",
"{",
"ckStr",
"=",
"strings",
".",
"TrimSpace",
"(",
"ckStr",
")",
"\n",
"cks",
":=",
"strings",
".",
"Split",
"(",
"ckStr",
",",
"\"",
"\"",
")",
"\n",
"var",
"clusteringKeys",
"[",
"]",
"*",
"ClusteringKey",
"\n",
"for",
"_",
",",
"ck",
":=",
"range",
"cks",
"{",
"fields",
":=",
"strings",
".",
"Fields",
"(",
"ck",
")",
"\n",
"if",
"len",
"(",
"fields",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"len",
"(",
"fields",
")",
">",
"2",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"ck",
")",
"\n",
"}",
"\n",
"descending",
":=",
"false",
"\n",
"if",
"len",
"(",
"fields",
")",
"==",
"2",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"fields",
"[",
"1",
"]",
")",
"{",
"case",
"desc",
":",
"descending",
"=",
"true",
"\n",
"case",
"asc",
":",
"descending",
"=",
"false",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fields",
"[",
"1",
"]",
",",
"ck",
")",
"\n",
"}",
"\n\n",
"}",
"\n\n",
"clusteringKeys",
"=",
"append",
"(",
"clusteringKeys",
",",
"&",
"ClusteringKey",
"{",
"Name",
":",
"strings",
".",
"TrimSpace",
"(",
"fields",
"[",
"0",
"]",
")",
",",
"Descending",
":",
"descending",
"}",
")",
"\n",
"}",
"\n",
"return",
"clusteringKeys",
",",
"nil",
"\n",
"}"
] | // parseClusteringKeys func parses the clustering key of DOSA object | [
"parseClusteringKeys",
"func",
"parses",
"the",
"clustering",
"key",
"of",
"DOSA",
"object"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity_parser.go#L60-L89 |
4,176 | uber-go/dosa | entity_parser.go | parsePartitionKey | func parsePartitionKey(pkStr string) []string {
pkStr = strings.TrimSpace(pkStr)
var pks []string
partitionKeys := strings.Split(pkStr, ",")
for _, pk := range partitionKeys {
npk := strings.TrimSpace(pk)
if len(pk) > 0 {
pks = append(pks, npk)
}
}
return pks
} | go | func parsePartitionKey(pkStr string) []string {
pkStr = strings.TrimSpace(pkStr)
var pks []string
partitionKeys := strings.Split(pkStr, ",")
for _, pk := range partitionKeys {
npk := strings.TrimSpace(pk)
if len(pk) > 0 {
pks = append(pks, npk)
}
}
return pks
} | [
"func",
"parsePartitionKey",
"(",
"pkStr",
"string",
")",
"[",
"]",
"string",
"{",
"pkStr",
"=",
"strings",
".",
"TrimSpace",
"(",
"pkStr",
")",
"\n",
"var",
"pks",
"[",
"]",
"string",
"\n",
"partitionKeys",
":=",
"strings",
".",
"Split",
"(",
"pkStr",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"pk",
":=",
"range",
"partitionKeys",
"{",
"npk",
":=",
"strings",
".",
"TrimSpace",
"(",
"pk",
")",
"\n",
"if",
"len",
"(",
"pk",
")",
">",
"0",
"{",
"pks",
"=",
"append",
"(",
"pks",
",",
"npk",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"pks",
"\n",
"}"
] | // parsePartitionKey func parses the partition key of DOSA object | [
"parsePartitionKey",
"func",
"parses",
"the",
"partition",
"key",
"of",
"DOSA",
"object"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity_parser.go#L92-L103 |
4,177 | uber-go/dosa | entity_parser.go | parsePrimaryKey | func parsePrimaryKey(tableName, pkStr string) (*PrimaryKey, error) {
// parens must be matched
if !parensBalanced(pkStr) {
return nil, fmt.Errorf("unmatched parentheses: %q", pkStr)
}
// filter out "trailing comma and space"
pkStr = strings.TrimRight(pkStr, ", ")
pkStr = strings.TrimSpace(pkStr)
var partitionKeyStr string
var clusteringKeyStr string
matched := false
// case 1: primaryKey=((PK1,PK2), PK3, PK4)
matchs := primaryKeyPattern1.FindStringSubmatch(pkStr)
if len(matchs) == 3 {
matched = true
partitionKeyStr = matchs[1]
clusteringKeyStr = matchs[2]
}
// case 2: primaryKey=(PK1,PK2)
if !matched {
matchs = primaryKeyPattern2.FindStringSubmatch(pkStr)
if len(matchs) == 3 {
matched = true
partitionKeyStr = matchs[1]
clusteringKeyStr = matchs[2]
}
}
// case 3: primaryKey=PK1 (only one primary key)
if !matched {
matchs = primaryKeyPattern3.FindStringSubmatch(pkStr)
if len(matchs) == 2 {
matched = true
partitionKeyStr = matchs[1]
clusteringKeyStr = ""
}
}
if !matched {
return nil, fmt.Errorf("invalid primary key: %s", pkStr)
}
partitionKeys := parsePartitionKey(partitionKeyStr)
clusteringKeys, err := parseClusteringKeys(clusteringKeyStr)
if err != nil {
return nil, errors.Wrapf(err, "invalid primary key: %s", pkStr)
}
// TODO optimize this , this is too slow
// search for duplicates
everything := partitionKeys
for _, ck := range clusteringKeys {
everything = append(everything, ck.Name)
}
seen := map[string]bool{}
for v := range everything {
if _, ok := seen[everything[v]]; ok {
return nil, fmt.Errorf("Object %q has duplicate field %q in key struct tag", tableName, everything[v])
}
seen[everything[v]] = true
}
return &PrimaryKey{
PartitionKeys: partitionKeys,
ClusteringKeys: clusteringKeys,
}, nil
} | go | func parsePrimaryKey(tableName, pkStr string) (*PrimaryKey, error) {
// parens must be matched
if !parensBalanced(pkStr) {
return nil, fmt.Errorf("unmatched parentheses: %q", pkStr)
}
// filter out "trailing comma and space"
pkStr = strings.TrimRight(pkStr, ", ")
pkStr = strings.TrimSpace(pkStr)
var partitionKeyStr string
var clusteringKeyStr string
matched := false
// case 1: primaryKey=((PK1,PK2), PK3, PK4)
matchs := primaryKeyPattern1.FindStringSubmatch(pkStr)
if len(matchs) == 3 {
matched = true
partitionKeyStr = matchs[1]
clusteringKeyStr = matchs[2]
}
// case 2: primaryKey=(PK1,PK2)
if !matched {
matchs = primaryKeyPattern2.FindStringSubmatch(pkStr)
if len(matchs) == 3 {
matched = true
partitionKeyStr = matchs[1]
clusteringKeyStr = matchs[2]
}
}
// case 3: primaryKey=PK1 (only one primary key)
if !matched {
matchs = primaryKeyPattern3.FindStringSubmatch(pkStr)
if len(matchs) == 2 {
matched = true
partitionKeyStr = matchs[1]
clusteringKeyStr = ""
}
}
if !matched {
return nil, fmt.Errorf("invalid primary key: %s", pkStr)
}
partitionKeys := parsePartitionKey(partitionKeyStr)
clusteringKeys, err := parseClusteringKeys(clusteringKeyStr)
if err != nil {
return nil, errors.Wrapf(err, "invalid primary key: %s", pkStr)
}
// TODO optimize this , this is too slow
// search for duplicates
everything := partitionKeys
for _, ck := range clusteringKeys {
everything = append(everything, ck.Name)
}
seen := map[string]bool{}
for v := range everything {
if _, ok := seen[everything[v]]; ok {
return nil, fmt.Errorf("Object %q has duplicate field %q in key struct tag", tableName, everything[v])
}
seen[everything[v]] = true
}
return &PrimaryKey{
PartitionKeys: partitionKeys,
ClusteringKeys: clusteringKeys,
}, nil
} | [
"func",
"parsePrimaryKey",
"(",
"tableName",
",",
"pkStr",
"string",
")",
"(",
"*",
"PrimaryKey",
",",
"error",
")",
"{",
"// parens must be matched",
"if",
"!",
"parensBalanced",
"(",
"pkStr",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pkStr",
")",
"\n",
"}",
"\n",
"// filter out \"trailing comma and space\"",
"pkStr",
"=",
"strings",
".",
"TrimRight",
"(",
"pkStr",
",",
"\"",
"\"",
")",
"\n",
"pkStr",
"=",
"strings",
".",
"TrimSpace",
"(",
"pkStr",
")",
"\n\n",
"var",
"partitionKeyStr",
"string",
"\n",
"var",
"clusteringKeyStr",
"string",
"\n",
"matched",
":=",
"false",
"\n",
"// case 1: primaryKey=((PK1,PK2), PK3, PK4)",
"matchs",
":=",
"primaryKeyPattern1",
".",
"FindStringSubmatch",
"(",
"pkStr",
")",
"\n",
"if",
"len",
"(",
"matchs",
")",
"==",
"3",
"{",
"matched",
"=",
"true",
"\n",
"partitionKeyStr",
"=",
"matchs",
"[",
"1",
"]",
"\n",
"clusteringKeyStr",
"=",
"matchs",
"[",
"2",
"]",
"\n",
"}",
"\n\n",
"// case 2: primaryKey=(PK1,PK2)",
"if",
"!",
"matched",
"{",
"matchs",
"=",
"primaryKeyPattern2",
".",
"FindStringSubmatch",
"(",
"pkStr",
")",
"\n",
"if",
"len",
"(",
"matchs",
")",
"==",
"3",
"{",
"matched",
"=",
"true",
"\n",
"partitionKeyStr",
"=",
"matchs",
"[",
"1",
"]",
"\n",
"clusteringKeyStr",
"=",
"matchs",
"[",
"2",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"// case 3: primaryKey=PK1 (only one primary key)",
"if",
"!",
"matched",
"{",
"matchs",
"=",
"primaryKeyPattern3",
".",
"FindStringSubmatch",
"(",
"pkStr",
")",
"\n",
"if",
"len",
"(",
"matchs",
")",
"==",
"2",
"{",
"matched",
"=",
"true",
"\n",
"partitionKeyStr",
"=",
"matchs",
"[",
"1",
"]",
"\n",
"clusteringKeyStr",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"matched",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pkStr",
")",
"\n",
"}",
"\n",
"partitionKeys",
":=",
"parsePartitionKey",
"(",
"partitionKeyStr",
")",
"\n",
"clusteringKeys",
",",
"err",
":=",
"parseClusteringKeys",
"(",
"clusteringKeyStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"pkStr",
")",
"\n",
"}",
"\n\n",
"// TODO optimize this , this is too slow",
"// search for duplicates",
"everything",
":=",
"partitionKeys",
"\n",
"for",
"_",
",",
"ck",
":=",
"range",
"clusteringKeys",
"{",
"everything",
"=",
"append",
"(",
"everything",
",",
"ck",
".",
"Name",
")",
"\n",
"}",
"\n",
"seen",
":=",
"map",
"[",
"string",
"]",
"bool",
"{",
"}",
"\n",
"for",
"v",
":=",
"range",
"everything",
"{",
"if",
"_",
",",
"ok",
":=",
"seen",
"[",
"everything",
"[",
"v",
"]",
"]",
";",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tableName",
",",
"everything",
"[",
"v",
"]",
")",
"\n",
"}",
"\n\n",
"seen",
"[",
"everything",
"[",
"v",
"]",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"return",
"&",
"PrimaryKey",
"{",
"PartitionKeys",
":",
"partitionKeys",
",",
"ClusteringKeys",
":",
"clusteringKeys",
",",
"}",
",",
"nil",
"\n",
"}"
] | // parsePrimaryKey func parses the primary key of DOSA object | [
"parsePrimaryKey",
"func",
"parses",
"the",
"primary",
"key",
"of",
"DOSA",
"object"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity_parser.go#L106-L174 |
4,178 | uber-go/dosa | entity_parser.go | translateKeyName | func translateKeyName(t *Table) {
pk := t.EntityDefinition.Key
for i := range pk.PartitionKeys {
name := pk.PartitionKeys[i]
if v, ok := t.FieldToCol[name]; ok {
pk.PartitionKeys[i] = v
}
}
for i := range pk.ClusteringKeys {
name := pk.ClusteringKeys[i].Name
if v, ok := t.FieldToCol[name]; ok {
pk.ClusteringKeys[i].Name = v
}
}
for _, index := range t.Indexes {
pk := index.Key
for i := range pk.PartitionKeys {
name := pk.PartitionKeys[i]
if v, ok := t.FieldToCol[name]; ok {
pk.PartitionKeys[i] = v
}
}
for i := range pk.ClusteringKeys {
name := pk.ClusteringKeys[i].Name
if v, ok := t.FieldToCol[name]; ok {
pk.ClusteringKeys[i].Name = v
}
}
}
} | go | func translateKeyName(t *Table) {
pk := t.EntityDefinition.Key
for i := range pk.PartitionKeys {
name := pk.PartitionKeys[i]
if v, ok := t.FieldToCol[name]; ok {
pk.PartitionKeys[i] = v
}
}
for i := range pk.ClusteringKeys {
name := pk.ClusteringKeys[i].Name
if v, ok := t.FieldToCol[name]; ok {
pk.ClusteringKeys[i].Name = v
}
}
for _, index := range t.Indexes {
pk := index.Key
for i := range pk.PartitionKeys {
name := pk.PartitionKeys[i]
if v, ok := t.FieldToCol[name]; ok {
pk.PartitionKeys[i] = v
}
}
for i := range pk.ClusteringKeys {
name := pk.ClusteringKeys[i].Name
if v, ok := t.FieldToCol[name]; ok {
pk.ClusteringKeys[i].Name = v
}
}
}
} | [
"func",
"translateKeyName",
"(",
"t",
"*",
"Table",
")",
"{",
"pk",
":=",
"t",
".",
"EntityDefinition",
".",
"Key",
"\n",
"for",
"i",
":=",
"range",
"pk",
".",
"PartitionKeys",
"{",
"name",
":=",
"pk",
".",
"PartitionKeys",
"[",
"i",
"]",
"\n",
"if",
"v",
",",
"ok",
":=",
"t",
".",
"FieldToCol",
"[",
"name",
"]",
";",
"ok",
"{",
"pk",
".",
"PartitionKeys",
"[",
"i",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"pk",
".",
"ClusteringKeys",
"{",
"name",
":=",
"pk",
".",
"ClusteringKeys",
"[",
"i",
"]",
".",
"Name",
"\n",
"if",
"v",
",",
"ok",
":=",
"t",
".",
"FieldToCol",
"[",
"name",
"]",
";",
"ok",
"{",
"pk",
".",
"ClusteringKeys",
"[",
"i",
"]",
".",
"Name",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"index",
":=",
"range",
"t",
".",
"Indexes",
"{",
"pk",
":=",
"index",
".",
"Key",
"\n",
"for",
"i",
":=",
"range",
"pk",
".",
"PartitionKeys",
"{",
"name",
":=",
"pk",
".",
"PartitionKeys",
"[",
"i",
"]",
"\n",
"if",
"v",
",",
"ok",
":=",
"t",
".",
"FieldToCol",
"[",
"name",
"]",
";",
"ok",
"{",
"pk",
".",
"PartitionKeys",
"[",
"i",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"pk",
".",
"ClusteringKeys",
"{",
"name",
":=",
"pk",
".",
"ClusteringKeys",
"[",
"i",
"]",
".",
"Name",
"\n",
"if",
"v",
",",
"ok",
":=",
"t",
".",
"FieldToCol",
"[",
"name",
"]",
";",
"ok",
"{",
"pk",
".",
"ClusteringKeys",
"[",
"i",
"]",
".",
"Name",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // translateKeyName translate the primary keys to the internal column name based on the mapping
// between fields and columns. | [
"translateKeyName",
"translate",
"the",
"primary",
"keys",
"to",
"the",
"internal",
"column",
"name",
"based",
"on",
"the",
"mapping",
"between",
"fields",
"and",
"columns",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity_parser.go#L244-L276 |
4,179 | uber-go/dosa | entity_parser.go | parseIndexTag | func parseIndexTag(indexName, dosaAnnotation string) (string, *PrimaryKey, error) {
// index name struct must be exported in the entity,
// otherwise it will be ignored when upserting the schema.
if len(indexName) != 0 && unicode.IsLower([]rune(indexName)[0]) {
expected := []rune(indexName)
expected[0] = unicode.ToUpper(expected[0])
return "", nil, fmt.Errorf("index name (%s) must be exported, "+
"try (%s) instead", indexName, string(expected))
}
tag := dosaAnnotation
// find the primaryKey
matchs := indexKeyPattern0.FindStringSubmatch(tag)
if len(matchs) != 4 {
return "", nil, fmt.Errorf("dosa.Index %s with an invalid dosa index tag %q", indexName, tag)
}
pkString := matchs[1]
key, err := parsePrimaryKey(indexName, pkString)
if err != nil {
return "", nil, errors.Wrapf(err, "struct %s has an invalid index key %q", indexName, pkString)
}
toRemove := strings.TrimSuffix(matchs[0], matchs[2])
toRemove = strings.TrimSuffix(matchs[0], matchs[3])
tag = strings.Replace(tag, toRemove, "", 1)
//find the name
fullNameTag, name, err := parseNameTag(tag, indexName)
if err != nil {
return "", nil, errors.Wrapf(err, "invalid name tag: %s", tag)
}
tag = strings.Replace(tag, fullNameTag, "", 1)
tag = strings.TrimSpace(tag)
if tag != "" {
return "", nil, fmt.Errorf("index field %s with an invalid dosa index tag: %s", indexName, tag)
}
return name, key, nil
} | go | func parseIndexTag(indexName, dosaAnnotation string) (string, *PrimaryKey, error) {
// index name struct must be exported in the entity,
// otherwise it will be ignored when upserting the schema.
if len(indexName) != 0 && unicode.IsLower([]rune(indexName)[0]) {
expected := []rune(indexName)
expected[0] = unicode.ToUpper(expected[0])
return "", nil, fmt.Errorf("index name (%s) must be exported, "+
"try (%s) instead", indexName, string(expected))
}
tag := dosaAnnotation
// find the primaryKey
matchs := indexKeyPattern0.FindStringSubmatch(tag)
if len(matchs) != 4 {
return "", nil, fmt.Errorf("dosa.Index %s with an invalid dosa index tag %q", indexName, tag)
}
pkString := matchs[1]
key, err := parsePrimaryKey(indexName, pkString)
if err != nil {
return "", nil, errors.Wrapf(err, "struct %s has an invalid index key %q", indexName, pkString)
}
toRemove := strings.TrimSuffix(matchs[0], matchs[2])
toRemove = strings.TrimSuffix(matchs[0], matchs[3])
tag = strings.Replace(tag, toRemove, "", 1)
//find the name
fullNameTag, name, err := parseNameTag(tag, indexName)
if err != nil {
return "", nil, errors.Wrapf(err, "invalid name tag: %s", tag)
}
tag = strings.Replace(tag, fullNameTag, "", 1)
tag = strings.TrimSpace(tag)
if tag != "" {
return "", nil, fmt.Errorf("index field %s with an invalid dosa index tag: %s", indexName, tag)
}
return name, key, nil
} | [
"func",
"parseIndexTag",
"(",
"indexName",
",",
"dosaAnnotation",
"string",
")",
"(",
"string",
",",
"*",
"PrimaryKey",
",",
"error",
")",
"{",
"// index name struct must be exported in the entity,",
"// otherwise it will be ignored when upserting the schema.",
"if",
"len",
"(",
"indexName",
")",
"!=",
"0",
"&&",
"unicode",
".",
"IsLower",
"(",
"[",
"]",
"rune",
"(",
"indexName",
")",
"[",
"0",
"]",
")",
"{",
"expected",
":=",
"[",
"]",
"rune",
"(",
"indexName",
")",
"\n",
"expected",
"[",
"0",
"]",
"=",
"unicode",
".",
"ToUpper",
"(",
"expected",
"[",
"0",
"]",
")",
"\n",
"return",
"\"",
"\"",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"indexName",
",",
"string",
"(",
"expected",
")",
")",
"\n",
"}",
"\n",
"tag",
":=",
"dosaAnnotation",
"\n",
"// find the primaryKey",
"matchs",
":=",
"indexKeyPattern0",
".",
"FindStringSubmatch",
"(",
"tag",
")",
"\n",
"if",
"len",
"(",
"matchs",
")",
"!=",
"4",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"indexName",
",",
"tag",
")",
"\n",
"}",
"\n",
"pkString",
":=",
"matchs",
"[",
"1",
"]",
"\n",
"key",
",",
"err",
":=",
"parsePrimaryKey",
"(",
"indexName",
",",
"pkString",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"indexName",
",",
"pkString",
")",
"\n",
"}",
"\n",
"toRemove",
":=",
"strings",
".",
"TrimSuffix",
"(",
"matchs",
"[",
"0",
"]",
",",
"matchs",
"[",
"2",
"]",
")",
"\n",
"toRemove",
"=",
"strings",
".",
"TrimSuffix",
"(",
"matchs",
"[",
"0",
"]",
",",
"matchs",
"[",
"3",
"]",
")",
"\n",
"tag",
"=",
"strings",
".",
"Replace",
"(",
"tag",
",",
"toRemove",
",",
"\"",
"\"",
",",
"1",
")",
"\n\n",
"//find the name",
"fullNameTag",
",",
"name",
",",
"err",
":=",
"parseNameTag",
"(",
"tag",
",",
"indexName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"tag",
")",
"\n",
"}",
"\n\n",
"tag",
"=",
"strings",
".",
"Replace",
"(",
"tag",
",",
"fullNameTag",
",",
"\"",
"\"",
",",
"1",
")",
"\n",
"tag",
"=",
"strings",
".",
"TrimSpace",
"(",
"tag",
")",
"\n",
"if",
"tag",
"!=",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"indexName",
",",
"tag",
")",
"\n",
"}",
"\n\n",
"return",
"name",
",",
"key",
",",
"nil",
"\n",
"}"
] | // parseIndexTag functions parses DOSA index tag | [
"parseIndexTag",
"functions",
"parses",
"DOSA",
"index",
"tag"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity_parser.go#L279-L316 |
4,180 | uber-go/dosa | entity_parser.go | parseNameTag | func parseNameTag(tag, defaultName string) (string, string, error) {
fullNameTag := ""
name := defaultName
matches := namePattern0.FindStringSubmatch(tag)
if len(matches) == 2 {
fullNameTag = matches[0]
name = matches[1]
}
// filter out "trailing comma"
name = strings.TrimRight(name, " ,")
var err error
name, err = NormalizeName(name)
if err != nil {
return "", "", err
}
return fullNameTag, name, nil
} | go | func parseNameTag(tag, defaultName string) (string, string, error) {
fullNameTag := ""
name := defaultName
matches := namePattern0.FindStringSubmatch(tag)
if len(matches) == 2 {
fullNameTag = matches[0]
name = matches[1]
}
// filter out "trailing comma"
name = strings.TrimRight(name, " ,")
var err error
name, err = NormalizeName(name)
if err != nil {
return "", "", err
}
return fullNameTag, name, nil
} | [
"func",
"parseNameTag",
"(",
"tag",
",",
"defaultName",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"fullNameTag",
":=",
"\"",
"\"",
"\n",
"name",
":=",
"defaultName",
"\n\n",
"matches",
":=",
"namePattern0",
".",
"FindStringSubmatch",
"(",
"tag",
")",
"\n",
"if",
"len",
"(",
"matches",
")",
"==",
"2",
"{",
"fullNameTag",
"=",
"matches",
"[",
"0",
"]",
"\n",
"name",
"=",
"matches",
"[",
"1",
"]",
"\n",
"}",
"\n\n",
"// filter out \"trailing comma\"",
"name",
"=",
"strings",
".",
"TrimRight",
"(",
"name",
",",
"\"",
"\"",
")",
"\n\n",
"var",
"err",
"error",
"\n",
"name",
",",
"err",
"=",
"NormalizeName",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"fullNameTag",
",",
"name",
",",
"nil",
"\n",
"}"
] | // parseNameTag functions parses DOSA "name" tag | [
"parseNameTag",
"functions",
"parses",
"DOSA",
"name",
"tag"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity_parser.go#L319-L339 |
4,181 | uber-go/dosa | entity_parser.go | parseETLTag | func parseETLTag(tag string) (string, ETLState, error) {
fullETLTag := ""
etlTag := ""
matches := etlPattern0.FindStringSubmatch(tag)
if len(matches) == 2 {
fullETLTag = matches[0]
etlTag = matches[1]
}
if len(matches) == 0 {
return "", EtlOff, nil
}
// filter out "trailing comma"
etlTag = strings.TrimRight(etlTag, " ,")
var err error
etlTag, err = NormalizeName(etlTag)
if err != nil {
return "", EtlOff, err
}
etlState, err := ToETLState(etlTag)
if err != nil {
return "", EtlOff, err
}
return fullETLTag, etlState, nil
} | go | func parseETLTag(tag string) (string, ETLState, error) {
fullETLTag := ""
etlTag := ""
matches := etlPattern0.FindStringSubmatch(tag)
if len(matches) == 2 {
fullETLTag = matches[0]
etlTag = matches[1]
}
if len(matches) == 0 {
return "", EtlOff, nil
}
// filter out "trailing comma"
etlTag = strings.TrimRight(etlTag, " ,")
var err error
etlTag, err = NormalizeName(etlTag)
if err != nil {
return "", EtlOff, err
}
etlState, err := ToETLState(etlTag)
if err != nil {
return "", EtlOff, err
}
return fullETLTag, etlState, nil
} | [
"func",
"parseETLTag",
"(",
"tag",
"string",
")",
"(",
"string",
",",
"ETLState",
",",
"error",
")",
"{",
"fullETLTag",
":=",
"\"",
"\"",
"\n",
"etlTag",
":=",
"\"",
"\"",
"\n",
"matches",
":=",
"etlPattern0",
".",
"FindStringSubmatch",
"(",
"tag",
")",
"\n",
"if",
"len",
"(",
"matches",
")",
"==",
"2",
"{",
"fullETLTag",
"=",
"matches",
"[",
"0",
"]",
"\n",
"etlTag",
"=",
"matches",
"[",
"1",
"]",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"matches",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"EtlOff",
",",
"nil",
"\n",
"}",
"\n\n",
"// filter out \"trailing comma\"",
"etlTag",
"=",
"strings",
".",
"TrimRight",
"(",
"etlTag",
",",
"\"",
"\"",
")",
"\n\n",
"var",
"err",
"error",
"\n",
"etlTag",
",",
"err",
"=",
"NormalizeName",
"(",
"etlTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"EtlOff",
",",
"err",
"\n",
"}",
"\n\n",
"etlState",
",",
"err",
":=",
"ToETLState",
"(",
"etlTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"EtlOff",
",",
"err",
"\n",
"}",
"\n",
"return",
"fullETLTag",
",",
"etlState",
",",
"nil",
"\n",
"}"
] | // parseETLTag functions parses DOSA "etl" tag | [
"parseETLTag",
"functions",
"parses",
"DOSA",
"etl",
"tag"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity_parser.go#L342-L369 |
4,182 | uber-go/dosa | entity_parser.go | parseTTLTag | func parseTTLTag(tag string) (string, time.Duration, error) {
fullTTLTag := ""
ttlTag := ""
matches := ttlPattern0.FindStringSubmatch(tag)
if len(matches) == 0 {
return "", NoTTL(), nil
}
if len(matches) == 2 {
fullTTLTag = matches[0]
ttlTag = matches[1]
}
// filter out "trailing comma"
ttlTag = strings.TrimRight(ttlTag, " ,")
ttl, err := time.ParseDuration(ttlTag)
if err != nil {
return "", NoTTL(), err
}
if err = ValidateTTL(ttl); err != nil {
return "", NoTTL(), err
}
return fullTTLTag, ttl, nil
} | go | func parseTTLTag(tag string) (string, time.Duration, error) {
fullTTLTag := ""
ttlTag := ""
matches := ttlPattern0.FindStringSubmatch(tag)
if len(matches) == 0 {
return "", NoTTL(), nil
}
if len(matches) == 2 {
fullTTLTag = matches[0]
ttlTag = matches[1]
}
// filter out "trailing comma"
ttlTag = strings.TrimRight(ttlTag, " ,")
ttl, err := time.ParseDuration(ttlTag)
if err != nil {
return "", NoTTL(), err
}
if err = ValidateTTL(ttl); err != nil {
return "", NoTTL(), err
}
return fullTTLTag, ttl, nil
} | [
"func",
"parseTTLTag",
"(",
"tag",
"string",
")",
"(",
"string",
",",
"time",
".",
"Duration",
",",
"error",
")",
"{",
"fullTTLTag",
":=",
"\"",
"\"",
"\n",
"ttlTag",
":=",
"\"",
"\"",
"\n",
"matches",
":=",
"ttlPattern0",
".",
"FindStringSubmatch",
"(",
"tag",
")",
"\n\n",
"if",
"len",
"(",
"matches",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"NoTTL",
"(",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"matches",
")",
"==",
"2",
"{",
"fullTTLTag",
"=",
"matches",
"[",
"0",
"]",
"\n",
"ttlTag",
"=",
"matches",
"[",
"1",
"]",
"\n",
"}",
"\n\n",
"// filter out \"trailing comma\"",
"ttlTag",
"=",
"strings",
".",
"TrimRight",
"(",
"ttlTag",
",",
"\"",
"\"",
")",
"\n",
"ttl",
",",
"err",
":=",
"time",
".",
"ParseDuration",
"(",
"ttlTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"NoTTL",
"(",
")",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"ValidateTTL",
"(",
"ttl",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"NoTTL",
"(",
")",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"fullTTLTag",
",",
"ttl",
",",
"nil",
"\n",
"}"
] | // parseTTLTag functions parses DOSA "ttl" tag | [
"parseTTLTag",
"functions",
"parses",
"DOSA",
"ttl",
"tag"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity_parser.go#L372-L398 |
4,183 | uber-go/dosa | entity_parser.go | parseEntityTag | func parseEntityTag(structName, dosaAnnotation string) (string, time.Duration, ETLState, *PrimaryKey, error) {
tag := dosaAnnotation
// find the primaryKey
matchs := primaryKeyPattern0.FindStringSubmatch(tag)
if len(matchs) != primaryKeyPattern0.NumSubexp()+1 {
return "", NoTTL(), EtlOff, nil, fmt.Errorf("dosa.Entity on object %s with an invalid dosa struct tag %q", structName, tag)
}
pkString := matchs[1]
key, err := parsePrimaryKey(structName, pkString)
if err != nil {
return "", NoTTL(), EtlOff, nil, errors.Wrapf(err, "struct %s has an invalid primary key %q", structName, pkString)
}
toRemove := strings.TrimSuffix(matchs[0], matchs[2])
toRemove = strings.TrimSuffix(matchs[0], matchs[3])
tag = strings.Replace(tag, toRemove, "", 1)
// find the name
fullNameTag, name, err := parseNameTag(tag, structName)
if err != nil {
return "", NoTTL(), EtlOff, nil, errors.Wrapf(err, "invalid name tag: %s", tag)
}
tag = strings.Replace(tag, fullNameTag, "", 1)
// find the ETL flag
fullETLTag, etlState, err := parseETLTag(tag)
if err != nil {
return "", NoTTL(), EtlOff, nil, errors.Wrapf(err, "invalid etl tag: %s", tag)
}
tag = strings.Replace(tag, fullETLTag, "", 1)
// find the ttl flag
fullTTLTag, ttl, err := parseTTLTag(tag)
if err != nil {
return "", NoTTL(), EtlOff, nil, errors.Wrapf(err, "invalid ttl tag: %s", tag)
}
tag = strings.Replace(tag, fullTTLTag, "", 1)
tag = strings.TrimSpace(tag)
if tag != "" {
return "", NoTTL(), EtlOff, nil, fmt.Errorf("struct %s with an invalid dosa struct tag: %s", structName, tag)
}
return name, ttl, etlState, key, nil
} | go | func parseEntityTag(structName, dosaAnnotation string) (string, time.Duration, ETLState, *PrimaryKey, error) {
tag := dosaAnnotation
// find the primaryKey
matchs := primaryKeyPattern0.FindStringSubmatch(tag)
if len(matchs) != primaryKeyPattern0.NumSubexp()+1 {
return "", NoTTL(), EtlOff, nil, fmt.Errorf("dosa.Entity on object %s with an invalid dosa struct tag %q", structName, tag)
}
pkString := matchs[1]
key, err := parsePrimaryKey(structName, pkString)
if err != nil {
return "", NoTTL(), EtlOff, nil, errors.Wrapf(err, "struct %s has an invalid primary key %q", structName, pkString)
}
toRemove := strings.TrimSuffix(matchs[0], matchs[2])
toRemove = strings.TrimSuffix(matchs[0], matchs[3])
tag = strings.Replace(tag, toRemove, "", 1)
// find the name
fullNameTag, name, err := parseNameTag(tag, structName)
if err != nil {
return "", NoTTL(), EtlOff, nil, errors.Wrapf(err, "invalid name tag: %s", tag)
}
tag = strings.Replace(tag, fullNameTag, "", 1)
// find the ETL flag
fullETLTag, etlState, err := parseETLTag(tag)
if err != nil {
return "", NoTTL(), EtlOff, nil, errors.Wrapf(err, "invalid etl tag: %s", tag)
}
tag = strings.Replace(tag, fullETLTag, "", 1)
// find the ttl flag
fullTTLTag, ttl, err := parseTTLTag(tag)
if err != nil {
return "", NoTTL(), EtlOff, nil, errors.Wrapf(err, "invalid ttl tag: %s", tag)
}
tag = strings.Replace(tag, fullTTLTag, "", 1)
tag = strings.TrimSpace(tag)
if tag != "" {
return "", NoTTL(), EtlOff, nil, fmt.Errorf("struct %s with an invalid dosa struct tag: %s", structName, tag)
}
return name, ttl, etlState, key, nil
} | [
"func",
"parseEntityTag",
"(",
"structName",
",",
"dosaAnnotation",
"string",
")",
"(",
"string",
",",
"time",
".",
"Duration",
",",
"ETLState",
",",
"*",
"PrimaryKey",
",",
"error",
")",
"{",
"tag",
":=",
"dosaAnnotation",
"\n\n",
"// find the primaryKey",
"matchs",
":=",
"primaryKeyPattern0",
".",
"FindStringSubmatch",
"(",
"tag",
")",
"\n",
"if",
"len",
"(",
"matchs",
")",
"!=",
"primaryKeyPattern0",
".",
"NumSubexp",
"(",
")",
"+",
"1",
"{",
"return",
"\"",
"\"",
",",
"NoTTL",
"(",
")",
",",
"EtlOff",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"structName",
",",
"tag",
")",
"\n",
"}",
"\n",
"pkString",
":=",
"matchs",
"[",
"1",
"]",
"\n\n",
"key",
",",
"err",
":=",
"parsePrimaryKey",
"(",
"structName",
",",
"pkString",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"NoTTL",
"(",
")",
",",
"EtlOff",
",",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"structName",
",",
"pkString",
")",
"\n",
"}",
"\n",
"toRemove",
":=",
"strings",
".",
"TrimSuffix",
"(",
"matchs",
"[",
"0",
"]",
",",
"matchs",
"[",
"2",
"]",
")",
"\n",
"toRemove",
"=",
"strings",
".",
"TrimSuffix",
"(",
"matchs",
"[",
"0",
"]",
",",
"matchs",
"[",
"3",
"]",
")",
"\n",
"tag",
"=",
"strings",
".",
"Replace",
"(",
"tag",
",",
"toRemove",
",",
"\"",
"\"",
",",
"1",
")",
"\n\n",
"// find the name",
"fullNameTag",
",",
"name",
",",
"err",
":=",
"parseNameTag",
"(",
"tag",
",",
"structName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"NoTTL",
"(",
")",
",",
"EtlOff",
",",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"tag",
")",
"\n",
"}",
"\n",
"tag",
"=",
"strings",
".",
"Replace",
"(",
"tag",
",",
"fullNameTag",
",",
"\"",
"\"",
",",
"1",
")",
"\n\n",
"// find the ETL flag",
"fullETLTag",
",",
"etlState",
",",
"err",
":=",
"parseETLTag",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"NoTTL",
"(",
")",
",",
"EtlOff",
",",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"tag",
")",
"\n",
"}",
"\n",
"tag",
"=",
"strings",
".",
"Replace",
"(",
"tag",
",",
"fullETLTag",
",",
"\"",
"\"",
",",
"1",
")",
"\n\n",
"// find the ttl flag",
"fullTTLTag",
",",
"ttl",
",",
"err",
":=",
"parseTTLTag",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"NoTTL",
"(",
")",
",",
"EtlOff",
",",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"tag",
")",
"\n",
"}",
"\n",
"tag",
"=",
"strings",
".",
"Replace",
"(",
"tag",
",",
"fullTTLTag",
",",
"\"",
"\"",
",",
"1",
")",
"\n\n",
"tag",
"=",
"strings",
".",
"TrimSpace",
"(",
"tag",
")",
"\n",
"if",
"tag",
"!=",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"NoTTL",
"(",
")",
",",
"EtlOff",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"structName",
",",
"tag",
")",
"\n",
"}",
"\n\n",
"return",
"name",
",",
"ttl",
",",
"etlState",
",",
"key",
",",
"nil",
"\n",
"}"
] | // parseEntityTag function parses DOSA tag on the "Entity" field | [
"parseEntityTag",
"function",
"parses",
"DOSA",
"tag",
"on",
"the",
"Entity",
"field"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity_parser.go#L401-L446 |
4,184 | uber-go/dosa | entity_parser.go | parseFieldTag | func parseFieldTag(structField reflect.StructField, dosaAnnotation string) (*ColumnDefinition, error) {
typ, isPointer, err := typify(structField.Type)
if err != nil {
return nil, err
}
return parseField(typ, isPointer, structField.Name, dosaAnnotation)
} | go | func parseFieldTag(structField reflect.StructField, dosaAnnotation string) (*ColumnDefinition, error) {
typ, isPointer, err := typify(structField.Type)
if err != nil {
return nil, err
}
return parseField(typ, isPointer, structField.Name, dosaAnnotation)
} | [
"func",
"parseFieldTag",
"(",
"structField",
"reflect",
".",
"StructField",
",",
"dosaAnnotation",
"string",
")",
"(",
"*",
"ColumnDefinition",
",",
"error",
")",
"{",
"typ",
",",
"isPointer",
",",
"err",
":=",
"typify",
"(",
"structField",
".",
"Type",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"parseField",
"(",
"typ",
",",
"isPointer",
",",
"structField",
".",
"Name",
",",
"dosaAnnotation",
")",
"\n",
"}"
] | // parseFieldTag function parses DOSA tag on the fields in the DOSA struct except the "Entity" field | [
"parseFieldTag",
"function",
"parses",
"DOSA",
"tag",
"on",
"the",
"fields",
"in",
"the",
"DOSA",
"struct",
"except",
"the",
"Entity",
"field"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/entity_parser.go#L449-L455 |
4,185 | uber-go/dosa | type.go | Bytes | func (u UUID) Bytes() ([]byte, error) {
id, err := uuid.FromString(string(u))
if err != nil {
return nil, errors.Wrap(err, "invalid uuid string")
}
return id.Bytes(), nil
} | go | func (u UUID) Bytes() ([]byte, error) {
id, err := uuid.FromString(string(u))
if err != nil {
return nil, errors.Wrap(err, "invalid uuid string")
}
return id.Bytes(), nil
} | [
"func",
"(",
"u",
"UUID",
")",
"Bytes",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"id",
",",
"err",
":=",
"uuid",
".",
"FromString",
"(",
"string",
"(",
"u",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"id",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Bytes gets the bytes from a UUID | [
"Bytes",
"gets",
"the",
"bytes",
"from",
"a",
"UUID"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/type.go#L74-L80 |
4,186 | uber-go/dosa | type.go | BytesToUUID | func BytesToUUID(bs []byte) (UUID, error) {
id, err := uuid.FromBytes(bs)
if err != nil {
return "", errors.Wrap(err, "invalid uuid bytes")
}
return UUID(id.String()), nil
} | go | func BytesToUUID(bs []byte) (UUID, error) {
id, err := uuid.FromBytes(bs)
if err != nil {
return "", errors.Wrap(err, "invalid uuid bytes")
}
return UUID(id.String()), nil
} | [
"func",
"BytesToUUID",
"(",
"bs",
"[",
"]",
"byte",
")",
"(",
"UUID",
",",
"error",
")",
"{",
"id",
",",
"err",
":=",
"uuid",
".",
"FromBytes",
"(",
"bs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"UUID",
"(",
"id",
".",
"String",
"(",
")",
")",
",",
"nil",
"\n",
"}"
] | // BytesToUUID creates a UUID from a byte slice | [
"BytesToUUID",
"creates",
"a",
"UUID",
"from",
"a",
"byte",
"slice"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/type.go#L83-L89 |
4,187 | uber-go/dosa | type.go | FromString | func FromString(s string) Type {
switch s {
case TUUID.String():
return TUUID
case String.String():
return String
case Int32.String():
return Int32
case Int64.String():
return Int64
case Double.String():
return Double
case Blob.String():
return Blob
case Timestamp.String():
return Timestamp
case Bool.String():
return Bool
default:
return Invalid
}
} | go | func FromString(s string) Type {
switch s {
case TUUID.String():
return TUUID
case String.String():
return String
case Int32.String():
return Int32
case Int64.String():
return Int64
case Double.String():
return Double
case Blob.String():
return Blob
case Timestamp.String():
return Timestamp
case Bool.String():
return Bool
default:
return Invalid
}
} | [
"func",
"FromString",
"(",
"s",
"string",
")",
"Type",
"{",
"switch",
"s",
"{",
"case",
"TUUID",
".",
"String",
"(",
")",
":",
"return",
"TUUID",
"\n",
"case",
"String",
".",
"String",
"(",
")",
":",
"return",
"String",
"\n",
"case",
"Int32",
".",
"String",
"(",
")",
":",
"return",
"Int32",
"\n",
"case",
"Int64",
".",
"String",
"(",
")",
":",
"return",
"Int64",
"\n",
"case",
"Double",
".",
"String",
"(",
")",
":",
"return",
"Double",
"\n",
"case",
"Blob",
".",
"String",
"(",
")",
":",
"return",
"Blob",
"\n",
"case",
"Timestamp",
".",
"String",
"(",
")",
":",
"return",
"Timestamp",
"\n",
"case",
"Bool",
".",
"String",
"(",
")",
":",
"return",
"Bool",
"\n",
"default",
":",
"return",
"Invalid",
"\n",
"}",
"\n",
"}"
] | // FromString converts string to dosa Type | [
"FromString",
"converts",
"string",
"to",
"dosa",
"Type"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/type.go#L92-L113 |
4,188 | uber-go/dosa | user.go | GetUsername | func GetUsername() *string {
// user.Current only fails on some internal cache error: not sure what
// corrective action is appropriate... on failure return NULL.
if u, err := user.Current(); err == nil {
return &u.Username
}
return nil
} | go | func GetUsername() *string {
// user.Current only fails on some internal cache error: not sure what
// corrective action is appropriate... on failure return NULL.
if u, err := user.Current(); err == nil {
return &u.Username
}
return nil
} | [
"func",
"GetUsername",
"(",
")",
"*",
"string",
"{",
"// user.Current only fails on some internal cache error: not sure what",
"// corrective action is appropriate... on failure return NULL.",
"if",
"u",
",",
"err",
":=",
"user",
".",
"Current",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"&",
"u",
".",
"Username",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // GetUsername returns the username of the current user. | [
"GetUsername",
"returns",
"the",
"username",
"of",
"the",
"current",
"user",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/user.go#L26-L33 |
4,189 | uber-go/dosa | schema/avro/avro.go | ToAvro | func ToAvro(namePrefix string, ed *dosa.EntityDefinition) ([]byte, error) {
fields := make([]*Field, len(ed.Columns))
for i, c := range ed.Columns {
props := make(map[string]string)
props[dosaTypeKey] = c.Type.String()
// TODO add tags
fields[i] = &Field{
Name: c.Name,
Type: avroTypes[c.Type],
Properties: props,
Default: nil,
}
}
meta := make(map[string]interface{})
meta[partitionKeys] = ed.Key.PartitionKeys
meta[clusteringKeys] = ed.Key.ClusteringKeys
meta[indexKeys] = ed.Indexes
ar := &Record{
Name: ed.Name,
Namespace: namePrefix,
Fields: fields,
Properties: meta,
}
bs, err := ar.MarshalJSON()
if err != nil {
return nil, errors.Wrap(err, "failed to serialize avro schema into json")
}
return bs, nil
} | go | func ToAvro(namePrefix string, ed *dosa.EntityDefinition) ([]byte, error) {
fields := make([]*Field, len(ed.Columns))
for i, c := range ed.Columns {
props := make(map[string]string)
props[dosaTypeKey] = c.Type.String()
// TODO add tags
fields[i] = &Field{
Name: c.Name,
Type: avroTypes[c.Type],
Properties: props,
Default: nil,
}
}
meta := make(map[string]interface{})
meta[partitionKeys] = ed.Key.PartitionKeys
meta[clusteringKeys] = ed.Key.ClusteringKeys
meta[indexKeys] = ed.Indexes
ar := &Record{
Name: ed.Name,
Namespace: namePrefix,
Fields: fields,
Properties: meta,
}
bs, err := ar.MarshalJSON()
if err != nil {
return nil, errors.Wrap(err, "failed to serialize avro schema into json")
}
return bs, nil
} | [
"func",
"ToAvro",
"(",
"namePrefix",
"string",
",",
"ed",
"*",
"dosa",
".",
"EntityDefinition",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"fields",
":=",
"make",
"(",
"[",
"]",
"*",
"Field",
",",
"len",
"(",
"ed",
".",
"Columns",
")",
")",
"\n",
"for",
"i",
",",
"c",
":=",
"range",
"ed",
".",
"Columns",
"{",
"props",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"props",
"[",
"dosaTypeKey",
"]",
"=",
"c",
".",
"Type",
".",
"String",
"(",
")",
"\n",
"// TODO add tags",
"fields",
"[",
"i",
"]",
"=",
"&",
"Field",
"{",
"Name",
":",
"c",
".",
"Name",
",",
"Type",
":",
"avroTypes",
"[",
"c",
".",
"Type",
"]",
",",
"Properties",
":",
"props",
",",
"Default",
":",
"nil",
",",
"}",
"\n",
"}",
"\n\n",
"meta",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"meta",
"[",
"partitionKeys",
"]",
"=",
"ed",
".",
"Key",
".",
"PartitionKeys",
"\n",
"meta",
"[",
"clusteringKeys",
"]",
"=",
"ed",
".",
"Key",
".",
"ClusteringKeys",
"\n",
"meta",
"[",
"indexKeys",
"]",
"=",
"ed",
".",
"Indexes",
"\n\n",
"ar",
":=",
"&",
"Record",
"{",
"Name",
":",
"ed",
".",
"Name",
",",
"Namespace",
":",
"namePrefix",
",",
"Fields",
":",
"fields",
",",
"Properties",
":",
"meta",
",",
"}",
"\n\n",
"bs",
",",
"err",
":=",
"ar",
".",
"MarshalJSON",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"bs",
",",
"nil",
"\n",
"}"
] | // ToAvro converts dosa entity definition to avro schema | [
"ToAvro",
"converts",
"dosa",
"entity",
"definition",
"to",
"avro",
"schema"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/schema/avro/avro.go#L135-L166 |
4,190 | uber-go/dosa | schema/avro/avro.go | FromAvro | func FromAvro(data string) (*dosa.EntityDefinition, error) {
schema, err := gv.ParseSchema(data)
if err != nil {
return nil, errors.Wrap(err, "failed to parse avro schema from json")
}
pks, err := decodePartitionKeysFromSchema(schema)
if err != nil {
return nil, errors.Wrap(err, "failed to parse avro schema for partition keys")
}
cks, err := decodeClusteringKeysFromSchema(schema)
if err != nil {
return nil, errors.Wrap(err, "failed to parse avro schema for clustering keys")
}
rs, ok := schema.(*gv.RecordSchema)
if !ok {
return nil, errors.New("fail to parse avro schema")
}
cols, err := decodeFields(rs.Fields)
if err != nil {
return nil, errors.Wrap(err, "failed to parse avro schema for fields")
}
// index
idx, err := decodeIndexes(schema)
if err != nil {
return nil, errors.Wrap(err, "failed to parse avro schema for index")
}
return &dosa.EntityDefinition{
Name: schema.GetName(),
Key: &dosa.PrimaryKey{
PartitionKeys: pks,
ClusteringKeys: cks,
},
Columns: cols,
Indexes: idx,
}, nil
} | go | func FromAvro(data string) (*dosa.EntityDefinition, error) {
schema, err := gv.ParseSchema(data)
if err != nil {
return nil, errors.Wrap(err, "failed to parse avro schema from json")
}
pks, err := decodePartitionKeysFromSchema(schema)
if err != nil {
return nil, errors.Wrap(err, "failed to parse avro schema for partition keys")
}
cks, err := decodeClusteringKeysFromSchema(schema)
if err != nil {
return nil, errors.Wrap(err, "failed to parse avro schema for clustering keys")
}
rs, ok := schema.(*gv.RecordSchema)
if !ok {
return nil, errors.New("fail to parse avro schema")
}
cols, err := decodeFields(rs.Fields)
if err != nil {
return nil, errors.Wrap(err, "failed to parse avro schema for fields")
}
// index
idx, err := decodeIndexes(schema)
if err != nil {
return nil, errors.Wrap(err, "failed to parse avro schema for index")
}
return &dosa.EntityDefinition{
Name: schema.GetName(),
Key: &dosa.PrimaryKey{
PartitionKeys: pks,
ClusteringKeys: cks,
},
Columns: cols,
Indexes: idx,
}, nil
} | [
"func",
"FromAvro",
"(",
"data",
"string",
")",
"(",
"*",
"dosa",
".",
"EntityDefinition",
",",
"error",
")",
"{",
"schema",
",",
"err",
":=",
"gv",
".",
"ParseSchema",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"pks",
",",
"err",
":=",
"decodePartitionKeysFromSchema",
"(",
"schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"cks",
",",
"err",
":=",
"decodeClusteringKeysFromSchema",
"(",
"schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"rs",
",",
"ok",
":=",
"schema",
".",
"(",
"*",
"gv",
".",
"RecordSchema",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"cols",
",",
"err",
":=",
"decodeFields",
"(",
"rs",
".",
"Fields",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// index",
"idx",
",",
"err",
":=",
"decodeIndexes",
"(",
"schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"dosa",
".",
"EntityDefinition",
"{",
"Name",
":",
"schema",
".",
"GetName",
"(",
")",
",",
"Key",
":",
"&",
"dosa",
".",
"PrimaryKey",
"{",
"PartitionKeys",
":",
"pks",
",",
"ClusteringKeys",
":",
"cks",
",",
"}",
",",
"Columns",
":",
"cols",
",",
"Indexes",
":",
"idx",
",",
"}",
",",
"nil",
"\n",
"}"
] | // FromAvro converts avro schema to dosa entity definition | [
"FromAvro",
"converts",
"avro",
"schema",
"to",
"dosa",
"entity",
"definition"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/schema/avro/avro.go#L169-L210 |
4,191 | uber-go/dosa | cmd/dosa/options.go | UnmarshalFlag | func (t *timeFlag) UnmarshalFlag(value string) error {
valueInt, err := strconv.Atoi(value)
if err == nil {
// We received a number without a unit, assume milliseconds.
t.setDuration(time.Duration(valueInt) * time.Millisecond)
return nil
}
d, err := time.ParseDuration(value)
if err != nil {
return err
}
t.setDuration(d)
return nil
} | go | func (t *timeFlag) UnmarshalFlag(value string) error {
valueInt, err := strconv.Atoi(value)
if err == nil {
// We received a number without a unit, assume milliseconds.
t.setDuration(time.Duration(valueInt) * time.Millisecond)
return nil
}
d, err := time.ParseDuration(value)
if err != nil {
return err
}
t.setDuration(d)
return nil
} | [
"func",
"(",
"t",
"*",
"timeFlag",
")",
"UnmarshalFlag",
"(",
"value",
"string",
")",
"error",
"{",
"valueInt",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"value",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// We received a number without a unit, assume milliseconds.",
"t",
".",
"setDuration",
"(",
"time",
".",
"Duration",
"(",
"valueInt",
")",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"d",
",",
"err",
":=",
"time",
".",
"ParseDuration",
"(",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"t",
".",
"setDuration",
"(",
"d",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // UmarshalFlag satisfies the flag interface | [
"UmarshalFlag",
"satisfies",
"the",
"flag",
"interface"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/options.go#L77-L92 |
4,192 | uber-go/dosa | cmd/dosa/client.go | newShellQueryClient | func newShellQueryClient(reg dosa.Registrar, conn dosa.Connector) ShellQueryClient {
return &shellQueryClient{
registrar: reg,
connector: conn,
}
} | go | func newShellQueryClient(reg dosa.Registrar, conn dosa.Connector) ShellQueryClient {
return &shellQueryClient{
registrar: reg,
connector: conn,
}
} | [
"func",
"newShellQueryClient",
"(",
"reg",
"dosa",
".",
"Registrar",
",",
"conn",
"dosa",
".",
"Connector",
")",
"ShellQueryClient",
"{",
"return",
"&",
"shellQueryClient",
"{",
"registrar",
":",
"reg",
",",
"connector",
":",
"conn",
",",
"}",
"\n",
"}"
] | // newShellClient returns a new DOSA shell query client for the registrar and connector provided. | [
"newShellClient",
"returns",
"a",
"new",
"DOSA",
"shell",
"query",
"client",
"for",
"the",
"registrar",
"and",
"connector",
"provided",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/client.go#L50-L55 |
4,193 | uber-go/dosa | client.go | ErrorIsAlreadyExists | func ErrorIsAlreadyExists(err error) bool {
_, ok := errors.Cause(err).(*ErrAlreadyExists)
return ok
} | go | func ErrorIsAlreadyExists(err error) bool {
_, ok := errors.Cause(err).(*ErrAlreadyExists)
return ok
} | [
"func",
"ErrorIsAlreadyExists",
"(",
"err",
"error",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"*",
"ErrAlreadyExists",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // ErrorIsAlreadyExists checks if the error is caused by "ErrAlreadyExists" | [
"ErrorIsAlreadyExists",
"checks",
"if",
"the",
"error",
"is",
"caused",
"by",
"ErrAlreadyExists"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/client.go#L132-L135 |
4,194 | uber-go/dosa | client.go | NewClient | func NewClient(reg Registrar, conn Connector) Client {
return &client{
registrar: reg,
connector: conn,
}
} | go | func NewClient(reg Registrar, conn Connector) Client {
return &client{
registrar: reg,
connector: conn,
}
} | [
"func",
"NewClient",
"(",
"reg",
"Registrar",
",",
"conn",
"Connector",
")",
"Client",
"{",
"return",
"&",
"client",
"{",
"registrar",
":",
"reg",
",",
"connector",
":",
"conn",
",",
"}",
"\n",
"}"
] | // NewClient returns a new DOSA client for the registrar and connector provided.
// This is currently only a partial implementation to demonstrate basic CRUD functionality. | [
"NewClient",
"returns",
"a",
"new",
"DOSA",
"client",
"for",
"the",
"registrar",
"and",
"connector",
"provided",
".",
"This",
"is",
"currently",
"only",
"a",
"partial",
"implementation",
"to",
"demonstrate",
"basic",
"CRUD",
"functionality",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/client.go#L265-L270 |
4,195 | uber-go/dosa | client.go | Initialize | func (c *client) Initialize(ctx context.Context) error {
if c.initialized {
return nil
}
// check schema for all registered entities
registered := c.registrar.FindAll()
if len(registered) == 0 {
return errors.Errorf("No registered entities found")
}
eds := []*EntityDefinition{}
for _, re := range registered {
eds = append(eds, re.EntityDefinition())
}
// fetch latest version for all registered entities, assume order is preserved
version, err := c.connector.CheckSchema(ctx, c.registrar.Scope(), c.registrar.NamePrefix(), eds)
if err != nil {
return errors.Wrap(err, "CheckSchema failed")
}
// set version for all registered entities
for _, reg := range registered {
reg.SetVersion(version)
}
c.initialized = true
return nil
} | go | func (c *client) Initialize(ctx context.Context) error {
if c.initialized {
return nil
}
// check schema for all registered entities
registered := c.registrar.FindAll()
if len(registered) == 0 {
return errors.Errorf("No registered entities found")
}
eds := []*EntityDefinition{}
for _, re := range registered {
eds = append(eds, re.EntityDefinition())
}
// fetch latest version for all registered entities, assume order is preserved
version, err := c.connector.CheckSchema(ctx, c.registrar.Scope(), c.registrar.NamePrefix(), eds)
if err != nil {
return errors.Wrap(err, "CheckSchema failed")
}
// set version for all registered entities
for _, reg := range registered {
reg.SetVersion(version)
}
c.initialized = true
return nil
} | [
"func",
"(",
"c",
"*",
"client",
")",
"Initialize",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"c",
".",
"initialized",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// check schema for all registered entities",
"registered",
":=",
"c",
".",
"registrar",
".",
"FindAll",
"(",
")",
"\n",
"if",
"len",
"(",
"registered",
")",
"==",
"0",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"eds",
":=",
"[",
"]",
"*",
"EntityDefinition",
"{",
"}",
"\n",
"for",
"_",
",",
"re",
":=",
"range",
"registered",
"{",
"eds",
"=",
"append",
"(",
"eds",
",",
"re",
".",
"EntityDefinition",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// fetch latest version for all registered entities, assume order is preserved",
"version",
",",
"err",
":=",
"c",
".",
"connector",
".",
"CheckSchema",
"(",
"ctx",
",",
"c",
".",
"registrar",
".",
"Scope",
"(",
")",
",",
"c",
".",
"registrar",
".",
"NamePrefix",
"(",
")",
",",
"eds",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// set version for all registered entities",
"for",
"_",
",",
"reg",
":=",
"range",
"registered",
"{",
"reg",
".",
"SetVersion",
"(",
"version",
")",
"\n",
"}",
"\n",
"c",
".",
"initialized",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] | // Initialize performs initial schema checks against all registered entities. | [
"Initialize",
"performs",
"initial",
"schema",
"checks",
"against",
"all",
"registered",
"entities",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/client.go#L278-L306 |
4,196 | uber-go/dosa | client.go | CreateIfNotExists | func (c *client) CreateIfNotExists(ctx context.Context, entity DomainObject) error {
return c.createOrUpsert(ctx, nil, entity, c.connector.CreateIfNotExists)
} | go | func (c *client) CreateIfNotExists(ctx context.Context, entity DomainObject) error {
return c.createOrUpsert(ctx, nil, entity, c.connector.CreateIfNotExists)
} | [
"func",
"(",
"c",
"*",
"client",
")",
"CreateIfNotExists",
"(",
"ctx",
"context",
".",
"Context",
",",
"entity",
"DomainObject",
")",
"error",
"{",
"return",
"c",
".",
"createOrUpsert",
"(",
"ctx",
",",
"nil",
",",
"entity",
",",
"c",
".",
"connector",
".",
"CreateIfNotExists",
")",
"\n",
"}"
] | // CreateIfNotExists creates a row, but only if it does not exist. The entity
// provided must contain values for all components of its primary key for the
// operation to succeed. | [
"CreateIfNotExists",
"creates",
"a",
"row",
"but",
"only",
"if",
"it",
"does",
"not",
"exist",
".",
"The",
"entity",
"provided",
"must",
"contain",
"values",
"for",
"all",
"components",
"of",
"its",
"primary",
"key",
"for",
"the",
"operation",
"to",
"succeed",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/client.go#L311-L313 |
4,197 | uber-go/dosa | client.go | Read | func (c *client) Read(ctx context.Context, fieldsToRead []string, entity DomainObject) error {
if !c.initialized {
return &ErrNotInitialized{}
}
// lookup registered entity, the registrar will return error if it is not found
re, err := c.registrar.Find(entity)
if err != nil {
return err
}
// translate entity field values to a map of primary key name/values pairs
// required to perform a read
fieldValues := re.KeyFieldValues(entity)
// build a list of column names from a list of entities field names
columnsToRead, err := re.ColumnNames(fieldsToRead)
if err != nil {
return err
}
results, err := c.connector.Read(ctx, re.EntityInfo(), fieldValues, columnsToRead)
if err != nil {
return err
}
// map results to entity fields
re.SetFieldValues(entity, results, columnsToRead)
return nil
} | go | func (c *client) Read(ctx context.Context, fieldsToRead []string, entity DomainObject) error {
if !c.initialized {
return &ErrNotInitialized{}
}
// lookup registered entity, the registrar will return error if it is not found
re, err := c.registrar.Find(entity)
if err != nil {
return err
}
// translate entity field values to a map of primary key name/values pairs
// required to perform a read
fieldValues := re.KeyFieldValues(entity)
// build a list of column names from a list of entities field names
columnsToRead, err := re.ColumnNames(fieldsToRead)
if err != nil {
return err
}
results, err := c.connector.Read(ctx, re.EntityInfo(), fieldValues, columnsToRead)
if err != nil {
return err
}
// map results to entity fields
re.SetFieldValues(entity, results, columnsToRead)
return nil
} | [
"func",
"(",
"c",
"*",
"client",
")",
"Read",
"(",
"ctx",
"context",
".",
"Context",
",",
"fieldsToRead",
"[",
"]",
"string",
",",
"entity",
"DomainObject",
")",
"error",
"{",
"if",
"!",
"c",
".",
"initialized",
"{",
"return",
"&",
"ErrNotInitialized",
"{",
"}",
"\n",
"}",
"\n\n",
"// lookup registered entity, the registrar will return error if it is not found",
"re",
",",
"err",
":=",
"c",
".",
"registrar",
".",
"Find",
"(",
"entity",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// translate entity field values to a map of primary key name/values pairs",
"// required to perform a read",
"fieldValues",
":=",
"re",
".",
"KeyFieldValues",
"(",
"entity",
")",
"\n\n",
"// build a list of column names from a list of entities field names",
"columnsToRead",
",",
"err",
":=",
"re",
".",
"ColumnNames",
"(",
"fieldsToRead",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"results",
",",
"err",
":=",
"c",
".",
"connector",
".",
"Read",
"(",
"ctx",
",",
"re",
".",
"EntityInfo",
"(",
")",
",",
"fieldValues",
",",
"columnsToRead",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// map results to entity fields",
"re",
".",
"SetFieldValues",
"(",
"entity",
",",
"results",
",",
"columnsToRead",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Read fetches an entity by primary key, The entity provided must contain
// values for all components of its primary key for the operation to succeed.
// If `fieldsToRead` is provided, only a subset of fields will be
// marshalled onto the given entity | [
"Read",
"fetches",
"an",
"entity",
"by",
"primary",
"key",
"The",
"entity",
"provided",
"must",
"contain",
"values",
"for",
"all",
"components",
"of",
"its",
"primary",
"key",
"for",
"the",
"operation",
"to",
"succeed",
".",
"If",
"fieldsToRead",
"is",
"provided",
"only",
"a",
"subset",
"of",
"fields",
"will",
"be",
"marshalled",
"onto",
"the",
"given",
"entity"
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/client.go#L319-L349 |
4,198 | uber-go/dosa | client.go | MultiRead | func (c *client) MultiRead(ctx context.Context, fieldsToRead []string, entities ...DomainObject) (MultiResult, error) {
if !c.initialized {
return nil, &ErrNotInitialized{}
}
if len(entities) == 0 {
return nil, fmt.Errorf("the number of entities to read is zero")
}
// lookup registered entity, the registrar will return error if it is not found
var re *RegisteredEntity
var listFieldValues []map[string]FieldValue
for _, entity := range entities {
ere, err := c.registrar.Find(entity)
if err != nil {
return nil, err
}
if re == nil {
re = ere
} else if re != ere {
return nil, fmt.Errorf("inconsistent entity type for multi read: %v vs %v", re, ere)
}
// translate entity field values to a map of primary key name/values pairs
// required to perform a read
listFieldValues = append(listFieldValues, re.KeyFieldValues(entity))
}
// build a list of column names from a list of entities field names
columnsToRead, err := re.ColumnNames(fieldsToRead)
if err != nil {
return nil, err
}
results, err := c.connector.MultiRead(ctx, re.EntityInfo(), listFieldValues, columnsToRead)
if err != nil {
return nil, err
}
multiResult := MultiResult{}
// map results to entity fields
for i, entity := range entities {
if results[i].Error != nil {
multiResult[entity] = results[i].Error
continue
}
re.SetFieldValues(entity, results[i].Values, columnsToRead)
}
return multiResult, nil
} | go | func (c *client) MultiRead(ctx context.Context, fieldsToRead []string, entities ...DomainObject) (MultiResult, error) {
if !c.initialized {
return nil, &ErrNotInitialized{}
}
if len(entities) == 0 {
return nil, fmt.Errorf("the number of entities to read is zero")
}
// lookup registered entity, the registrar will return error if it is not found
var re *RegisteredEntity
var listFieldValues []map[string]FieldValue
for _, entity := range entities {
ere, err := c.registrar.Find(entity)
if err != nil {
return nil, err
}
if re == nil {
re = ere
} else if re != ere {
return nil, fmt.Errorf("inconsistent entity type for multi read: %v vs %v", re, ere)
}
// translate entity field values to a map of primary key name/values pairs
// required to perform a read
listFieldValues = append(listFieldValues, re.KeyFieldValues(entity))
}
// build a list of column names from a list of entities field names
columnsToRead, err := re.ColumnNames(fieldsToRead)
if err != nil {
return nil, err
}
results, err := c.connector.MultiRead(ctx, re.EntityInfo(), listFieldValues, columnsToRead)
if err != nil {
return nil, err
}
multiResult := MultiResult{}
// map results to entity fields
for i, entity := range entities {
if results[i].Error != nil {
multiResult[entity] = results[i].Error
continue
}
re.SetFieldValues(entity, results[i].Values, columnsToRead)
}
return multiResult, nil
} | [
"func",
"(",
"c",
"*",
"client",
")",
"MultiRead",
"(",
"ctx",
"context",
".",
"Context",
",",
"fieldsToRead",
"[",
"]",
"string",
",",
"entities",
"...",
"DomainObject",
")",
"(",
"MultiResult",
",",
"error",
")",
"{",
"if",
"!",
"c",
".",
"initialized",
"{",
"return",
"nil",
",",
"&",
"ErrNotInitialized",
"{",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"entities",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// lookup registered entity, the registrar will return error if it is not found",
"var",
"re",
"*",
"RegisteredEntity",
"\n",
"var",
"listFieldValues",
"[",
"]",
"map",
"[",
"string",
"]",
"FieldValue",
"\n",
"for",
"_",
",",
"entity",
":=",
"range",
"entities",
"{",
"ere",
",",
"err",
":=",
"c",
".",
"registrar",
".",
"Find",
"(",
"entity",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"re",
"==",
"nil",
"{",
"re",
"=",
"ere",
"\n",
"}",
"else",
"if",
"re",
"!=",
"ere",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"re",
",",
"ere",
")",
"\n",
"}",
"\n\n",
"// translate entity field values to a map of primary key name/values pairs",
"// required to perform a read",
"listFieldValues",
"=",
"append",
"(",
"listFieldValues",
",",
"re",
".",
"KeyFieldValues",
"(",
"entity",
")",
")",
"\n",
"}",
"\n\n",
"// build a list of column names from a list of entities field names",
"columnsToRead",
",",
"err",
":=",
"re",
".",
"ColumnNames",
"(",
"fieldsToRead",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"results",
",",
"err",
":=",
"c",
".",
"connector",
".",
"MultiRead",
"(",
"ctx",
",",
"re",
".",
"EntityInfo",
"(",
")",
",",
"listFieldValues",
",",
"columnsToRead",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"multiResult",
":=",
"MultiResult",
"{",
"}",
"\n",
"// map results to entity fields",
"for",
"i",
",",
"entity",
":=",
"range",
"entities",
"{",
"if",
"results",
"[",
"i",
"]",
".",
"Error",
"!=",
"nil",
"{",
"multiResult",
"[",
"entity",
"]",
"=",
"results",
"[",
"i",
"]",
".",
"Error",
"\n",
"continue",
"\n",
"}",
"\n",
"re",
".",
"SetFieldValues",
"(",
"entity",
",",
"results",
"[",
"i",
"]",
".",
"Values",
",",
"columnsToRead",
")",
"\n",
"}",
"\n\n",
"return",
"multiResult",
",",
"nil",
"\n",
"}"
] | // MultiRead fetches several entities by primary key, The entities provided
// must contain values for all components of its primary key for the operation
// to succeed. If `fieldsToRead` is provided, only a subset of fields will be
// marshalled onto the given entities. | [
"MultiRead",
"fetches",
"several",
"entities",
"by",
"primary",
"key",
"The",
"entities",
"provided",
"must",
"contain",
"values",
"for",
"all",
"components",
"of",
"its",
"primary",
"key",
"for",
"the",
"operation",
"to",
"succeed",
".",
"If",
"fieldsToRead",
"is",
"provided",
"only",
"a",
"subset",
"of",
"fields",
"will",
"be",
"marshalled",
"onto",
"the",
"given",
"entities",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/client.go#L355-L406 |
4,199 | uber-go/dosa | client.go | Upsert | func (c *client) Upsert(ctx context.Context, fieldsToUpdate []string, entity DomainObject) error {
return c.createOrUpsert(ctx, fieldsToUpdate, entity, c.connector.Upsert)
} | go | func (c *client) Upsert(ctx context.Context, fieldsToUpdate []string, entity DomainObject) error {
return c.createOrUpsert(ctx, fieldsToUpdate, entity, c.connector.Upsert)
} | [
"func",
"(",
"c",
"*",
"client",
")",
"Upsert",
"(",
"ctx",
"context",
".",
"Context",
",",
"fieldsToUpdate",
"[",
"]",
"string",
",",
"entity",
"DomainObject",
")",
"error",
"{",
"return",
"c",
".",
"createOrUpsert",
"(",
"ctx",
",",
"fieldsToUpdate",
",",
"entity",
",",
"c",
".",
"connector",
".",
"Upsert",
")",
"\n",
"}"
] | // Upsert updates some values of an entity, or creates it if it doesn't exist.
// The entity provided must contain values for all components of its primary
// key for the operation to succeed. If `fieldsToUpdate` is provided, only a
// subset of fields will be updated. | [
"Upsert",
"updates",
"some",
"values",
"of",
"an",
"entity",
"or",
"creates",
"it",
"if",
"it",
"doesn",
"t",
"exist",
".",
"The",
"entity",
"provided",
"must",
"contain",
"values",
"for",
"all",
"components",
"of",
"its",
"primary",
"key",
"for",
"the",
"operation",
"to",
"succeed",
".",
"If",
"fieldsToUpdate",
"is",
"provided",
"only",
"a",
"subset",
"of",
"fields",
"will",
"be",
"updated",
"."
] | 18f7766015f97d726635fc75b21c93ec270e5ac5 | https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/client.go#L414-L416 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.