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
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
|---|---|---|---|---|---|---|---|---|---|---|---|
20,400
|
uniplaces/carbon
|
carbon.go
|
DiffInMinutes
|
func (c *Carbon) DiffInMinutes(d *Carbon, abs bool) int64 {
return c.DiffInSeconds(d, abs) / secondsPerMinute
}
|
go
|
func (c *Carbon) DiffInMinutes(d *Carbon, abs bool) int64 {
return c.DiffInSeconds(d, abs) / secondsPerMinute
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"DiffInMinutes",
"(",
"d",
"*",
"Carbon",
",",
"abs",
"bool",
")",
"int64",
"{",
"return",
"c",
".",
"DiffInSeconds",
"(",
"d",
",",
"abs",
")",
"/",
"secondsPerMinute",
"\n",
"}"
] |
// DiffInMinutes returns the difference in minutes
|
[
"DiffInMinutes",
"returns",
"the",
"difference",
"in",
"minutes"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1356-L1358
|
20,401
|
uniplaces/carbon
|
carbon.go
|
DiffInSeconds
|
func (c *Carbon) DiffInSeconds(carb *Carbon, abs bool) int64 {
if carb == nil {
carb = nowIn(c.Location())
}
diff := carb.Timestamp() - c.Timestamp()
return absValue(abs, diff)
}
|
go
|
func (c *Carbon) DiffInSeconds(carb *Carbon, abs bool) int64 {
if carb == nil {
carb = nowIn(c.Location())
}
diff := carb.Timestamp() - c.Timestamp()
return absValue(abs, diff)
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"DiffInSeconds",
"(",
"carb",
"*",
"Carbon",
",",
"abs",
"bool",
")",
"int64",
"{",
"if",
"carb",
"==",
"nil",
"{",
"carb",
"=",
"nowIn",
"(",
"c",
".",
"Location",
"(",
")",
")",
"\n",
"}",
"\n",
"diff",
":=",
"carb",
".",
"Timestamp",
"(",
")",
"-",
"c",
".",
"Timestamp",
"(",
")",
"\n\n",
"return",
"absValue",
"(",
"abs",
",",
"diff",
")",
"\n",
"}"
] |
// DiffInSeconds returns the difference in seconds
|
[
"DiffInSeconds",
"returns",
"the",
"difference",
"in",
"seconds"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1361-L1368
|
20,402
|
uniplaces/carbon
|
carbon.go
|
SecondsSinceMidnight
|
func (c *Carbon) SecondsSinceMidnight() int {
startOfDay := c.StartOfDay()
return int(c.DiffInSeconds(startOfDay, true))
}
|
go
|
func (c *Carbon) SecondsSinceMidnight() int {
startOfDay := c.StartOfDay()
return int(c.DiffInSeconds(startOfDay, true))
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"SecondsSinceMidnight",
"(",
")",
"int",
"{",
"startOfDay",
":=",
"c",
".",
"StartOfDay",
"(",
")",
"\n\n",
"return",
"int",
"(",
"c",
".",
"DiffInSeconds",
"(",
"startOfDay",
",",
"true",
")",
")",
"\n",
"}"
] |
// SecondsSinceMidnight returns the number of seconds since midnight.
|
[
"SecondsSinceMidnight",
"returns",
"the",
"number",
"of",
"seconds",
"since",
"midnight",
"."
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1371-L1375
|
20,403
|
uniplaces/carbon
|
carbon.go
|
absValue
|
func absValue(needsAbs bool, value int64) int64 {
if needsAbs && value < 0 {
return -value
}
return value
}
|
go
|
func absValue(needsAbs bool, value int64) int64 {
if needsAbs && value < 0 {
return -value
}
return value
}
|
[
"func",
"absValue",
"(",
"needsAbs",
"bool",
",",
"value",
"int64",
")",
"int64",
"{",
"if",
"needsAbs",
"&&",
"value",
"<",
"0",
"{",
"return",
"-",
"value",
"\n",
"}",
"\n\n",
"return",
"value",
"\n",
"}"
] |
// absValue returns the abs value if needed
|
[
"absValue",
"returns",
"the",
"abs",
"value",
"if",
"needed"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1385-L1391
|
20,404
|
uniplaces/carbon
|
carbon.go
|
Next
|
func (c *Carbon) Next(wd time.Weekday) *Carbon {
c = c.AddDay()
for c.Weekday() != wd {
c = c.AddDay()
}
return c.StartOfDay()
}
|
go
|
func (c *Carbon) Next(wd time.Weekday) *Carbon {
c = c.AddDay()
for c.Weekday() != wd {
c = c.AddDay()
}
return c.StartOfDay()
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"Next",
"(",
"wd",
"time",
".",
"Weekday",
")",
"*",
"Carbon",
"{",
"c",
"=",
"c",
".",
"AddDay",
"(",
")",
"\n",
"for",
"c",
".",
"Weekday",
"(",
")",
"!=",
"wd",
"{",
"c",
"=",
"c",
".",
"AddDay",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"StartOfDay",
"(",
")",
"\n",
"}"
] |
// Next changes the time to the next occurrence of a given day of the week
|
[
"Next",
"changes",
"the",
"time",
"to",
"the",
"next",
"occurrence",
"of",
"a",
"given",
"day",
"of",
"the",
"week"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1609-L1616
|
20,405
|
uniplaces/carbon
|
carbon.go
|
NextWeekendDay
|
func (c *Carbon) NextWeekendDay() *Carbon {
c = c.AddDay()
for !c.IsWeekend() {
c = c.AddDay()
}
return c
}
|
go
|
func (c *Carbon) NextWeekendDay() *Carbon {
c = c.AddDay()
for !c.IsWeekend() {
c = c.AddDay()
}
return c
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"NextWeekendDay",
"(",
")",
"*",
"Carbon",
"{",
"c",
"=",
"c",
".",
"AddDay",
"(",
")",
"\n",
"for",
"!",
"c",
".",
"IsWeekend",
"(",
")",
"{",
"c",
"=",
"c",
".",
"AddDay",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"c",
"\n",
"}"
] |
// NextWeekendDay goes forward to the next weekend day
|
[
"NextWeekendDay",
"goes",
"forward",
"to",
"the",
"next",
"weekend",
"day"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1629-L1636
|
20,406
|
uniplaces/carbon
|
carbon.go
|
PreviousWeekendDay
|
func (c *Carbon) PreviousWeekendDay() *Carbon {
c = c.SubDay()
for !c.IsWeekend() {
c = c.SubDay()
}
return c
}
|
go
|
func (c *Carbon) PreviousWeekendDay() *Carbon {
c = c.SubDay()
for !c.IsWeekend() {
c = c.SubDay()
}
return c
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"PreviousWeekendDay",
"(",
")",
"*",
"Carbon",
"{",
"c",
"=",
"c",
".",
"SubDay",
"(",
")",
"\n",
"for",
"!",
"c",
".",
"IsWeekend",
"(",
")",
"{",
"c",
"=",
"c",
".",
"SubDay",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"c",
"\n",
"}"
] |
// PreviousWeekendDay goes back to the previous weekend day
|
[
"PreviousWeekendDay",
"goes",
"back",
"to",
"the",
"previous",
"weekend",
"day"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1639-L1646
|
20,407
|
uniplaces/carbon
|
carbon.go
|
Previous
|
func (c *Carbon) Previous(wd time.Weekday) *Carbon {
c = c.SubDay()
for c.Weekday() != wd {
c = c.SubDay()
}
return c.StartOfDay()
}
|
go
|
func (c *Carbon) Previous(wd time.Weekday) *Carbon {
c = c.SubDay()
for c.Weekday() != wd {
c = c.SubDay()
}
return c.StartOfDay()
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"Previous",
"(",
"wd",
"time",
".",
"Weekday",
")",
"*",
"Carbon",
"{",
"c",
"=",
"c",
".",
"SubDay",
"(",
")",
"\n",
"for",
"c",
".",
"Weekday",
"(",
")",
"!=",
"wd",
"{",
"c",
"=",
"c",
".",
"SubDay",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"StartOfDay",
"(",
")",
"\n",
"}"
] |
// Previous changes the time to the previous occurrence of a given day of the week
|
[
"Previous",
"changes",
"the",
"time",
"to",
"the",
"previous",
"occurrence",
"of",
"a",
"given",
"day",
"of",
"the",
"week"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1649-L1656
|
20,408
|
uniplaces/carbon
|
carbon.go
|
FirstOfMonth
|
func (c *Carbon) FirstOfMonth(wd time.Weekday) *Carbon {
d := c.StartOfMonth()
if d.Weekday() != wd {
return d.Next(wd)
}
return d
}
|
go
|
func (c *Carbon) FirstOfMonth(wd time.Weekday) *Carbon {
d := c.StartOfMonth()
if d.Weekday() != wd {
return d.Next(wd)
}
return d
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"FirstOfMonth",
"(",
"wd",
"time",
".",
"Weekday",
")",
"*",
"Carbon",
"{",
"d",
":=",
"c",
".",
"StartOfMonth",
"(",
")",
"\n",
"if",
"d",
".",
"Weekday",
"(",
")",
"!=",
"wd",
"{",
"return",
"d",
".",
"Next",
"(",
"wd",
")",
"\n",
"}",
"\n\n",
"return",
"d",
"\n",
"}"
] |
// FirstOfMonth returns the first occurrence of a given day of the week in the current month
|
[
"FirstOfMonth",
"returns",
"the",
"first",
"occurrence",
"of",
"a",
"given",
"day",
"of",
"the",
"week",
"in",
"the",
"current",
"month"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1659-L1666
|
20,409
|
uniplaces/carbon
|
carbon.go
|
LastOfMonth
|
func (c *Carbon) LastOfMonth(wd time.Weekday) *Carbon {
d := c.EndOfMonth()
if d.Weekday() != wd {
return d.Previous(wd)
}
return d.StartOfDay()
}
|
go
|
func (c *Carbon) LastOfMonth(wd time.Weekday) *Carbon {
d := c.EndOfMonth()
if d.Weekday() != wd {
return d.Previous(wd)
}
return d.StartOfDay()
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"LastOfMonth",
"(",
"wd",
"time",
".",
"Weekday",
")",
"*",
"Carbon",
"{",
"d",
":=",
"c",
".",
"EndOfMonth",
"(",
")",
"\n",
"if",
"d",
".",
"Weekday",
"(",
")",
"!=",
"wd",
"{",
"return",
"d",
".",
"Previous",
"(",
"wd",
")",
"\n",
"}",
"\n\n",
"return",
"d",
".",
"StartOfDay",
"(",
")",
"\n",
"}"
] |
// LastOfMonth returns the last occurrence of a given day of the week in the current month
|
[
"LastOfMonth",
"returns",
"the",
"last",
"occurrence",
"of",
"a",
"given",
"day",
"of",
"the",
"week",
"in",
"the",
"current",
"month"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1669-L1676
|
20,410
|
uniplaces/carbon
|
carbon.go
|
LastDayOfMonth
|
func (c *Carbon) LastDayOfMonth() *Carbon {
return NewCarbon(time.Date(c.Year(), c.Month(), c.DaysInMonth(), 0, 0, 0, 0, time.UTC))
}
|
go
|
func (c *Carbon) LastDayOfMonth() *Carbon {
return NewCarbon(time.Date(c.Year(), c.Month(), c.DaysInMonth(), 0, 0, 0, 0, time.UTC))
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"LastDayOfMonth",
"(",
")",
"*",
"Carbon",
"{",
"return",
"NewCarbon",
"(",
"time",
".",
"Date",
"(",
"c",
".",
"Year",
"(",
")",
",",
"c",
".",
"Month",
"(",
")",
",",
"c",
".",
"DaysInMonth",
"(",
")",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"time",
".",
"UTC",
")",
")",
"\n",
"}"
] |
// LastDayOfMonth returns a new carbon instance with the last day of current month
|
[
"LastDayOfMonth",
"returns",
"a",
"new",
"carbon",
"instance",
"with",
"the",
"last",
"day",
"of",
"current",
"month"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1679-L1681
|
20,411
|
uniplaces/carbon
|
carbon.go
|
FirstDayOfMonth
|
func (c *Carbon) FirstDayOfMonth() *Carbon {
return NewCarbon(time.Date(c.Year(), c.Month(), 1, 0, 0, 0, 0, time.UTC))
}
|
go
|
func (c *Carbon) FirstDayOfMonth() *Carbon {
return NewCarbon(time.Date(c.Year(), c.Month(), 1, 0, 0, 0, 0, time.UTC))
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"FirstDayOfMonth",
"(",
")",
"*",
"Carbon",
"{",
"return",
"NewCarbon",
"(",
"time",
".",
"Date",
"(",
"c",
".",
"Year",
"(",
")",
",",
"c",
".",
"Month",
"(",
")",
",",
"1",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"time",
".",
"UTC",
")",
")",
"\n",
"}"
] |
// FirstDayOfMonth returns a new carbon instance with the first day of current month
|
[
"FirstDayOfMonth",
"returns",
"a",
"new",
"carbon",
"instance",
"with",
"the",
"first",
"day",
"of",
"current",
"month"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1684-L1686
|
20,412
|
uniplaces/carbon
|
carbon.go
|
NthOfMonth
|
func (c *Carbon) NthOfMonth(nth int, wd time.Weekday) *Carbon {
cp := c.Copy().StartOfMonth()
i := 0
if cp.Weekday() == wd {
i++
}
for i < nth {
cp = cp.Next(wd)
i++
}
if cp.Gt(c.EndOfMonth()) {
return c
}
return cp
}
|
go
|
func (c *Carbon) NthOfMonth(nth int, wd time.Weekday) *Carbon {
cp := c.Copy().StartOfMonth()
i := 0
if cp.Weekday() == wd {
i++
}
for i < nth {
cp = cp.Next(wd)
i++
}
if cp.Gt(c.EndOfMonth()) {
return c
}
return cp
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"NthOfMonth",
"(",
"nth",
"int",
",",
"wd",
"time",
".",
"Weekday",
")",
"*",
"Carbon",
"{",
"cp",
":=",
"c",
".",
"Copy",
"(",
")",
".",
"StartOfMonth",
"(",
")",
"\n",
"i",
":=",
"0",
"\n",
"if",
"cp",
".",
"Weekday",
"(",
")",
"==",
"wd",
"{",
"i",
"++",
"\n",
"}",
"\n",
"for",
"i",
"<",
"nth",
"{",
"cp",
"=",
"cp",
".",
"Next",
"(",
"wd",
")",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"if",
"cp",
".",
"Gt",
"(",
"c",
".",
"EndOfMonth",
"(",
")",
")",
"{",
"return",
"c",
"\n",
"}",
"\n\n",
"return",
"cp",
"\n",
"}"
] |
// NthOfMonth returns the given occurrence of a given day of the week in the current month
// If the calculated occurrence is outside the scope of current month, no modifications are made
|
[
"NthOfMonth",
"returns",
"the",
"given",
"occurrence",
"of",
"a",
"given",
"day",
"of",
"the",
"week",
"in",
"the",
"current",
"month",
"If",
"the",
"calculated",
"occurrence",
"is",
"outside",
"the",
"scope",
"of",
"current",
"month",
"no",
"modifications",
"are",
"made"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1690-L1705
|
20,413
|
uniplaces/carbon
|
carbon.go
|
FirstOfQuarter
|
func (c *Carbon) FirstOfQuarter(wd time.Weekday) *Carbon {
d := c.StartOfQuarter()
if d.Weekday() != wd {
return d.Next(wd)
}
return d
}
|
go
|
func (c *Carbon) FirstOfQuarter(wd time.Weekday) *Carbon {
d := c.StartOfQuarter()
if d.Weekday() != wd {
return d.Next(wd)
}
return d
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"FirstOfQuarter",
"(",
"wd",
"time",
".",
"Weekday",
")",
"*",
"Carbon",
"{",
"d",
":=",
"c",
".",
"StartOfQuarter",
"(",
")",
"\n",
"if",
"d",
".",
"Weekday",
"(",
")",
"!=",
"wd",
"{",
"return",
"d",
".",
"Next",
"(",
"wd",
")",
"\n",
"}",
"\n\n",
"return",
"d",
"\n",
"}"
] |
// FirstOfQuarter returns the first occurrence of a given day of the week in the current quarter
|
[
"FirstOfQuarter",
"returns",
"the",
"first",
"occurrence",
"of",
"a",
"given",
"day",
"of",
"the",
"week",
"in",
"the",
"current",
"quarter"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1708-L1715
|
20,414
|
uniplaces/carbon
|
carbon.go
|
LastOfQuarter
|
func (c *Carbon) LastOfQuarter(wd time.Weekday) *Carbon {
d := c.EndOfQuarter()
if d.Weekday() != wd {
return d.Previous(wd)
}
return d.StartOfDay()
}
|
go
|
func (c *Carbon) LastOfQuarter(wd time.Weekday) *Carbon {
d := c.EndOfQuarter()
if d.Weekday() != wd {
return d.Previous(wd)
}
return d.StartOfDay()
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"LastOfQuarter",
"(",
"wd",
"time",
".",
"Weekday",
")",
"*",
"Carbon",
"{",
"d",
":=",
"c",
".",
"EndOfQuarter",
"(",
")",
"\n",
"if",
"d",
".",
"Weekday",
"(",
")",
"!=",
"wd",
"{",
"return",
"d",
".",
"Previous",
"(",
"wd",
")",
"\n",
"}",
"\n\n",
"return",
"d",
".",
"StartOfDay",
"(",
")",
"\n",
"}"
] |
// LastOfQuarter returns the last occurrence of a given day of the week in the current quarter
|
[
"LastOfQuarter",
"returns",
"the",
"last",
"occurrence",
"of",
"a",
"given",
"day",
"of",
"the",
"week",
"in",
"the",
"current",
"quarter"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1718-L1725
|
20,415
|
uniplaces/carbon
|
carbon.go
|
NthOfQuarter
|
func (c *Carbon) NthOfQuarter(nth int, wd time.Weekday) *Carbon {
cp := c.Copy().StartOfQuarter()
i := 0
if cp.Weekday() == wd {
i++
}
for i < nth {
cp = cp.Next(wd)
i++
}
if cp.Gt(c.EndOfQuarter()) {
return c
}
return cp
}
|
go
|
func (c *Carbon) NthOfQuarter(nth int, wd time.Weekday) *Carbon {
cp := c.Copy().StartOfQuarter()
i := 0
if cp.Weekday() == wd {
i++
}
for i < nth {
cp = cp.Next(wd)
i++
}
if cp.Gt(c.EndOfQuarter()) {
return c
}
return cp
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"NthOfQuarter",
"(",
"nth",
"int",
",",
"wd",
"time",
".",
"Weekday",
")",
"*",
"Carbon",
"{",
"cp",
":=",
"c",
".",
"Copy",
"(",
")",
".",
"StartOfQuarter",
"(",
")",
"\n",
"i",
":=",
"0",
"\n",
"if",
"cp",
".",
"Weekday",
"(",
")",
"==",
"wd",
"{",
"i",
"++",
"\n",
"}",
"\n",
"for",
"i",
"<",
"nth",
"{",
"cp",
"=",
"cp",
".",
"Next",
"(",
"wd",
")",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"if",
"cp",
".",
"Gt",
"(",
"c",
".",
"EndOfQuarter",
"(",
")",
")",
"{",
"return",
"c",
"\n",
"}",
"\n\n",
"return",
"cp",
"\n",
"}"
] |
// NthOfQuarter returns the given occurrence of a given day of the week in the current quarter
// If the calculated occurrence is outside the scope of current quarter, no modifications are made
|
[
"NthOfQuarter",
"returns",
"the",
"given",
"occurrence",
"of",
"a",
"given",
"day",
"of",
"the",
"week",
"in",
"the",
"current",
"quarter",
"If",
"the",
"calculated",
"occurrence",
"is",
"outside",
"the",
"scope",
"of",
"current",
"quarter",
"no",
"modifications",
"are",
"made"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1729-L1744
|
20,416
|
uniplaces/carbon
|
carbon.go
|
FirstOfYear
|
func (c *Carbon) FirstOfYear(wd time.Weekday) *Carbon {
d := c.StartOfYear()
if d.Weekday() != wd {
return d.Next(wd)
}
return d
}
|
go
|
func (c *Carbon) FirstOfYear(wd time.Weekday) *Carbon {
d := c.StartOfYear()
if d.Weekday() != wd {
return d.Next(wd)
}
return d
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"FirstOfYear",
"(",
"wd",
"time",
".",
"Weekday",
")",
"*",
"Carbon",
"{",
"d",
":=",
"c",
".",
"StartOfYear",
"(",
")",
"\n",
"if",
"d",
".",
"Weekday",
"(",
")",
"!=",
"wd",
"{",
"return",
"d",
".",
"Next",
"(",
"wd",
")",
"\n",
"}",
"\n\n",
"return",
"d",
"\n",
"}"
] |
// FirstOfYear returns the first occurrence of a given day of the week in the current year
|
[
"FirstOfYear",
"returns",
"the",
"first",
"occurrence",
"of",
"a",
"given",
"day",
"of",
"the",
"week",
"in",
"the",
"current",
"year"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1747-L1754
|
20,417
|
uniplaces/carbon
|
carbon.go
|
LastOfYear
|
func (c *Carbon) LastOfYear(wd time.Weekday) *Carbon {
d := c.EndOfYear()
if d.Weekday() != wd {
return d.Previous(wd)
}
return d.StartOfDay()
}
|
go
|
func (c *Carbon) LastOfYear(wd time.Weekday) *Carbon {
d := c.EndOfYear()
if d.Weekday() != wd {
return d.Previous(wd)
}
return d.StartOfDay()
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"LastOfYear",
"(",
"wd",
"time",
".",
"Weekday",
")",
"*",
"Carbon",
"{",
"d",
":=",
"c",
".",
"EndOfYear",
"(",
")",
"\n",
"if",
"d",
".",
"Weekday",
"(",
")",
"!=",
"wd",
"{",
"return",
"d",
".",
"Previous",
"(",
"wd",
")",
"\n",
"}",
"\n\n",
"return",
"d",
".",
"StartOfDay",
"(",
")",
"\n",
"}"
] |
// LastOfYear returns the last occurrence of a given day of the week in the current year
|
[
"LastOfYear",
"returns",
"the",
"last",
"occurrence",
"of",
"a",
"given",
"day",
"of",
"the",
"week",
"in",
"the",
"current",
"year"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1757-L1764
|
20,418
|
uniplaces/carbon
|
carbon.go
|
NthOfYear
|
func (c *Carbon) NthOfYear(nth int, wd time.Weekday) *Carbon {
cp := c.Copy().StartOfYear()
i := 0
if cp.Weekday() == wd {
i++
}
for i < nth {
cp = cp.Next(wd)
i++
}
if cp.Gt(c.EndOfYear()) {
return c
}
return cp
}
|
go
|
func (c *Carbon) NthOfYear(nth int, wd time.Weekday) *Carbon {
cp := c.Copy().StartOfYear()
i := 0
if cp.Weekday() == wd {
i++
}
for i < nth {
cp = cp.Next(wd)
i++
}
if cp.Gt(c.EndOfYear()) {
return c
}
return cp
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"NthOfYear",
"(",
"nth",
"int",
",",
"wd",
"time",
".",
"Weekday",
")",
"*",
"Carbon",
"{",
"cp",
":=",
"c",
".",
"Copy",
"(",
")",
".",
"StartOfYear",
"(",
")",
"\n",
"i",
":=",
"0",
"\n",
"if",
"cp",
".",
"Weekday",
"(",
")",
"==",
"wd",
"{",
"i",
"++",
"\n",
"}",
"\n",
"for",
"i",
"<",
"nth",
"{",
"cp",
"=",
"cp",
".",
"Next",
"(",
"wd",
")",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"if",
"cp",
".",
"Gt",
"(",
"c",
".",
"EndOfYear",
"(",
")",
")",
"{",
"return",
"c",
"\n",
"}",
"\n\n",
"return",
"cp",
"\n",
"}"
] |
// NthOfYear returns the given occurrence of a given day of the week in the current year
// If the calculated occurrence is outside the scope of current year, no modifications are made
|
[
"NthOfYear",
"returns",
"the",
"given",
"occurrence",
"of",
"a",
"given",
"day",
"of",
"the",
"week",
"in",
"the",
"current",
"year",
"If",
"the",
"calculated",
"occurrence",
"is",
"outside",
"the",
"scope",
"of",
"current",
"year",
"no",
"modifications",
"are",
"made"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1768-L1783
|
20,419
|
uniplaces/carbon
|
carbon.go
|
Average
|
func (c *Carbon) Average(carb *Carbon) *Carbon {
if carb == nil {
carb = nowIn(c.Location())
}
if c.Eq(carb) {
return c.Copy()
}
average := int(c.DiffInSeconds(carb, false) / 2)
return c.AddSeconds(average)
}
|
go
|
func (c *Carbon) Average(carb *Carbon) *Carbon {
if carb == nil {
carb = nowIn(c.Location())
}
if c.Eq(carb) {
return c.Copy()
}
average := int(c.DiffInSeconds(carb, false) / 2)
return c.AddSeconds(average)
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"Average",
"(",
"carb",
"*",
"Carbon",
")",
"*",
"Carbon",
"{",
"if",
"carb",
"==",
"nil",
"{",
"carb",
"=",
"nowIn",
"(",
"c",
".",
"Location",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"Eq",
"(",
"carb",
")",
"{",
"return",
"c",
".",
"Copy",
"(",
")",
"\n",
"}",
"\n",
"average",
":=",
"int",
"(",
"c",
".",
"DiffInSeconds",
"(",
"carb",
",",
"false",
")",
"/",
"2",
")",
"\n\n",
"return",
"c",
".",
"AddSeconds",
"(",
"average",
")",
"\n",
"}"
] |
// Average returns the average between a given carbon date and the current date
|
[
"Average",
"returns",
"the",
"average",
"between",
"a",
"given",
"carbon",
"date",
"and",
"the",
"current",
"date"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1786-L1796
|
20,420
|
uniplaces/carbon
|
carbon.go
|
GetTranslator
|
func (c *Carbon) GetTranslator() (*Translator, error) {
if c.Translator == nil {
c.Translator = translator()
}
return c.Translator, nil
}
|
go
|
func (c *Carbon) GetTranslator() (*Translator, error) {
if c.Translator == nil {
c.Translator = translator()
}
return c.Translator, nil
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"GetTranslator",
"(",
")",
"(",
"*",
"Translator",
",",
"error",
")",
"{",
"if",
"c",
".",
"Translator",
"==",
"nil",
"{",
"c",
".",
"Translator",
"=",
"translator",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"Translator",
",",
"nil",
"\n",
"}"
] |
// Localization
// GetTranslator returns Translator inside a Carbon instance if exist,
// otherwise it creates a new Translator with "en" as default locale
|
[
"Localization",
"GetTranslator",
"returns",
"Translator",
"inside",
"a",
"Carbon",
"instance",
"if",
"exist",
"otherwise",
"it",
"creates",
"a",
"new",
"Translator",
"with",
"en",
"as",
"default",
"locale"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1802-L1808
|
20,421
|
uniplaces/carbon
|
carbon.go
|
SetLocale
|
func (c *Carbon) SetLocale(l string) error {
err := c.Translator.SetLocale(l)
if err != nil {
return err
}
return nil
}
|
go
|
func (c *Carbon) SetLocale(l string) error {
err := c.Translator.SetLocale(l)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Carbon",
")",
"SetLocale",
"(",
"l",
"string",
")",
"error",
"{",
"err",
":=",
"c",
".",
"Translator",
".",
"SetLocale",
"(",
"l",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// SetLocale sets locale for the Translator of Carbon
|
[
"SetLocale",
"sets",
"locale",
"for",
"the",
"Translator",
"of",
"Carbon"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carbon.go#L1828-L1835
|
20,422
|
uniplaces/carbon
|
carboninterval.go
|
NewCarbonInterval
|
func NewCarbonInterval(start, end *Carbon) (*CarbonInterval, error) {
if start.Gte(end) {
return nil, errors.New("The end date must be greater than the start date.")
}
return &CarbonInterval{
Start: start,
End: end,
}, nil
}
|
go
|
func NewCarbonInterval(start, end *Carbon) (*CarbonInterval, error) {
if start.Gte(end) {
return nil, errors.New("The end date must be greater than the start date.")
}
return &CarbonInterval{
Start: start,
End: end,
}, nil
}
|
[
"func",
"NewCarbonInterval",
"(",
"start",
",",
"end",
"*",
"Carbon",
")",
"(",
"*",
"CarbonInterval",
",",
"error",
")",
"{",
"if",
"start",
".",
"Gte",
"(",
"end",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"CarbonInterval",
"{",
"Start",
":",
"start",
",",
"End",
":",
"end",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewCarbonInterval returns a pointer to a new CarbonInterval instance
|
[
"NewCarbonInterval",
"returns",
"a",
"pointer",
"to",
"a",
"new",
"CarbonInterval",
"instance"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carboninterval.go#L14-L23
|
20,423
|
uniplaces/carbon
|
carboninterval.go
|
DiffInHours
|
func (ci *CarbonInterval) DiffInHours() int64 {
return ci.End.DiffInHours(ci.Start, true)
}
|
go
|
func (ci *CarbonInterval) DiffInHours() int64 {
return ci.End.DiffInHours(ci.Start, true)
}
|
[
"func",
"(",
"ci",
"*",
"CarbonInterval",
")",
"DiffInHours",
"(",
")",
"int64",
"{",
"return",
"ci",
".",
"End",
".",
"DiffInHours",
"(",
"ci",
".",
"Start",
",",
"true",
")",
"\n",
"}"
] |
// DiffInHours return the difference in hours between start and end date
|
[
"DiffInHours",
"return",
"the",
"difference",
"in",
"hours",
"between",
"start",
"and",
"end",
"date"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/carboninterval.go#L26-L28
|
20,424
|
uniplaces/carbon
|
translator.go
|
SetLocale
|
func (t *Translator) SetLocale(l string) error {
err := t.AssertValidLocale(l)
if err != nil {
return err
}
err = t.loadResource(l)
if err != nil {
return err
}
t.locale = l
return nil
}
|
go
|
func (t *Translator) SetLocale(l string) error {
err := t.AssertValidLocale(l)
if err != nil {
return err
}
err = t.loadResource(l)
if err != nil {
return err
}
t.locale = l
return nil
}
|
[
"func",
"(",
"t",
"*",
"Translator",
")",
"SetLocale",
"(",
"l",
"string",
")",
"error",
"{",
"err",
":=",
"t",
".",
"AssertValidLocale",
"(",
"l",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"t",
".",
"loadResource",
"(",
"l",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"t",
".",
"locale",
"=",
"l",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// SetLocale will set locale on a Translator
|
[
"SetLocale",
"will",
"set",
"locale",
"on",
"a",
"Translator"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/translator.go#L33-L47
|
20,425
|
uniplaces/carbon
|
translator.go
|
AssertValidLocale
|
func (t *Translator) AssertValidLocale(l string) error {
matched, err := regexp.MatchString("^(?:[a-z]{2}|[a-z]{2}(([_-]{1})([a-zA-Z]{2}){1,2}))$", l)
if err != nil {
return errors.New("unable to match locale code : " + err.Error())
}
if !matched {
return errors.New("invalid locale code : " + l)
}
return nil
}
|
go
|
func (t *Translator) AssertValidLocale(l string) error {
matched, err := regexp.MatchString("^(?:[a-z]{2}|[a-z]{2}(([_-]{1})([a-zA-Z]{2}){1,2}))$", l)
if err != nil {
return errors.New("unable to match locale code : " + err.Error())
}
if !matched {
return errors.New("invalid locale code : " + l)
}
return nil
}
|
[
"func",
"(",
"t",
"*",
"Translator",
")",
"AssertValidLocale",
"(",
"l",
"string",
")",
"error",
"{",
"matched",
",",
"err",
":=",
"regexp",
".",
"MatchString",
"(",
"\"",
"\"",
",",
"l",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"!",
"matched",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"l",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// AssertValidLocale checks if the locale is valid or not
|
[
"AssertValidLocale",
"checks",
"if",
"the",
"locale",
"is",
"valid",
"or",
"not"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/translator.go#L50-L60
|
20,426
|
uniplaces/carbon
|
translator.go
|
loadResource
|
func (t *Translator) loadResource(l string) error {
ltext, err := lang.LoadLocaleText(l)
if err != nil {
return err
}
err = json.Unmarshal(ltext, &t.resources)
if err != nil {
return errors.New("unable to unmarshall locale data : " + err.Error())
}
return nil
}
|
go
|
func (t *Translator) loadResource(l string) error {
ltext, err := lang.LoadLocaleText(l)
if err != nil {
return err
}
err = json.Unmarshal(ltext, &t.resources)
if err != nil {
return errors.New("unable to unmarshall locale data : " + err.Error())
}
return nil
}
|
[
"func",
"(",
"t",
"*",
"Translator",
")",
"loadResource",
"(",
"l",
"string",
")",
"error",
"{",
"ltext",
",",
"err",
":=",
"lang",
".",
"LoadLocaleText",
"(",
"l",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"ltext",
",",
"&",
"t",
".",
"resources",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// loadResource loads the translations according to the locale
|
[
"loadResource",
"loads",
"the",
"translations",
"according",
"to",
"the",
"locale"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/translator.go#L63-L75
|
20,427
|
uniplaces/carbon
|
translator.go
|
chooseUnit
|
func (t *Translator) chooseUnit(unit string, count int64) (string, error) {
s := strings.Split(t.resources[unit], "|")
if count > 1 {
return strings.Replace(s[1], ":count", strconv.FormatInt(int64(count), 10), 1), nil
}
return s[0], nil
}
|
go
|
func (t *Translator) chooseUnit(unit string, count int64) (string, error) {
s := strings.Split(t.resources[unit], "|")
if count > 1 {
return strings.Replace(s[1], ":count", strconv.FormatInt(int64(count), 10), 1), nil
}
return s[0], nil
}
|
[
"func",
"(",
"t",
"*",
"Translator",
")",
"chooseUnit",
"(",
"unit",
"string",
",",
"count",
"int64",
")",
"(",
"string",
",",
"error",
")",
"{",
"s",
":=",
"strings",
".",
"Split",
"(",
"t",
".",
"resources",
"[",
"unit",
"]",
",",
"\"",
"\"",
")",
"\n",
"if",
"count",
">",
"1",
"{",
"return",
"strings",
".",
"Replace",
"(",
"s",
"[",
"1",
"]",
",",
"\"",
"\"",
",",
"strconv",
".",
"FormatInt",
"(",
"int64",
"(",
"count",
")",
",",
"10",
")",
",",
"1",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"s",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] |
// chooseUnit will choose unit of translations according to the count
|
[
"chooseUnit",
"will",
"choose",
"unit",
"of",
"translations",
"according",
"to",
"the",
"count"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/translator.go#L78-L85
|
20,428
|
uniplaces/carbon
|
translator.go
|
chooseTrans
|
func (t *Translator) chooseTrans(transID, time string) string {
return strings.Replace(t.resources[transID], ":time", time, 1)
}
|
go
|
func (t *Translator) chooseTrans(transID, time string) string {
return strings.Replace(t.resources[transID], ":time", time, 1)
}
|
[
"func",
"(",
"t",
"*",
"Translator",
")",
"chooseTrans",
"(",
"transID",
",",
"time",
"string",
")",
"string",
"{",
"return",
"strings",
".",
"Replace",
"(",
"t",
".",
"resources",
"[",
"transID",
"]",
",",
"\"",
"\"",
",",
"time",
",",
"1",
")",
"\n",
"}"
] |
// chooseTrans will choose the word to make a diffForHumans statement
|
[
"chooseTrans",
"will",
"choose",
"the",
"word",
"to",
"make",
"a",
"diffForHumans",
"statement"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/translator.go#L88-L90
|
20,429
|
uniplaces/carbon
|
lang/loader.go
|
LoadLocaleText
|
func LoadLocaleText(l string) ([]byte, error) {
lText, err := ioutil.ReadFile("./lang/" + l + ".json")
if err != nil {
return nil, errors.New("not able to read the lang file:" + err.Error())
}
return lText, nil
}
|
go
|
func LoadLocaleText(l string) ([]byte, error) {
lText, err := ioutil.ReadFile("./lang/" + l + ".json")
if err != nil {
return nil, errors.New("not able to read the lang file:" + err.Error())
}
return lText, nil
}
|
[
"func",
"LoadLocaleText",
"(",
"l",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"lText",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"\"",
"\"",
"+",
"l",
"+",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"lText",
",",
"nil",
"\n",
"}"
] |
// LoadLocaleText will load the translations from the locale json files according to the locale
|
[
"LoadLocaleText",
"will",
"load",
"the",
"translations",
"from",
"the",
"locale",
"json",
"files",
"according",
"to",
"the",
"locale"
] |
223a8652664c690cc91a950eba4cbbc579defb71
|
https://github.com/uniplaces/carbon/blob/223a8652664c690cc91a950eba4cbbc579defb71/lang/loader.go#L9-L16
|
20,430
|
matryer/is
|
is.go
|
New
|
func New(t T) *I {
return &I{t, t.FailNow, os.Stdout, !noColorFlag}
}
|
go
|
func New(t T) *I {
return &I{t, t.FailNow, os.Stdout, !noColorFlag}
}
|
[
"func",
"New",
"(",
"t",
"T",
")",
"*",
"I",
"{",
"return",
"&",
"I",
"{",
"t",
",",
"t",
".",
"FailNow",
",",
"os",
".",
"Stdout",
",",
"!",
"noColorFlag",
"}",
"\n",
"}"
] |
// New makes a new testing helper using the specified
// T through which failures will be reported.
// In strict mode, failures call T.FailNow causing the test
// to be aborted. See NewRelaxed for alternative behavior.
|
[
"New",
"makes",
"a",
"new",
"testing",
"helper",
"using",
"the",
"specified",
"T",
"through",
"which",
"failures",
"will",
"be",
"reported",
".",
"In",
"strict",
"mode",
"failures",
"call",
"T",
".",
"FailNow",
"causing",
"the",
"test",
"to",
"be",
"aborted",
".",
"See",
"NewRelaxed",
"for",
"alternative",
"behavior",
"."
] |
2eb2c933a79e268369b74caa16ac7f4b84bba0ab
|
https://github.com/matryer/is/blob/2eb2c933a79e268369b74caa16ac7f4b84bba0ab/is.go#L84-L86
|
20,431
|
matryer/is
|
is.go
|
NewRelaxed
|
func NewRelaxed(t T) *I {
return &I{t, t.Fail, os.Stdout, !noColorFlag}
}
|
go
|
func NewRelaxed(t T) *I {
return &I{t, t.Fail, os.Stdout, !noColorFlag}
}
|
[
"func",
"NewRelaxed",
"(",
"t",
"T",
")",
"*",
"I",
"{",
"return",
"&",
"I",
"{",
"t",
",",
"t",
".",
"Fail",
",",
"os",
".",
"Stdout",
",",
"!",
"noColorFlag",
"}",
"\n",
"}"
] |
// NewRelaxed makes a new testing helper using the specified
// T through which failures will be reported.
// In relaxed mode, failures call T.Fail allowing
// multiple failures per test.
|
[
"NewRelaxed",
"makes",
"a",
"new",
"testing",
"helper",
"using",
"the",
"specified",
"T",
"through",
"which",
"failures",
"will",
"be",
"reported",
".",
"In",
"relaxed",
"mode",
"failures",
"call",
"T",
".",
"Fail",
"allowing",
"multiple",
"failures",
"per",
"test",
"."
] |
2eb2c933a79e268369b74caa16ac7f4b84bba0ab
|
https://github.com/matryer/is/blob/2eb2c933a79e268369b74caa16ac7f4b84bba0ab/is.go#L92-L94
|
20,432
|
matryer/is
|
is.go
|
loadComment
|
func loadComment(path string, line int) (string, bool) {
f, err := os.Open(path)
if err != nil {
return "", false
}
defer f.Close()
s := bufio.NewScanner(f)
i := 1
for s.Scan() {
if i == line {
text := s.Text()
commentI := strings.Index(text, "//")
if commentI == -1 {
return "", false // no comment
}
text = text[commentI+2:]
text = strings.TrimSpace(text)
return text, true
}
i++
}
return "", false
}
|
go
|
func loadComment(path string, line int) (string, bool) {
f, err := os.Open(path)
if err != nil {
return "", false
}
defer f.Close()
s := bufio.NewScanner(f)
i := 1
for s.Scan() {
if i == line {
text := s.Text()
commentI := strings.Index(text, "//")
if commentI == -1 {
return "", false // no comment
}
text = text[commentI+2:]
text = strings.TrimSpace(text)
return text, true
}
i++
}
return "", false
}
|
[
"func",
"loadComment",
"(",
"path",
"string",
",",
"line",
"int",
")",
"(",
"string",
",",
"bool",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"s",
":=",
"bufio",
".",
"NewScanner",
"(",
"f",
")",
"\n",
"i",
":=",
"1",
"\n",
"for",
"s",
".",
"Scan",
"(",
")",
"{",
"if",
"i",
"==",
"line",
"{",
"text",
":=",
"s",
".",
"Text",
"(",
")",
"\n",
"commentI",
":=",
"strings",
".",
"Index",
"(",
"text",
",",
"\"",
"\"",
")",
"\n",
"if",
"commentI",
"==",
"-",
"1",
"{",
"return",
"\"",
"\"",
",",
"false",
"// no comment",
"\n",
"}",
"\n",
"text",
"=",
"text",
"[",
"commentI",
"+",
"2",
":",
"]",
"\n",
"text",
"=",
"strings",
".",
"TrimSpace",
"(",
"text",
")",
"\n",
"return",
"text",
",",
"true",
"\n",
"}",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}"
] |
// loadComment gets the Go comment from the specified line
// in the specified file.
|
[
"loadComment",
"gets",
"the",
"Go",
"comment",
"from",
"the",
"specified",
"line",
"in",
"the",
"specified",
"file",
"."
] |
2eb2c933a79e268369b74caa16ac7f4b84bba0ab
|
https://github.com/matryer/is/blob/2eb2c933a79e268369b74caa16ac7f4b84bba0ab/is.go#L272-L294
|
20,433
|
matryer/is
|
is.go
|
loadArguments
|
func loadArguments(path string, line int) (string, bool) {
f, err := os.Open(path)
if err != nil {
return "", false
}
defer f.Close()
s := bufio.NewScanner(f)
i := 1
for s.Scan() {
if i == line {
text := s.Text()
braceI := strings.Index(text, "(")
if braceI == -1 {
return "", false
}
text = text[braceI+1:]
cs := bufio.NewScanner(strings.NewReader(text))
cs.Split(bufio.ScanBytes)
j := 0
c := 1
for cs.Scan() {
switch cs.Text() {
case ")":
c--
case "(":
c++
}
if c == 0 {
break
}
j++
}
text = text[:j]
return text, true
}
i++
}
return "", false
}
|
go
|
func loadArguments(path string, line int) (string, bool) {
f, err := os.Open(path)
if err != nil {
return "", false
}
defer f.Close()
s := bufio.NewScanner(f)
i := 1
for s.Scan() {
if i == line {
text := s.Text()
braceI := strings.Index(text, "(")
if braceI == -1 {
return "", false
}
text = text[braceI+1:]
cs := bufio.NewScanner(strings.NewReader(text))
cs.Split(bufio.ScanBytes)
j := 0
c := 1
for cs.Scan() {
switch cs.Text() {
case ")":
c--
case "(":
c++
}
if c == 0 {
break
}
j++
}
text = text[:j]
return text, true
}
i++
}
return "", false
}
|
[
"func",
"loadArguments",
"(",
"path",
"string",
",",
"line",
"int",
")",
"(",
"string",
",",
"bool",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"s",
":=",
"bufio",
".",
"NewScanner",
"(",
"f",
")",
"\n",
"i",
":=",
"1",
"\n",
"for",
"s",
".",
"Scan",
"(",
")",
"{",
"if",
"i",
"==",
"line",
"{",
"text",
":=",
"s",
".",
"Text",
"(",
")",
"\n",
"braceI",
":=",
"strings",
".",
"Index",
"(",
"text",
",",
"\"",
"\"",
")",
"\n",
"if",
"braceI",
"==",
"-",
"1",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n",
"text",
"=",
"text",
"[",
"braceI",
"+",
"1",
":",
"]",
"\n",
"cs",
":=",
"bufio",
".",
"NewScanner",
"(",
"strings",
".",
"NewReader",
"(",
"text",
")",
")",
"\n",
"cs",
".",
"Split",
"(",
"bufio",
".",
"ScanBytes",
")",
"\n",
"j",
":=",
"0",
"\n",
"c",
":=",
"1",
"\n",
"for",
"cs",
".",
"Scan",
"(",
")",
"{",
"switch",
"cs",
".",
"Text",
"(",
")",
"{",
"case",
"\"",
"\"",
":",
"c",
"--",
"\n",
"case",
"\"",
"\"",
":",
"c",
"++",
"\n",
"}",
"\n",
"if",
"c",
"==",
"0",
"{",
"break",
"\n",
"}",
"\n",
"j",
"++",
"\n",
"}",
"\n",
"text",
"=",
"text",
"[",
":",
"j",
"]",
"\n",
"return",
"text",
",",
"true",
"\n",
"}",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}"
] |
// loadArguments gets the arguments from the function call
// on the specified line of the file.
|
[
"loadArguments",
"gets",
"the",
"arguments",
"from",
"the",
"function",
"call",
"on",
"the",
"specified",
"line",
"of",
"the",
"file",
"."
] |
2eb2c933a79e268369b74caa16ac7f4b84bba0ab
|
https://github.com/matryer/is/blob/2eb2c933a79e268369b74caa16ac7f4b84bba0ab/is.go#L298-L336
|
20,434
|
matryer/is
|
is.go
|
decorate
|
func (is *I) decorate(s string) string {
path, lineNumber, ok := callerinfo() // decorate + log + public function.
file := filepath.Base(path)
if ok {
// Truncate file name at last file name separator.
if index := strings.LastIndex(file, "/"); index >= 0 {
file = file[index+1:]
} else if index = strings.LastIndex(file, "\\"); index >= 0 {
file = file[index+1:]
}
} else {
file = "???"
lineNumber = 1
}
buf := new(bytes.Buffer)
// Every line is indented at least one tab.
buf.WriteByte('\t')
if is.colorful {
buf.WriteString(colorFile)
}
fmt.Fprintf(buf, "%s:%d: ", file, lineNumber)
if is.colorful {
buf.WriteString(colorNormal)
}
lines := strings.Split(s, "\n")
if l := len(lines); l > 1 && lines[l-1] == "" {
lines = lines[:l-1]
}
for i, line := range lines {
if i > 0 {
// Second and subsequent lines are indented an extra tab.
buf.WriteString("\n\t\t")
}
// expand arguments (if $ARGS is present)
if strings.Contains(line, "$ARGS") {
args, _ := loadArguments(path, lineNumber)
line = strings.Replace(line, "$ARGS", args, -1)
}
buf.WriteString(line)
}
comment, ok := loadComment(path, lineNumber)
if ok {
if is.colorful {
buf.WriteString(colorComment)
}
buf.WriteString(" // ")
buf.WriteString(comment)
if is.colorful {
buf.WriteString(colorNormal)
}
}
buf.WriteString("\n")
return buf.String()
}
|
go
|
func (is *I) decorate(s string) string {
path, lineNumber, ok := callerinfo() // decorate + log + public function.
file := filepath.Base(path)
if ok {
// Truncate file name at last file name separator.
if index := strings.LastIndex(file, "/"); index >= 0 {
file = file[index+1:]
} else if index = strings.LastIndex(file, "\\"); index >= 0 {
file = file[index+1:]
}
} else {
file = "???"
lineNumber = 1
}
buf := new(bytes.Buffer)
// Every line is indented at least one tab.
buf.WriteByte('\t')
if is.colorful {
buf.WriteString(colorFile)
}
fmt.Fprintf(buf, "%s:%d: ", file, lineNumber)
if is.colorful {
buf.WriteString(colorNormal)
}
lines := strings.Split(s, "\n")
if l := len(lines); l > 1 && lines[l-1] == "" {
lines = lines[:l-1]
}
for i, line := range lines {
if i > 0 {
// Second and subsequent lines are indented an extra tab.
buf.WriteString("\n\t\t")
}
// expand arguments (if $ARGS is present)
if strings.Contains(line, "$ARGS") {
args, _ := loadArguments(path, lineNumber)
line = strings.Replace(line, "$ARGS", args, -1)
}
buf.WriteString(line)
}
comment, ok := loadComment(path, lineNumber)
if ok {
if is.colorful {
buf.WriteString(colorComment)
}
buf.WriteString(" // ")
buf.WriteString(comment)
if is.colorful {
buf.WriteString(colorNormal)
}
}
buf.WriteString("\n")
return buf.String()
}
|
[
"func",
"(",
"is",
"*",
"I",
")",
"decorate",
"(",
"s",
"string",
")",
"string",
"{",
"path",
",",
"lineNumber",
",",
"ok",
":=",
"callerinfo",
"(",
")",
"// decorate + log + public function.",
"\n",
"file",
":=",
"filepath",
".",
"Base",
"(",
"path",
")",
"\n",
"if",
"ok",
"{",
"// Truncate file name at last file name separator.",
"if",
"index",
":=",
"strings",
".",
"LastIndex",
"(",
"file",
",",
"\"",
"\"",
")",
";",
"index",
">=",
"0",
"{",
"file",
"=",
"file",
"[",
"index",
"+",
"1",
":",
"]",
"\n",
"}",
"else",
"if",
"index",
"=",
"strings",
".",
"LastIndex",
"(",
"file",
",",
"\"",
"\\\\",
"\"",
")",
";",
"index",
">=",
"0",
"{",
"file",
"=",
"file",
"[",
"index",
"+",
"1",
":",
"]",
"\n",
"}",
"\n",
"}",
"else",
"{",
"file",
"=",
"\"",
"\"",
"\n",
"lineNumber",
"=",
"1",
"\n",
"}",
"\n",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"// Every line is indented at least one tab.",
"buf",
".",
"WriteByte",
"(",
"'\\t'",
")",
"\n",
"if",
"is",
".",
"colorful",
"{",
"buf",
".",
"WriteString",
"(",
"colorFile",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"buf",
",",
"\"",
"\"",
",",
"file",
",",
"lineNumber",
")",
"\n",
"if",
"is",
".",
"colorful",
"{",
"buf",
".",
"WriteString",
"(",
"colorNormal",
")",
"\n",
"}",
"\n",
"lines",
":=",
"strings",
".",
"Split",
"(",
"s",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"if",
"l",
":=",
"len",
"(",
"lines",
")",
";",
"l",
">",
"1",
"&&",
"lines",
"[",
"l",
"-",
"1",
"]",
"==",
"\"",
"\"",
"{",
"lines",
"=",
"lines",
"[",
":",
"l",
"-",
"1",
"]",
"\n",
"}",
"\n",
"for",
"i",
",",
"line",
":=",
"range",
"lines",
"{",
"if",
"i",
">",
"0",
"{",
"// Second and subsequent lines are indented an extra tab.",
"buf",
".",
"WriteString",
"(",
"\"",
"\\n",
"\\t",
"\\t",
"\"",
")",
"\n",
"}",
"\n",
"// expand arguments (if $ARGS is present)",
"if",
"strings",
".",
"Contains",
"(",
"line",
",",
"\"",
"\"",
")",
"{",
"args",
",",
"_",
":=",
"loadArguments",
"(",
"path",
",",
"lineNumber",
")",
"\n",
"line",
"=",
"strings",
".",
"Replace",
"(",
"line",
",",
"\"",
"\"",
",",
"args",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"buf",
".",
"WriteString",
"(",
"line",
")",
"\n",
"}",
"\n",
"comment",
",",
"ok",
":=",
"loadComment",
"(",
"path",
",",
"lineNumber",
")",
"\n",
"if",
"ok",
"{",
"if",
"is",
".",
"colorful",
"{",
"buf",
".",
"WriteString",
"(",
"colorComment",
")",
"\n",
"}",
"\n",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"buf",
".",
"WriteString",
"(",
"comment",
")",
"\n",
"if",
"is",
".",
"colorful",
"{",
"buf",
".",
"WriteString",
"(",
"colorNormal",
")",
"\n",
"}",
"\n",
"}",
"\n",
"buf",
".",
"WriteString",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] |
// decorate prefixes the string with the file and line of the call site
// and inserts the final newline if needed and indentation tabs for formatting.
// this function was copied from the testing framework and modified.
|
[
"decorate",
"prefixes",
"the",
"string",
"with",
"the",
"file",
"and",
"line",
"of",
"the",
"call",
"site",
"and",
"inserts",
"the",
"final",
"newline",
"if",
"needed",
"and",
"indentation",
"tabs",
"for",
"formatting",
".",
"this",
"function",
"was",
"copied",
"from",
"the",
"testing",
"framework",
"and",
"modified",
"."
] |
2eb2c933a79e268369b74caa16ac7f4b84bba0ab
|
https://github.com/matryer/is/blob/2eb2c933a79e268369b74caa16ac7f4b84bba0ab/is.go#L341-L394
|
20,435
|
araddon/qlbridge
|
lex/dialect_sql.go
|
LexEndOfSubStatement
|
func LexEndOfSubStatement(l *Lexer) StateFn {
l.SkipWhiteSpaces()
if strings.ToLower(l.PeekX(2)) == "as" {
return nil
}
l.backup()
return l.errorToken("Unexpected token:" + l.current())
}
|
go
|
func LexEndOfSubStatement(l *Lexer) StateFn {
l.SkipWhiteSpaces()
if strings.ToLower(l.PeekX(2)) == "as" {
return nil
}
l.backup()
return l.errorToken("Unexpected token:" + l.current())
}
|
[
"func",
"LexEndOfSubStatement",
"(",
"l",
"*",
"Lexer",
")",
"StateFn",
"{",
"l",
".",
"SkipWhiteSpaces",
"(",
")",
"\n",
"if",
"strings",
".",
"ToLower",
"(",
"l",
".",
"PeekX",
"(",
"2",
")",
")",
"==",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"l",
".",
"backup",
"(",
")",
"\n",
"return",
"l",
".",
"errorToken",
"(",
"\"",
"\"",
"+",
"l",
".",
"current",
"(",
")",
")",
"\n",
"}"
] |
// LexEndOfSubStatement Look for end of statement defined by either
// a semicolon or end of file.
|
[
"LexEndOfSubStatement",
"Look",
"for",
"end",
"of",
"statement",
"defined",
"by",
"either",
"a",
"semicolon",
"or",
"end",
"of",
"file",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/lex/dialect_sql.go#L238-L245
|
20,436
|
araddon/qlbridge
|
lex/dialect_sql.go
|
LexLimit
|
func LexLimit(l *Lexer) StateFn {
l.SkipWhiteSpaces()
keyWord := strings.ToLower(l.PeekWord())
//u.Debugf("LexLimit r= '%v'", string(keyWord))
switch keyWord {
case "offset":
return nil
case "", ";":
return nil
case ",":
l.ConsumeWord(keyWord)
l.Emit(TokenComma)
return LexNumber
default:
if isDigit(l.Peek()) {
l.Push("LexLimit", LexLimit)
return LexNumber
}
}
return nil
}
|
go
|
func LexLimit(l *Lexer) StateFn {
l.SkipWhiteSpaces()
keyWord := strings.ToLower(l.PeekWord())
//u.Debugf("LexLimit r= '%v'", string(keyWord))
switch keyWord {
case "offset":
return nil
case "", ";":
return nil
case ",":
l.ConsumeWord(keyWord)
l.Emit(TokenComma)
return LexNumber
default:
if isDigit(l.Peek()) {
l.Push("LexLimit", LexLimit)
return LexNumber
}
}
return nil
}
|
[
"func",
"LexLimit",
"(",
"l",
"*",
"Lexer",
")",
"StateFn",
"{",
"l",
".",
"SkipWhiteSpaces",
"(",
")",
"\n",
"keyWord",
":=",
"strings",
".",
"ToLower",
"(",
"l",
".",
"PeekWord",
"(",
")",
")",
"\n",
"//u.Debugf(\"LexLimit r= '%v'\", string(keyWord))",
"switch",
"keyWord",
"{",
"case",
"\"",
"\"",
":",
"return",
"nil",
"\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"l",
".",
"ConsumeWord",
"(",
"keyWord",
")",
"\n",
"l",
".",
"Emit",
"(",
"TokenComma",
")",
"\n",
"return",
"LexNumber",
"\n",
"default",
":",
"if",
"isDigit",
"(",
"l",
".",
"Peek",
"(",
")",
")",
"{",
"l",
".",
"Push",
"(",
"\"",
"\"",
",",
"LexLimit",
")",
"\n",
"return",
"LexNumber",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// LexLimit clause
//
// LIMIT 1000 OFFSET 100
// LIMIT 0, 1000
// LIMIT 1000
|
[
"LexLimit",
"clause",
"LIMIT",
"1000",
"OFFSET",
"100",
"LIMIT",
"0",
"1000",
"LIMIT",
"1000"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/lex/dialect_sql.go#L366-L388
|
20,437
|
araddon/qlbridge
|
lex/dialect_sql.go
|
LexDdlTable
|
func LexDdlTable(l *Lexer) StateFn {
/*
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
(create_definition,...)
[table_options]
[partition_options]
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
[(create_definition,...)]
[table_options]
[partition_options]
[IGNORE | REPLACE]
[AS] query_expression
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
{ LIKE old_tbl_name | (LIKE old_tbl_name) }
CREATE TABLE `City` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` char(35) NOT NULL DEFAULT '',
`CountryCode` char(3) NOT NULL DEFAULT '',
`District` char(20) NOT NULL DEFAULT '',
`Population` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `CountryCode` (`CountryCode`),
CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`)
REFERENCES `Country` (`Code`)
) ENGINE=InnoDB AUTO_INCREMENT=4080 DEFAULT CHARSET=utf8
*/
l.SkipWhiteSpaces()
r := l.Next()
//u.Debugf("LexDdlTable r= '%v'", string(r))
// Cover the logic and grouping
switch r {
case '(':
// Start of columns
l.Emit(TokenLeftParenthesis)
l.Push("LexDdlTableColumn", LexDdlTableColumn)
return LexIdentifier
case ')':
// end of columns
l.Emit(TokenRightParenthesis)
return LexDdlTableStorage
case '-', '/': // comment?
p := l.Peek()
if p == '-' {
l.backup()
l.Push("LexDdlTable", LexDdlTable)
return LexInlineComment
}
u.Warnf("unhandled comment non inline ")
case ';':
l.backup()
return nil
}
l.backup()
word := strings.ToLower(l.PeekWord())
//u.Debugf("looking table col start: word=%s", word)
r = l.Peek()
if r == ',' {
l.Emit(TokenComma)
l.Push("LexDdlTable", l.clauseState())
return LexExpressionOrIdentity
}
if l.isNextKeyword(word) {
return nil
}
// ensure we don't get into a recursive death spiral here?
if len(l.stack) < 10 {
l.Push("LexDdlTable", LexDdlTable)
} else {
u.Errorf("Gracefully refusing to add more LexDdlTable: ")
}
return LexExpressionOrIdentity
}
|
go
|
func LexDdlTable(l *Lexer) StateFn {
/*
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
(create_definition,...)
[table_options]
[partition_options]
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
[(create_definition,...)]
[table_options]
[partition_options]
[IGNORE | REPLACE]
[AS] query_expression
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
{ LIKE old_tbl_name | (LIKE old_tbl_name) }
CREATE TABLE `City` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` char(35) NOT NULL DEFAULT '',
`CountryCode` char(3) NOT NULL DEFAULT '',
`District` char(20) NOT NULL DEFAULT '',
`Population` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `CountryCode` (`CountryCode`),
CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`)
REFERENCES `Country` (`Code`)
) ENGINE=InnoDB AUTO_INCREMENT=4080 DEFAULT CHARSET=utf8
*/
l.SkipWhiteSpaces()
r := l.Next()
//u.Debugf("LexDdlTable r= '%v'", string(r))
// Cover the logic and grouping
switch r {
case '(':
// Start of columns
l.Emit(TokenLeftParenthesis)
l.Push("LexDdlTableColumn", LexDdlTableColumn)
return LexIdentifier
case ')':
// end of columns
l.Emit(TokenRightParenthesis)
return LexDdlTableStorage
case '-', '/': // comment?
p := l.Peek()
if p == '-' {
l.backup()
l.Push("LexDdlTable", LexDdlTable)
return LexInlineComment
}
u.Warnf("unhandled comment non inline ")
case ';':
l.backup()
return nil
}
l.backup()
word := strings.ToLower(l.PeekWord())
//u.Debugf("looking table col start: word=%s", word)
r = l.Peek()
if r == ',' {
l.Emit(TokenComma)
l.Push("LexDdlTable", l.clauseState())
return LexExpressionOrIdentity
}
if l.isNextKeyword(word) {
return nil
}
// ensure we don't get into a recursive death spiral here?
if len(l.stack) < 10 {
l.Push("LexDdlTable", LexDdlTable)
} else {
u.Errorf("Gracefully refusing to add more LexDdlTable: ")
}
return LexExpressionOrIdentity
}
|
[
"func",
"LexDdlTable",
"(",
"l",
"*",
"Lexer",
")",
"StateFn",
"{",
"/*\n\t\tCREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name\n\t\t (create_definition,...)\n\t\t [table_options]\n\t\t [partition_options]\n\n\t\tCREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name\n\t\t [(create_definition,...)]\n\t\t [table_options]\n\t\t [partition_options]\n\t\t [IGNORE | REPLACE]\n\t\t [AS] query_expression\n\n\t\tCREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name\n\t\t { LIKE old_tbl_name | (LIKE old_tbl_name) }\n\n\t\tCREATE TABLE `City` (\n\t\t `ID` int(11) NOT NULL AUTO_INCREMENT,\n\t\t `Name` char(35) NOT NULL DEFAULT '',\n\t\t `CountryCode` char(3) NOT NULL DEFAULT '',\n\t\t `District` char(20) NOT NULL DEFAULT '',\n\t\t `Population` int(11) NOT NULL DEFAULT '0',\n\t\t PRIMARY KEY (`ID`),\n\t\t KEY `CountryCode` (`CountryCode`),\n\t\t CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`)\n\t\t REFERENCES `Country` (`Code`)\n\t\t) ENGINE=InnoDB AUTO_INCREMENT=4080 DEFAULT CHARSET=utf8\n\t*/",
"l",
".",
"SkipWhiteSpaces",
"(",
")",
"\n",
"r",
":=",
"l",
".",
"Next",
"(",
")",
"\n\n",
"//u.Debugf(\"LexDdlTable r= '%v'\", string(r))",
"// Cover the logic and grouping",
"switch",
"r",
"{",
"case",
"'('",
":",
"// Start of columns",
"l",
".",
"Emit",
"(",
"TokenLeftParenthesis",
")",
"\n",
"l",
".",
"Push",
"(",
"\"",
"\"",
",",
"LexDdlTableColumn",
")",
"\n",
"return",
"LexIdentifier",
"\n",
"case",
"')'",
":",
"// end of columns",
"l",
".",
"Emit",
"(",
"TokenRightParenthesis",
")",
"\n",
"return",
"LexDdlTableStorage",
"\n",
"case",
"'-'",
",",
"'/'",
":",
"// comment?",
"p",
":=",
"l",
".",
"Peek",
"(",
")",
"\n",
"if",
"p",
"==",
"'-'",
"{",
"l",
".",
"backup",
"(",
")",
"\n",
"l",
".",
"Push",
"(",
"\"",
"\"",
",",
"LexDdlTable",
")",
"\n",
"return",
"LexInlineComment",
"\n",
"}",
"\n",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"';'",
":",
"l",
".",
"backup",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"l",
".",
"backup",
"(",
")",
"\n",
"word",
":=",
"strings",
".",
"ToLower",
"(",
"l",
".",
"PeekWord",
"(",
")",
")",
"\n",
"//u.Debugf(\"looking table col start: word=%s\", word)",
"r",
"=",
"l",
".",
"Peek",
"(",
")",
"\n",
"if",
"r",
"==",
"','",
"{",
"l",
".",
"Emit",
"(",
"TokenComma",
")",
"\n",
"l",
".",
"Push",
"(",
"\"",
"\"",
",",
"l",
".",
"clauseState",
"(",
")",
")",
"\n",
"return",
"LexExpressionOrIdentity",
"\n",
"}",
"\n",
"if",
"l",
".",
"isNextKeyword",
"(",
"word",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"// ensure we don't get into a recursive death spiral here?",
"if",
"len",
"(",
"l",
".",
"stack",
")",
"<",
"10",
"{",
"l",
".",
"Push",
"(",
"\"",
"\"",
",",
"LexDdlTable",
")",
"\n",
"}",
"else",
"{",
"u",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"LexExpressionOrIdentity",
"\n",
"}"
] |
// LexDdlTable data definition language table
|
[
"LexDdlTable",
"data",
"definition",
"language",
"table"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/lex/dialect_sql.go#L556-L634
|
20,438
|
araddon/qlbridge
|
datasource/sqlite/source.go
|
Setup
|
func (m *Source) Setup(s *schema.Schema) error {
m.mu.Lock()
defer m.mu.Unlock()
u.Debugf("got new sqlite schema %s", s.Name)
m.schema = s
if m.db != nil {
return nil
}
m.file = s.Conf.Settings.String("file")
if m.file == "" {
m.file = fmt.Sprintf("/tmp/%s.sql.db", s.Name)
u.Warnf("using tmp? %q", m.file)
}
// It will be created if it doesn't exist.
// "./source.enriched.db"
db, err := sql.Open("sqlite3", m.file)
if err != nil {
u.Errorf("could not open %q err=%v", m.file, err)
return err
}
err = db.Ping()
if err != nil {
u.Errorf("could not ping %q err=%v", m.file, err)
return err
}
m.db = db
// SELECT * FROM dbname.sqlite_master WHERE type='table';
rows, err := db.Query("SELECT tbl_name, sql FROM sqlite_master WHERE type='table';")
if err != nil {
u.Errorf("could not open master err=%v", err)
return err
}
var name, sql string
for rows.Next() {
rows.Scan(&name, &sql)
name = strings.ToLower(name)
t := tableFromSQL(name, sql)
m.tables[name] = t
m.tableList = append(m.tableList, name)
}
rows.Close()
// if err := datasource.IntrospectTable(m.tbl, m.CreateIterator()); err != nil {
// u.Errorf("Could not introspect schema %v", err)
// }
return nil
}
|
go
|
func (m *Source) Setup(s *schema.Schema) error {
m.mu.Lock()
defer m.mu.Unlock()
u.Debugf("got new sqlite schema %s", s.Name)
m.schema = s
if m.db != nil {
return nil
}
m.file = s.Conf.Settings.String("file")
if m.file == "" {
m.file = fmt.Sprintf("/tmp/%s.sql.db", s.Name)
u.Warnf("using tmp? %q", m.file)
}
// It will be created if it doesn't exist.
// "./source.enriched.db"
db, err := sql.Open("sqlite3", m.file)
if err != nil {
u.Errorf("could not open %q err=%v", m.file, err)
return err
}
err = db.Ping()
if err != nil {
u.Errorf("could not ping %q err=%v", m.file, err)
return err
}
m.db = db
// SELECT * FROM dbname.sqlite_master WHERE type='table';
rows, err := db.Query("SELECT tbl_name, sql FROM sqlite_master WHERE type='table';")
if err != nil {
u.Errorf("could not open master err=%v", err)
return err
}
var name, sql string
for rows.Next() {
rows.Scan(&name, &sql)
name = strings.ToLower(name)
t := tableFromSQL(name, sql)
m.tables[name] = t
m.tableList = append(m.tableList, name)
}
rows.Close()
// if err := datasource.IntrospectTable(m.tbl, m.CreateIterator()); err != nil {
// u.Errorf("Could not introspect schema %v", err)
// }
return nil
}
|
[
"func",
"(",
"m",
"*",
"Source",
")",
"Setup",
"(",
"s",
"*",
"schema",
".",
"Schema",
")",
"error",
"{",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"u",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"s",
".",
"Name",
")",
"\n",
"m",
".",
"schema",
"=",
"s",
"\n",
"if",
"m",
".",
"db",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"m",
".",
"file",
"=",
"s",
".",
"Conf",
".",
"Settings",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"if",
"m",
".",
"file",
"==",
"\"",
"\"",
"{",
"m",
".",
"file",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"Name",
")",
"\n",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"m",
".",
"file",
")",
"\n",
"}",
"\n\n",
"// It will be created if it doesn't exist.",
"// \"./source.enriched.db\"",
"db",
",",
"err",
":=",
"sql",
".",
"Open",
"(",
"\"",
"\"",
",",
"m",
".",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"u",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
".",
"file",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"db",
".",
"Ping",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"u",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
".",
"file",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"m",
".",
"db",
"=",
"db",
"\n\n",
"// SELECT * FROM dbname.sqlite_master WHERE type='table';",
"rows",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"u",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"var",
"name",
",",
"sql",
"string",
"\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"rows",
".",
"Scan",
"(",
"&",
"name",
",",
"&",
"sql",
")",
"\n",
"name",
"=",
"strings",
".",
"ToLower",
"(",
"name",
")",
"\n",
"t",
":=",
"tableFromSQL",
"(",
"name",
",",
"sql",
")",
"\n",
"m",
".",
"tables",
"[",
"name",
"]",
"=",
"t",
"\n",
"m",
".",
"tableList",
"=",
"append",
"(",
"m",
".",
"tableList",
",",
"name",
")",
"\n",
"}",
"\n",
"rows",
".",
"Close",
"(",
")",
"\n\n",
"// if err := datasource.IntrospectTable(m.tbl, m.CreateIterator()); err != nil {",
"// \tu.Errorf(\"Could not introspect schema %v\", err)",
"// }",
"return",
"nil",
"\n",
"}"
] |
// Setup this source with schema from parent.
|
[
"Setup",
"this",
"source",
"with",
"schema",
"from",
"parent",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/datasource/sqlite/source.go#L62-L113
|
20,439
|
araddon/qlbridge
|
datasource/sqlite/source.go
|
Open
|
func (m *Source) Open(table string) (schema.Conn, error) {
//u.Infof("Open conn=%q", table)
m.tblmu.Lock()
t, ok := m.tables[table]
m.tblmu.Unlock()
if !ok {
return nil, schema.ErrNotFound
}
m.mu.Lock()
//u.Infof("after open lock")
qc := newQueryConn(t, m)
m.qryconns[table] = qc
return qc, nil
}
|
go
|
func (m *Source) Open(table string) (schema.Conn, error) {
//u.Infof("Open conn=%q", table)
m.tblmu.Lock()
t, ok := m.tables[table]
m.tblmu.Unlock()
if !ok {
return nil, schema.ErrNotFound
}
m.mu.Lock()
//u.Infof("after open lock")
qc := newQueryConn(t, m)
m.qryconns[table] = qc
return qc, nil
}
|
[
"func",
"(",
"m",
"*",
"Source",
")",
"Open",
"(",
"table",
"string",
")",
"(",
"schema",
".",
"Conn",
",",
"error",
")",
"{",
"//u.Infof(\"Open conn=%q\", table)",
"m",
".",
"tblmu",
".",
"Lock",
"(",
")",
"\n",
"t",
",",
"ok",
":=",
"m",
".",
"tables",
"[",
"table",
"]",
"\n",
"m",
".",
"tblmu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"schema",
".",
"ErrNotFound",
"\n",
"}",
"\n",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"//u.Infof(\"after open lock\")",
"qc",
":=",
"newQueryConn",
"(",
"t",
",",
"m",
")",
"\n",
"m",
".",
"qryconns",
"[",
"table",
"]",
"=",
"qc",
"\n",
"return",
"qc",
",",
"nil",
"\n",
"}"
] |
// Open a connection, since sqlite is not threadsafe, this is locked.
|
[
"Open",
"a",
"connection",
"since",
"sqlite",
"is",
"not",
"threadsafe",
"this",
"is",
"locked",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/datasource/sqlite/source.go#L119-L132
|
20,440
|
araddon/qlbridge
|
datasource/sqlite/source.go
|
Table
|
func (m *Source) Table(table string) (*schema.Table, error) {
u.Infof("source.Table(%q)", table)
m.tblmu.Lock()
t, ok := m.tables[table]
m.tblmu.Unlock()
if !ok {
return nil, schema.ErrNotFound
}
return t, nil
}
|
go
|
func (m *Source) Table(table string) (*schema.Table, error) {
u.Infof("source.Table(%q)", table)
m.tblmu.Lock()
t, ok := m.tables[table]
m.tblmu.Unlock()
if !ok {
return nil, schema.ErrNotFound
}
return t, nil
}
|
[
"func",
"(",
"m",
"*",
"Source",
")",
"Table",
"(",
"table",
"string",
")",
"(",
"*",
"schema",
".",
"Table",
",",
"error",
")",
"{",
"u",
".",
"Infof",
"(",
"\"",
"\"",
",",
"table",
")",
"\n",
"m",
".",
"tblmu",
".",
"Lock",
"(",
")",
"\n",
"t",
",",
"ok",
":=",
"m",
".",
"tables",
"[",
"table",
"]",
"\n",
"m",
".",
"tblmu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"schema",
".",
"ErrNotFound",
"\n",
"}",
"\n",
"return",
"t",
",",
"nil",
"\n",
"}"
] |
// Table gets table schema for given table
|
[
"Table",
"gets",
"table",
"schema",
"for",
"given",
"table"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/datasource/sqlite/source.go#L135-L144
|
20,441
|
araddon/qlbridge
|
datasource/sqlite/source.go
|
Close
|
func (m *Source) Close() error {
if m.db != nil {
err := m.db.Close()
if err != nil {
return err
}
m.db = nil
}
return nil
}
|
go
|
func (m *Source) Close() error {
if m.db != nil {
err := m.db.Close()
if err != nil {
return err
}
m.db = nil
}
return nil
}
|
[
"func",
"(",
"m",
"*",
"Source",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"m",
".",
"db",
"!=",
"nil",
"{",
"err",
":=",
"m",
".",
"db",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"m",
".",
"db",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close this source, closing the underlying sqlite db file
|
[
"Close",
"this",
"source",
"closing",
"the",
"underlying",
"sqlite",
"db",
"file"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/datasource/sqlite/source.go#L150-L159
|
20,442
|
araddon/qlbridge
|
vm/vm.go
|
errRecover
|
func errRecover(errp *error) {
e := recover()
if e != nil {
switch err := e.(type) {
case runtime.Error:
panic(e)
case error:
*errp = err
default:
panic(e)
}
}
}
|
go
|
func errRecover(errp *error) {
e := recover()
if e != nil {
switch err := e.(type) {
case runtime.Error:
panic(e)
case error:
*errp = err
default:
panic(e)
}
}
}
|
[
"func",
"errRecover",
"(",
"errp",
"*",
"error",
")",
"{",
"e",
":=",
"recover",
"(",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"switch",
"err",
":=",
"e",
".",
"(",
"type",
")",
"{",
"case",
"runtime",
".",
"Error",
":",
"panic",
"(",
"e",
")",
"\n",
"case",
"error",
":",
"*",
"errp",
"=",
"err",
"\n",
"default",
":",
"panic",
"(",
"e",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// errRecover is the handler that turns panics into returns from the top
|
[
"errRecover",
"is",
"the",
"handler",
"that",
"turns",
"panics",
"into",
"returns",
"from",
"the",
"top"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/vm/vm.go#L48-L60
|
20,443
|
araddon/qlbridge
|
vm/vm.go
|
numberNodeToValue
|
func numberNodeToValue(t *expr.NumberNode) (value.Value, bool) {
if t.IsInt {
return value.NewIntValue(t.Int64), true
} else if t.IsFloat {
fv, ok := value.StringToFloat64(t.Text)
if !ok {
u.Debugf("Could not perform numeric conversion for %q", t.Text)
return value.NilValueVal, false
}
return value.NewNumberValue(fv), true
}
u.Debugf("Could not find numeric conversion for %#v", t)
return value.NilValueVal, false
}
|
go
|
func numberNodeToValue(t *expr.NumberNode) (value.Value, bool) {
if t.IsInt {
return value.NewIntValue(t.Int64), true
} else if t.IsFloat {
fv, ok := value.StringToFloat64(t.Text)
if !ok {
u.Debugf("Could not perform numeric conversion for %q", t.Text)
return value.NilValueVal, false
}
return value.NewNumberValue(fv), true
}
u.Debugf("Could not find numeric conversion for %#v", t)
return value.NilValueVal, false
}
|
[
"func",
"numberNodeToValue",
"(",
"t",
"*",
"expr",
".",
"NumberNode",
")",
"(",
"value",
".",
"Value",
",",
"bool",
")",
"{",
"if",
"t",
".",
"IsInt",
"{",
"return",
"value",
".",
"NewIntValue",
"(",
"t",
".",
"Int64",
")",
",",
"true",
"\n",
"}",
"else",
"if",
"t",
".",
"IsFloat",
"{",
"fv",
",",
"ok",
":=",
"value",
".",
"StringToFloat64",
"(",
"t",
".",
"Text",
")",
"\n",
"if",
"!",
"ok",
"{",
"u",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"t",
".",
"Text",
")",
"\n",
"return",
"value",
".",
"NilValueVal",
",",
"false",
"\n",
"}",
"\n",
"return",
"value",
".",
"NewNumberValue",
"(",
"fv",
")",
",",
"true",
"\n",
"}",
"\n",
"u",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"t",
")",
"\n",
"return",
"value",
".",
"NilValueVal",
",",
"false",
"\n",
"}"
] |
// creates a new Value with a nil group and given value.
|
[
"creates",
"a",
"new",
"Value",
"with",
"a",
"nil",
"group",
"and",
"given",
"value",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/vm/vm.go#L63-L76
|
20,444
|
araddon/qlbridge
|
vm/vm.go
|
ResolveIncludes
|
func ResolveIncludes(ctx expr.Includer, arg expr.Node) error {
return resolveIncludesDepth(ctx, arg, 0)
}
|
go
|
func ResolveIncludes(ctx expr.Includer, arg expr.Node) error {
return resolveIncludesDepth(ctx, arg, 0)
}
|
[
"func",
"ResolveIncludes",
"(",
"ctx",
"expr",
".",
"Includer",
",",
"arg",
"expr",
".",
"Node",
")",
"error",
"{",
"return",
"resolveIncludesDepth",
"(",
"ctx",
",",
"arg",
",",
"0",
")",
"\n",
"}"
] |
// ResolveIncludes take an expression and resolve any includes so that
// it does not have to be resolved at runtime. There is also a
// InlineIncludes alternative in expr pkg which actually re-writes the expression
// to remove includes and embed the expressions they refer to as part of this expression.
|
[
"ResolveIncludes",
"take",
"an",
"expression",
"and",
"resolve",
"any",
"includes",
"so",
"that",
"it",
"does",
"not",
"have",
"to",
"be",
"resolved",
"at",
"runtime",
".",
"There",
"is",
"also",
"a",
"InlineIncludes",
"alternative",
"in",
"expr",
"pkg",
"which",
"actually",
"re",
"-",
"writes",
"the",
"expression",
"to",
"remove",
"includes",
"and",
"embed",
"the",
"expressions",
"they",
"refer",
"to",
"as",
"part",
"of",
"this",
"expression",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/vm/vm.go#L82-L84
|
20,445
|
araddon/qlbridge
|
vm/vm.go
|
walkTernary
|
func walkTernary(ctx expr.EvalContext, node *expr.TriNode, depth int) (value.Value, bool) {
a, aok := Eval(ctx, node.Args[0])
b, bok := Eval(ctx, node.Args[1])
c, cok := Eval(ctx, node.Args[2])
//u.Infof("tri: %T:%v %v %T:%v %T:%v", a, a, node.Operator, b, b, c, c)
if !aok {
return nil, false
}
if !bok || !cok {
return nil, false
}
if a == nil || b == nil || c == nil {
return nil, false
}
switch node.Operator.T {
case lex.TokenBetween:
switch at := a.(type) {
case value.IntValue:
av := at.Val()
bv, ok := value.ValueToInt64(b)
if !ok {
return nil, false
}
cv, ok := value.ValueToInt64(c)
if !ok {
return nil, false
}
if av > bv && av < cv {
return value.NewBoolValue(true), true
}
return value.NewBoolValue(false), true
case value.NumberValue:
av := at.Val()
bv, ok := value.ValueToFloat64(b)
if !ok {
return nil, false
}
cv, ok := value.ValueToFloat64(c)
if !ok {
return nil, false
}
if av > bv && av < cv {
return value.NewBoolValue(true), true
}
return value.NewBoolValue(false), true
case value.TimeValue:
av := at.Val()
bv, ok := value.ValueToTime(b)
if !ok {
return nil, false
}
cv, ok := value.ValueToTime(c)
if !ok {
return nil, false
}
if av.Unix() > bv.Unix() && av.Unix() < cv.Unix() {
return value.NewBoolValue(true), true
}
return value.NewBoolValue(false), true
default:
u.Warnf("between not implemented for type %s %#v", a.Type().String(), node)
}
default:
u.Warnf("ternary node walk not implemented for node %#v", node)
}
return nil, false
}
|
go
|
func walkTernary(ctx expr.EvalContext, node *expr.TriNode, depth int) (value.Value, bool) {
a, aok := Eval(ctx, node.Args[0])
b, bok := Eval(ctx, node.Args[1])
c, cok := Eval(ctx, node.Args[2])
//u.Infof("tri: %T:%v %v %T:%v %T:%v", a, a, node.Operator, b, b, c, c)
if !aok {
return nil, false
}
if !bok || !cok {
return nil, false
}
if a == nil || b == nil || c == nil {
return nil, false
}
switch node.Operator.T {
case lex.TokenBetween:
switch at := a.(type) {
case value.IntValue:
av := at.Val()
bv, ok := value.ValueToInt64(b)
if !ok {
return nil, false
}
cv, ok := value.ValueToInt64(c)
if !ok {
return nil, false
}
if av > bv && av < cv {
return value.NewBoolValue(true), true
}
return value.NewBoolValue(false), true
case value.NumberValue:
av := at.Val()
bv, ok := value.ValueToFloat64(b)
if !ok {
return nil, false
}
cv, ok := value.ValueToFloat64(c)
if !ok {
return nil, false
}
if av > bv && av < cv {
return value.NewBoolValue(true), true
}
return value.NewBoolValue(false), true
case value.TimeValue:
av := at.Val()
bv, ok := value.ValueToTime(b)
if !ok {
return nil, false
}
cv, ok := value.ValueToTime(c)
if !ok {
return nil, false
}
if av.Unix() > bv.Unix() && av.Unix() < cv.Unix() {
return value.NewBoolValue(true), true
}
return value.NewBoolValue(false), true
default:
u.Warnf("between not implemented for type %s %#v", a.Type().String(), node)
}
default:
u.Warnf("ternary node walk not implemented for node %#v", node)
}
return nil, false
}
|
[
"func",
"walkTernary",
"(",
"ctx",
"expr",
".",
"EvalContext",
",",
"node",
"*",
"expr",
".",
"TriNode",
",",
"depth",
"int",
")",
"(",
"value",
".",
"Value",
",",
"bool",
")",
"{",
"a",
",",
"aok",
":=",
"Eval",
"(",
"ctx",
",",
"node",
".",
"Args",
"[",
"0",
"]",
")",
"\n",
"b",
",",
"bok",
":=",
"Eval",
"(",
"ctx",
",",
"node",
".",
"Args",
"[",
"1",
"]",
")",
"\n",
"c",
",",
"cok",
":=",
"Eval",
"(",
"ctx",
",",
"node",
".",
"Args",
"[",
"2",
"]",
")",
"\n",
"//u.Infof(\"tri: %T:%v %v %T:%v %T:%v\", a, a, node.Operator, b, b, c, c)",
"if",
"!",
"aok",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"if",
"!",
"bok",
"||",
"!",
"cok",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"if",
"a",
"==",
"nil",
"||",
"b",
"==",
"nil",
"||",
"c",
"==",
"nil",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"switch",
"node",
".",
"Operator",
".",
"T",
"{",
"case",
"lex",
".",
"TokenBetween",
":",
"switch",
"at",
":=",
"a",
".",
"(",
"type",
")",
"{",
"case",
"value",
".",
"IntValue",
":",
"av",
":=",
"at",
".",
"Val",
"(",
")",
"\n",
"bv",
",",
"ok",
":=",
"value",
".",
"ValueToInt64",
"(",
"b",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"cv",
",",
"ok",
":=",
"value",
".",
"ValueToInt64",
"(",
"c",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"if",
"av",
">",
"bv",
"&&",
"av",
"<",
"cv",
"{",
"return",
"value",
".",
"NewBoolValue",
"(",
"true",
")",
",",
"true",
"\n",
"}",
"\n\n",
"return",
"value",
".",
"NewBoolValue",
"(",
"false",
")",
",",
"true",
"\n",
"case",
"value",
".",
"NumberValue",
":",
"av",
":=",
"at",
".",
"Val",
"(",
")",
"\n",
"bv",
",",
"ok",
":=",
"value",
".",
"ValueToFloat64",
"(",
"b",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"cv",
",",
"ok",
":=",
"value",
".",
"ValueToFloat64",
"(",
"c",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"if",
"av",
">",
"bv",
"&&",
"av",
"<",
"cv",
"{",
"return",
"value",
".",
"NewBoolValue",
"(",
"true",
")",
",",
"true",
"\n",
"}",
"\n\n",
"return",
"value",
".",
"NewBoolValue",
"(",
"false",
")",
",",
"true",
"\n\n",
"case",
"value",
".",
"TimeValue",
":",
"av",
":=",
"at",
".",
"Val",
"(",
")",
"\n",
"bv",
",",
"ok",
":=",
"value",
".",
"ValueToTime",
"(",
"b",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"cv",
",",
"ok",
":=",
"value",
".",
"ValueToTime",
"(",
"c",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"if",
"av",
".",
"Unix",
"(",
")",
">",
"bv",
".",
"Unix",
"(",
")",
"&&",
"av",
".",
"Unix",
"(",
")",
"<",
"cv",
".",
"Unix",
"(",
")",
"{",
"return",
"value",
".",
"NewBoolValue",
"(",
"true",
")",
",",
"true",
"\n",
"}",
"\n\n",
"return",
"value",
".",
"NewBoolValue",
"(",
"false",
")",
",",
"true",
"\n\n",
"default",
":",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"a",
".",
"Type",
"(",
")",
".",
"String",
"(",
")",
",",
"node",
")",
"\n",
"}",
"\n",
"default",
":",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"node",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"false",
"\n",
"}"
] |
// walkTernary ternary evaluator
//
// A BETWEEN B AND C
//
|
[
"walkTernary",
"ternary",
"evaluator",
"A",
"BETWEEN",
"B",
"AND",
"C"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/vm/vm.go#L893-L969
|
20,446
|
araddon/qlbridge
|
vm/vm.go
|
walkFunc
|
func walkFunc(ctx expr.EvalContext, node *expr.FuncNode, depth int) (value.Value, bool) {
if node.F.CustomFunc == nil {
return nil, false
}
if node.Eval == nil {
u.LogThrottle(u.WARN, 10, "No Eval() for %s", node.Name)
return nil, false
}
args := make([]value.Value, len(node.Args))
for i, a := range node.Args {
v, ok := Eval(ctx, a)
if !ok {
v = value.NewNilValue()
}
args[i] = v
}
return node.Eval(ctx, args)
}
|
go
|
func walkFunc(ctx expr.EvalContext, node *expr.FuncNode, depth int) (value.Value, bool) {
if node.F.CustomFunc == nil {
return nil, false
}
if node.Eval == nil {
u.LogThrottle(u.WARN, 10, "No Eval() for %s", node.Name)
return nil, false
}
args := make([]value.Value, len(node.Args))
for i, a := range node.Args {
v, ok := Eval(ctx, a)
if !ok {
v = value.NewNilValue()
}
args[i] = v
}
return node.Eval(ctx, args)
}
|
[
"func",
"walkFunc",
"(",
"ctx",
"expr",
".",
"EvalContext",
",",
"node",
"*",
"expr",
".",
"FuncNode",
",",
"depth",
"int",
")",
"(",
"value",
".",
"Value",
",",
"bool",
")",
"{",
"if",
"node",
".",
"F",
".",
"CustomFunc",
"==",
"nil",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"if",
"node",
".",
"Eval",
"==",
"nil",
"{",
"u",
".",
"LogThrottle",
"(",
"u",
".",
"WARN",
",",
"10",
",",
"\"",
"\"",
",",
"node",
".",
"Name",
")",
"\n",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n\n",
"args",
":=",
"make",
"(",
"[",
"]",
"value",
".",
"Value",
",",
"len",
"(",
"node",
".",
"Args",
")",
")",
"\n\n",
"for",
"i",
",",
"a",
":=",
"range",
"node",
".",
"Args",
"{",
"v",
",",
"ok",
":=",
"Eval",
"(",
"ctx",
",",
"a",
")",
"\n",
"if",
"!",
"ok",
"{",
"v",
"=",
"value",
".",
"NewNilValue",
"(",
")",
"\n",
"}",
"\n",
"args",
"[",
"i",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"node",
".",
"Eval",
"(",
"ctx",
",",
"args",
")",
"\n",
"}"
] |
// walkFunc evaluates a function
|
[
"walkFunc",
"evaluates",
"a",
"function"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/vm/vm.go#L989-L1009
|
20,447
|
araddon/qlbridge
|
vm/vm.go
|
LikeCompare
|
func LikeCompare(a, b string) (value.BoolValue, bool) {
// Do we want to always do this replacement? Or do this at parse time or config?
if strings.Contains(b, "%") {
b = strings.Replace(b, "%", "*", -1)
}
match, err := glob.Match(b, a)
if err != nil {
return value.BoolValueFalse, false
}
if match {
return value.BoolValueTrue, true
}
return value.BoolValueFalse, true
}
|
go
|
func LikeCompare(a, b string) (value.BoolValue, bool) {
// Do we want to always do this replacement? Or do this at parse time or config?
if strings.Contains(b, "%") {
b = strings.Replace(b, "%", "*", -1)
}
match, err := glob.Match(b, a)
if err != nil {
return value.BoolValueFalse, false
}
if match {
return value.BoolValueTrue, true
}
return value.BoolValueFalse, true
}
|
[
"func",
"LikeCompare",
"(",
"a",
",",
"b",
"string",
")",
"(",
"value",
".",
"BoolValue",
",",
"bool",
")",
"{",
"// Do we want to always do this replacement? Or do this at parse time or config?",
"if",
"strings",
".",
"Contains",
"(",
"b",
",",
"\"",
"\"",
")",
"{",
"b",
"=",
"strings",
".",
"Replace",
"(",
"b",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"match",
",",
"err",
":=",
"glob",
".",
"Match",
"(",
"b",
",",
"a",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"value",
".",
"BoolValueFalse",
",",
"false",
"\n",
"}",
"\n",
"if",
"match",
"{",
"return",
"value",
".",
"BoolValueTrue",
",",
"true",
"\n",
"}",
"\n",
"return",
"value",
".",
"BoolValueFalse",
",",
"true",
"\n",
"}"
] |
// LikeCompare takes two strings and evaluates them for like equality
|
[
"LikeCompare",
"takes",
"two",
"strings",
"and",
"evaluates",
"them",
"for",
"like",
"equality"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/vm/vm.go#L1172-L1185
|
20,448
|
araddon/qlbridge
|
datasource/datatypes.go
|
UnmarshalJSON
|
func (m *JsonHelperScannable) UnmarshalJSON(data []byte) error {
if m == nil {
return errors.New("JsonHelperScannable must not be nil")
}
jh := make(u.JsonHelper)
if err := json.Unmarshal(data, &jh); err != nil {
return err
}
*m = JsonHelperScannable(jh)
return nil
}
|
go
|
func (m *JsonHelperScannable) UnmarshalJSON(data []byte) error {
if m == nil {
return errors.New("JsonHelperScannable must not be nil")
}
jh := make(u.JsonHelper)
if err := json.Unmarshal(data, &jh); err != nil {
return err
}
*m = JsonHelperScannable(jh)
return nil
}
|
[
"func",
"(",
"m",
"*",
"JsonHelperScannable",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"m",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"jh",
":=",
"make",
"(",
"u",
".",
"JsonHelper",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"jh",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"m",
"=",
"JsonHelperScannable",
"(",
"jh",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON bytes into this typed struct
|
[
"UnmarshalJSON",
"bytes",
"into",
"this",
"typed",
"struct"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/datasource/datatypes.go#L139-L149
|
20,449
|
araddon/qlbridge
|
datasource/datatypes.go
|
Value
|
func (m StringArray) Value() (driver.Value, error) {
by, err := json.Marshal(m)
return by, err
}
|
go
|
func (m StringArray) Value() (driver.Value, error) {
by, err := json.Marshal(m)
return by, err
}
|
[
"func",
"(",
"m",
"StringArray",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"by",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"m",
")",
"\n",
"return",
"by",
",",
"err",
"\n",
"}"
] |
// Value convert string to json values
|
[
"Value",
"convert",
"string",
"to",
"json",
"values"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/datasource/datatypes.go#L199-L202
|
20,450
|
araddon/qlbridge
|
expr/include.go
|
InlineIncludes
|
func InlineIncludes(ctx Includer, n Node) (Node, error) {
return doInlineIncludes(ctx, n, 0)
}
|
go
|
func InlineIncludes(ctx Includer, n Node) (Node, error) {
return doInlineIncludes(ctx, n, 0)
}
|
[
"func",
"InlineIncludes",
"(",
"ctx",
"Includer",
",",
"n",
"Node",
")",
"(",
"Node",
",",
"error",
")",
"{",
"return",
"doInlineIncludes",
"(",
"ctx",
",",
"n",
",",
"0",
")",
"\n",
"}"
] |
// InlineIncludes take an expression and resolve any includes so that
// the included expression is "Inline"
|
[
"InlineIncludes",
"take",
"an",
"expression",
"and",
"resolve",
"any",
"includes",
"so",
"that",
"the",
"included",
"expression",
"is",
"Inline"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/include.go#L25-L27
|
20,451
|
araddon/qlbridge
|
plan/plan.go
|
WalkStmt
|
func WalkStmt(ctx *Context, stmt rel.SqlStatement, planner Planner) (Task, error) {
var p Task
base := NewPlanBase(false)
switch st := stmt.(type) {
case *rel.SqlSelect:
p = &Select{Stmt: st, PlanBase: base, Ctx: ctx}
case *rel.SqlInsert:
p = &Insert{Stmt: st, PlanBase: base}
case *rel.SqlUpsert:
p = &Upsert{Stmt: st, PlanBase: base}
case *rel.SqlUpdate:
p = &Update{Stmt: st, PlanBase: base}
case *rel.SqlDelete:
p = &Delete{Stmt: st, PlanBase: base}
case *rel.SqlShow:
sel, err := RewriteShowAsSelect(st, ctx)
if err != nil {
return nil, err
}
ctx.Stmt = sel
p = &Select{Stmt: sel, PlanBase: base, Ctx: ctx}
case *rel.SqlDescribe:
sel, err := RewriteDescribeAsSelect(st, ctx)
if err != nil {
return nil, err
}
ctx.Stmt = sel
p = &Select{Stmt: sel, PlanBase: base}
case *rel.PreparedStatement:
p = &PreparedStatement{Stmt: st, PlanBase: base}
case *rel.SqlCommand:
p = &Command{Stmt: st, PlanBase: base, Ctx: ctx}
case *rel.SqlCreate:
p = &Create{Stmt: st, PlanBase: base, Ctx: ctx}
case *rel.SqlDrop:
p = &Drop{Stmt: st, PlanBase: base, Ctx: ctx}
case *rel.SqlAlter:
p = &Alter{Stmt: st, PlanBase: base, Ctx: ctx}
default:
panic(fmt.Sprintf("Not implemented for %T", stmt))
}
return p, p.Walk(planner)
}
|
go
|
func WalkStmt(ctx *Context, stmt rel.SqlStatement, planner Planner) (Task, error) {
var p Task
base := NewPlanBase(false)
switch st := stmt.(type) {
case *rel.SqlSelect:
p = &Select{Stmt: st, PlanBase: base, Ctx: ctx}
case *rel.SqlInsert:
p = &Insert{Stmt: st, PlanBase: base}
case *rel.SqlUpsert:
p = &Upsert{Stmt: st, PlanBase: base}
case *rel.SqlUpdate:
p = &Update{Stmt: st, PlanBase: base}
case *rel.SqlDelete:
p = &Delete{Stmt: st, PlanBase: base}
case *rel.SqlShow:
sel, err := RewriteShowAsSelect(st, ctx)
if err != nil {
return nil, err
}
ctx.Stmt = sel
p = &Select{Stmt: sel, PlanBase: base, Ctx: ctx}
case *rel.SqlDescribe:
sel, err := RewriteDescribeAsSelect(st, ctx)
if err != nil {
return nil, err
}
ctx.Stmt = sel
p = &Select{Stmt: sel, PlanBase: base}
case *rel.PreparedStatement:
p = &PreparedStatement{Stmt: st, PlanBase: base}
case *rel.SqlCommand:
p = &Command{Stmt: st, PlanBase: base, Ctx: ctx}
case *rel.SqlCreate:
p = &Create{Stmt: st, PlanBase: base, Ctx: ctx}
case *rel.SqlDrop:
p = &Drop{Stmt: st, PlanBase: base, Ctx: ctx}
case *rel.SqlAlter:
p = &Alter{Stmt: st, PlanBase: base, Ctx: ctx}
default:
panic(fmt.Sprintf("Not implemented for %T", stmt))
}
return p, p.Walk(planner)
}
|
[
"func",
"WalkStmt",
"(",
"ctx",
"*",
"Context",
",",
"stmt",
"rel",
".",
"SqlStatement",
",",
"planner",
"Planner",
")",
"(",
"Task",
",",
"error",
")",
"{",
"var",
"p",
"Task",
"\n",
"base",
":=",
"NewPlanBase",
"(",
"false",
")",
"\n",
"switch",
"st",
":=",
"stmt",
".",
"(",
"type",
")",
"{",
"case",
"*",
"rel",
".",
"SqlSelect",
":",
"p",
"=",
"&",
"Select",
"{",
"Stmt",
":",
"st",
",",
"PlanBase",
":",
"base",
",",
"Ctx",
":",
"ctx",
"}",
"\n",
"case",
"*",
"rel",
".",
"SqlInsert",
":",
"p",
"=",
"&",
"Insert",
"{",
"Stmt",
":",
"st",
",",
"PlanBase",
":",
"base",
"}",
"\n",
"case",
"*",
"rel",
".",
"SqlUpsert",
":",
"p",
"=",
"&",
"Upsert",
"{",
"Stmt",
":",
"st",
",",
"PlanBase",
":",
"base",
"}",
"\n",
"case",
"*",
"rel",
".",
"SqlUpdate",
":",
"p",
"=",
"&",
"Update",
"{",
"Stmt",
":",
"st",
",",
"PlanBase",
":",
"base",
"}",
"\n",
"case",
"*",
"rel",
".",
"SqlDelete",
":",
"p",
"=",
"&",
"Delete",
"{",
"Stmt",
":",
"st",
",",
"PlanBase",
":",
"base",
"}",
"\n",
"case",
"*",
"rel",
".",
"SqlShow",
":",
"sel",
",",
"err",
":=",
"RewriteShowAsSelect",
"(",
"st",
",",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ctx",
".",
"Stmt",
"=",
"sel",
"\n",
"p",
"=",
"&",
"Select",
"{",
"Stmt",
":",
"sel",
",",
"PlanBase",
":",
"base",
",",
"Ctx",
":",
"ctx",
"}",
"\n",
"case",
"*",
"rel",
".",
"SqlDescribe",
":",
"sel",
",",
"err",
":=",
"RewriteDescribeAsSelect",
"(",
"st",
",",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ctx",
".",
"Stmt",
"=",
"sel",
"\n",
"p",
"=",
"&",
"Select",
"{",
"Stmt",
":",
"sel",
",",
"PlanBase",
":",
"base",
"}",
"\n",
"case",
"*",
"rel",
".",
"PreparedStatement",
":",
"p",
"=",
"&",
"PreparedStatement",
"{",
"Stmt",
":",
"st",
",",
"PlanBase",
":",
"base",
"}",
"\n",
"case",
"*",
"rel",
".",
"SqlCommand",
":",
"p",
"=",
"&",
"Command",
"{",
"Stmt",
":",
"st",
",",
"PlanBase",
":",
"base",
",",
"Ctx",
":",
"ctx",
"}",
"\n",
"case",
"*",
"rel",
".",
"SqlCreate",
":",
"p",
"=",
"&",
"Create",
"{",
"Stmt",
":",
"st",
",",
"PlanBase",
":",
"base",
",",
"Ctx",
":",
"ctx",
"}",
"\n",
"case",
"*",
"rel",
".",
"SqlDrop",
":",
"p",
"=",
"&",
"Drop",
"{",
"Stmt",
":",
"st",
",",
"PlanBase",
":",
"base",
",",
"Ctx",
":",
"ctx",
"}",
"\n",
"case",
"*",
"rel",
".",
"SqlAlter",
":",
"p",
"=",
"&",
"Alter",
"{",
"Stmt",
":",
"st",
",",
"PlanBase",
":",
"base",
",",
"Ctx",
":",
"ctx",
"}",
"\n",
"default",
":",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"stmt",
")",
")",
"\n",
"}",
"\n",
"return",
"p",
",",
"p",
".",
"Walk",
"(",
"planner",
")",
"\n",
"}"
] |
// WalkStmt Walk given statement for given Planner to produce a query plan
// which is a plan.Task and children, ie a DAG of tasks
|
[
"WalkStmt",
"Walk",
"given",
"statement",
"for",
"given",
"Planner",
"to",
"produce",
"a",
"query",
"plan",
"which",
"is",
"a",
"plan",
".",
"Task",
"and",
"children",
"ie",
"a",
"DAG",
"of",
"tasks"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L272-L314
|
20,452
|
araddon/qlbridge
|
plan/plan.go
|
SelectPlanFromPbBytes
|
func SelectPlanFromPbBytes(pb []byte, loader SchemaLoader) (*Select, error) {
p := &PlanPb{}
if err := proto.Unmarshal(pb, p); err != nil {
u.Errorf("error reading protobuf select: %v \n%s", err, pb)
return nil, err
}
switch {
case p.Select != nil:
return SelectFromPB(p, loader)
}
return nil, ErrNotImplemented
}
|
go
|
func SelectPlanFromPbBytes(pb []byte, loader SchemaLoader) (*Select, error) {
p := &PlanPb{}
if err := proto.Unmarshal(pb, p); err != nil {
u.Errorf("error reading protobuf select: %v \n%s", err, pb)
return nil, err
}
switch {
case p.Select != nil:
return SelectFromPB(p, loader)
}
return nil, ErrNotImplemented
}
|
[
"func",
"SelectPlanFromPbBytes",
"(",
"pb",
"[",
"]",
"byte",
",",
"loader",
"SchemaLoader",
")",
"(",
"*",
"Select",
",",
"error",
")",
"{",
"p",
":=",
"&",
"PlanPb",
"{",
"}",
"\n",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"pb",
",",
"p",
")",
";",
"err",
"!=",
"nil",
"{",
"u",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
",",
"pb",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"switch",
"{",
"case",
"p",
".",
"Select",
"!=",
"nil",
":",
"return",
"SelectFromPB",
"(",
"p",
",",
"loader",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrNotImplemented",
"\n",
"}"
] |
// SelectPlanFromPbBytes Create a sql plan from pb.
|
[
"SelectPlanFromPbBytes",
"Create",
"a",
"sql",
"plan",
"from",
"pb",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L317-L328
|
20,453
|
araddon/qlbridge
|
plan/plan.go
|
SelectTaskFromTaskPb
|
func SelectTaskFromTaskPb(pb *PlanPb, ctx *Context, sel *rel.SqlSelect) (Task, error) {
switch {
case pb.Source != nil:
return SourceFromPB(pb, ctx)
case pb.Where != nil:
return WhereFromPB(pb), nil
case pb.Having != nil:
return HavingFromPB(pb), nil
case pb.GroupBy != nil:
return GroupByFromPB(pb), nil
case pb.Order != nil:
return OrderFromPB(pb), nil
case pb.Projection != nil:
return ProjectionFromPB(pb, sel), nil
case pb.JoinMerge != nil:
u.Warnf("JoinMerge not implemented: %T", pb)
case pb.JoinKey != nil:
u.Warnf("JoinKey not implemented: %T", pb)
default:
u.Warnf("not implemented: %#v", pb)
}
return nil, ErrNotImplemented
}
|
go
|
func SelectTaskFromTaskPb(pb *PlanPb, ctx *Context, sel *rel.SqlSelect) (Task, error) {
switch {
case pb.Source != nil:
return SourceFromPB(pb, ctx)
case pb.Where != nil:
return WhereFromPB(pb), nil
case pb.Having != nil:
return HavingFromPB(pb), nil
case pb.GroupBy != nil:
return GroupByFromPB(pb), nil
case pb.Order != nil:
return OrderFromPB(pb), nil
case pb.Projection != nil:
return ProjectionFromPB(pb, sel), nil
case pb.JoinMerge != nil:
u.Warnf("JoinMerge not implemented: %T", pb)
case pb.JoinKey != nil:
u.Warnf("JoinKey not implemented: %T", pb)
default:
u.Warnf("not implemented: %#v", pb)
}
return nil, ErrNotImplemented
}
|
[
"func",
"SelectTaskFromTaskPb",
"(",
"pb",
"*",
"PlanPb",
",",
"ctx",
"*",
"Context",
",",
"sel",
"*",
"rel",
".",
"SqlSelect",
")",
"(",
"Task",
",",
"error",
")",
"{",
"switch",
"{",
"case",
"pb",
".",
"Source",
"!=",
"nil",
":",
"return",
"SourceFromPB",
"(",
"pb",
",",
"ctx",
")",
"\n",
"case",
"pb",
".",
"Where",
"!=",
"nil",
":",
"return",
"WhereFromPB",
"(",
"pb",
")",
",",
"nil",
"\n",
"case",
"pb",
".",
"Having",
"!=",
"nil",
":",
"return",
"HavingFromPB",
"(",
"pb",
")",
",",
"nil",
"\n",
"case",
"pb",
".",
"GroupBy",
"!=",
"nil",
":",
"return",
"GroupByFromPB",
"(",
"pb",
")",
",",
"nil",
"\n",
"case",
"pb",
".",
"Order",
"!=",
"nil",
":",
"return",
"OrderFromPB",
"(",
"pb",
")",
",",
"nil",
"\n",
"case",
"pb",
".",
"Projection",
"!=",
"nil",
":",
"return",
"ProjectionFromPB",
"(",
"pb",
",",
"sel",
")",
",",
"nil",
"\n",
"case",
"pb",
".",
"JoinMerge",
"!=",
"nil",
":",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"pb",
")",
"\n",
"case",
"pb",
".",
"JoinKey",
"!=",
"nil",
":",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"pb",
")",
"\n",
"default",
":",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"pb",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrNotImplemented",
"\n",
"}"
] |
// SelectTaskFromTaskPb create plan task for SqlSelect from pb.
|
[
"SelectTaskFromTaskPb",
"create",
"plan",
"task",
"for",
"SqlSelect",
"from",
"pb",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L331-L353
|
20,454
|
araddon/qlbridge
|
plan/plan.go
|
NewCreate
|
func NewCreate(ctx *Context, stmt *rel.SqlCreate) *Create {
return &Create{Stmt: stmt, PlanBase: NewPlanBase(false), Ctx: ctx}
}
|
go
|
func NewCreate(ctx *Context, stmt *rel.SqlCreate) *Create {
return &Create{Stmt: stmt, PlanBase: NewPlanBase(false), Ctx: ctx}
}
|
[
"func",
"NewCreate",
"(",
"ctx",
"*",
"Context",
",",
"stmt",
"*",
"rel",
".",
"SqlCreate",
")",
"*",
"Create",
"{",
"return",
"&",
"Create",
"{",
"Stmt",
":",
"stmt",
",",
"PlanBase",
":",
"NewPlanBase",
"(",
"false",
")",
",",
"Ctx",
":",
"ctx",
"}",
"\n",
"}"
] |
// NewCreate creates a new Create Task plan.
|
[
"NewCreate",
"creates",
"a",
"new",
"Create",
"Task",
"plan",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L418-L420
|
20,455
|
araddon/qlbridge
|
plan/plan.go
|
NewDrop
|
func NewDrop(ctx *Context, stmt *rel.SqlDrop) *Drop {
return &Drop{Stmt: stmt, PlanBase: NewPlanBase(false), Ctx: ctx}
}
|
go
|
func NewDrop(ctx *Context, stmt *rel.SqlDrop) *Drop {
return &Drop{Stmt: stmt, PlanBase: NewPlanBase(false), Ctx: ctx}
}
|
[
"func",
"NewDrop",
"(",
"ctx",
"*",
"Context",
",",
"stmt",
"*",
"rel",
".",
"SqlDrop",
")",
"*",
"Drop",
"{",
"return",
"&",
"Drop",
"{",
"Stmt",
":",
"stmt",
",",
"PlanBase",
":",
"NewPlanBase",
"(",
"false",
")",
",",
"Ctx",
":",
"ctx",
"}",
"\n",
"}"
] |
// NewDrop create Drop plan task.
|
[
"NewDrop",
"create",
"Drop",
"plan",
"task",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L423-L425
|
20,456
|
araddon/qlbridge
|
plan/plan.go
|
NewAlter
|
func NewAlter(ctx *Context, stmt *rel.SqlAlter) *Alter {
return &Alter{Stmt: stmt, PlanBase: NewPlanBase(false), Ctx: ctx}
}
|
go
|
func NewAlter(ctx *Context, stmt *rel.SqlAlter) *Alter {
return &Alter{Stmt: stmt, PlanBase: NewPlanBase(false), Ctx: ctx}
}
|
[
"func",
"NewAlter",
"(",
"ctx",
"*",
"Context",
",",
"stmt",
"*",
"rel",
".",
"SqlAlter",
")",
"*",
"Alter",
"{",
"return",
"&",
"Alter",
"{",
"Stmt",
":",
"stmt",
",",
"PlanBase",
":",
"NewPlanBase",
"(",
"false",
")",
",",
"Ctx",
":",
"ctx",
"}",
"\n",
"}"
] |
// NewAlter create Alter plan task.
|
[
"NewAlter",
"create",
"Alter",
"plan",
"task",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L428-L430
|
20,457
|
araddon/qlbridge
|
plan/plan.go
|
NewSource
|
func NewSource(ctx *Context, stmt *rel.SqlSource, isFinal bool) (*Source, error) {
s := &Source{Stmt: stmt, ctx: ctx, SourcePb: &SourcePb{Final: isFinal}, PlanBase: NewPlanBase(false)}
err := s.load()
if err != nil {
return nil, err
}
return s, nil
}
|
go
|
func NewSource(ctx *Context, stmt *rel.SqlSource, isFinal bool) (*Source, error) {
s := &Source{Stmt: stmt, ctx: ctx, SourcePb: &SourcePb{Final: isFinal}, PlanBase: NewPlanBase(false)}
err := s.load()
if err != nil {
return nil, err
}
return s, nil
}
|
[
"func",
"NewSource",
"(",
"ctx",
"*",
"Context",
",",
"stmt",
"*",
"rel",
".",
"SqlSource",
",",
"isFinal",
"bool",
")",
"(",
"*",
"Source",
",",
"error",
")",
"{",
"s",
":=",
"&",
"Source",
"{",
"Stmt",
":",
"stmt",
",",
"ctx",
":",
"ctx",
",",
"SourcePb",
":",
"&",
"SourcePb",
"{",
"Final",
":",
"isFinal",
"}",
",",
"PlanBase",
":",
"NewPlanBase",
"(",
"false",
")",
"}",
"\n",
"err",
":=",
"s",
".",
"load",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"s",
",",
"nil",
"\n",
"}"
] |
// NewSource create a new plan Task for data source
|
[
"NewSource",
"create",
"a",
"new",
"plan",
"Task",
"for",
"data",
"source"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L625-L632
|
20,458
|
araddon/qlbridge
|
plan/plan.go
|
Equal
|
func (m *Projection) Equal(t Task) bool {
if m == nil && t == nil {
return true
}
if m == nil && t != nil {
return false
}
if m != nil && t == nil {
return false
}
s, ok := t.(*Projection)
if !ok {
return false
}
if m.Final != s.Final {
return false
}
if !m.Proj.Equal(s.Proj) {
return false
}
if !m.PlanBase.EqualBase(s.PlanBase) {
return false
}
return true
}
|
go
|
func (m *Projection) Equal(t Task) bool {
if m == nil && t == nil {
return true
}
if m == nil && t != nil {
return false
}
if m != nil && t == nil {
return false
}
s, ok := t.(*Projection)
if !ok {
return false
}
if m.Final != s.Final {
return false
}
if !m.Proj.Equal(s.Proj) {
return false
}
if !m.PlanBase.EqualBase(s.PlanBase) {
return false
}
return true
}
|
[
"func",
"(",
"m",
"*",
"Projection",
")",
"Equal",
"(",
"t",
"Task",
")",
"bool",
"{",
"if",
"m",
"==",
"nil",
"&&",
"t",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"m",
"==",
"nil",
"&&",
"t",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"m",
"!=",
"nil",
"&&",
"t",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"s",
",",
"ok",
":=",
"t",
".",
"(",
"*",
"Projection",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"m",
".",
"Final",
"!=",
"s",
".",
"Final",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"m",
".",
"Proj",
".",
"Equal",
"(",
"s",
".",
"Proj",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"m",
".",
"PlanBase",
".",
"EqualBase",
"(",
"s",
".",
"PlanBase",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// Equal checks if two tasks are equal.
|
[
"Equal",
"checks",
"if",
"two",
"tasks",
"are",
"equal",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L792-L816
|
20,459
|
araddon/qlbridge
|
plan/plan.go
|
ToPb
|
func (m *Projection) ToPb() (*PlanPb, error) {
pbp, err := m.PlanBase.ToPb()
if err != nil {
return nil, err
}
ppbptr := m.Proj.ToPB()
ppcpy := *ppbptr
ppcpy.Final = m.Final
pbp.Projection = &ppcpy
return pbp, nil
}
|
go
|
func (m *Projection) ToPb() (*PlanPb, error) {
pbp, err := m.PlanBase.ToPb()
if err != nil {
return nil, err
}
ppbptr := m.Proj.ToPB()
ppcpy := *ppbptr
ppcpy.Final = m.Final
pbp.Projection = &ppcpy
return pbp, nil
}
|
[
"func",
"(",
"m",
"*",
"Projection",
")",
"ToPb",
"(",
")",
"(",
"*",
"PlanPb",
",",
"error",
")",
"{",
"pbp",
",",
"err",
":=",
"m",
".",
"PlanBase",
".",
"ToPb",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ppbptr",
":=",
"m",
".",
"Proj",
".",
"ToPB",
"(",
")",
"\n",
"ppcpy",
":=",
"*",
"ppbptr",
"\n",
"ppcpy",
".",
"Final",
"=",
"m",
".",
"Final",
"\n",
"pbp",
".",
"Projection",
"=",
"&",
"ppcpy",
"\n",
"return",
"pbp",
",",
"nil",
"\n",
"}"
] |
// ToPb to protobuf.
|
[
"ToPb",
"to",
"protobuf",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L819-L829
|
20,460
|
araddon/qlbridge
|
plan/plan.go
|
ProjectionFromPB
|
func ProjectionFromPB(pb *PlanPb, sel *rel.SqlSelect) *Projection {
m := Projection{
Proj: rel.ProjectionFromPb(pb.Projection),
}
m.Final = pb.Projection.Final
m.PlanBase = NewPlanBase(pb.Parallel)
m.Stmt = sel
return &m
}
|
go
|
func ProjectionFromPB(pb *PlanPb, sel *rel.SqlSelect) *Projection {
m := Projection{
Proj: rel.ProjectionFromPb(pb.Projection),
}
m.Final = pb.Projection.Final
m.PlanBase = NewPlanBase(pb.Parallel)
m.Stmt = sel
return &m
}
|
[
"func",
"ProjectionFromPB",
"(",
"pb",
"*",
"PlanPb",
",",
"sel",
"*",
"rel",
".",
"SqlSelect",
")",
"*",
"Projection",
"{",
"m",
":=",
"Projection",
"{",
"Proj",
":",
"rel",
".",
"ProjectionFromPb",
"(",
"pb",
".",
"Projection",
")",
",",
"}",
"\n",
"m",
".",
"Final",
"=",
"pb",
".",
"Projection",
".",
"Final",
"\n",
"m",
".",
"PlanBase",
"=",
"NewPlanBase",
"(",
"pb",
".",
"Parallel",
")",
"\n",
"m",
".",
"Stmt",
"=",
"sel",
"\n",
"return",
"&",
"m",
"\n",
"}"
] |
// ProjectionFromPB create Projection from Protobuf.
|
[
"ProjectionFromPB",
"create",
"Projection",
"from",
"Protobuf",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L832-L840
|
20,461
|
araddon/qlbridge
|
plan/plan.go
|
NewJoinKey
|
func NewJoinKey(s *Source) *JoinKey {
return &JoinKey{Source: s, PlanBase: NewPlanBase(false)}
}
|
go
|
func NewJoinKey(s *Source) *JoinKey {
return &JoinKey{Source: s, PlanBase: NewPlanBase(false)}
}
|
[
"func",
"NewJoinKey",
"(",
"s",
"*",
"Source",
")",
"*",
"JoinKey",
"{",
"return",
"&",
"JoinKey",
"{",
"Source",
":",
"s",
",",
"PlanBase",
":",
"NewPlanBase",
"(",
"false",
")",
"}",
"\n",
"}"
] |
// NewJoinKey creates JoinKey from Source.
|
[
"NewJoinKey",
"creates",
"JoinKey",
"from",
"Source",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L880-L882
|
20,462
|
araddon/qlbridge
|
plan/plan.go
|
NewWhere
|
func NewWhere(stmt *rel.SqlSelect) *Where {
return &Where{Stmt: stmt, PlanBase: NewPlanBase(false)}
}
|
go
|
func NewWhere(stmt *rel.SqlSelect) *Where {
return &Where{Stmt: stmt, PlanBase: NewPlanBase(false)}
}
|
[
"func",
"NewWhere",
"(",
"stmt",
"*",
"rel",
".",
"SqlSelect",
")",
"*",
"Where",
"{",
"return",
"&",
"Where",
"{",
"Stmt",
":",
"stmt",
",",
"PlanBase",
":",
"NewPlanBase",
"(",
"false",
")",
"}",
"\n",
"}"
] |
// NewWhere new Where Task from SqlSelect statement.
|
[
"NewWhere",
"new",
"Where",
"Task",
"from",
"SqlSelect",
"statement",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L885-L887
|
20,463
|
araddon/qlbridge
|
plan/plan.go
|
NewWhereFinal
|
func NewWhereFinal(stmt *rel.SqlSelect) *Where {
return &Where{Stmt: stmt, Final: true, PlanBase: NewPlanBase(false)}
}
|
go
|
func NewWhereFinal(stmt *rel.SqlSelect) *Where {
return &Where{Stmt: stmt, Final: true, PlanBase: NewPlanBase(false)}
}
|
[
"func",
"NewWhereFinal",
"(",
"stmt",
"*",
"rel",
".",
"SqlSelect",
")",
"*",
"Where",
"{",
"return",
"&",
"Where",
"{",
"Stmt",
":",
"stmt",
",",
"Final",
":",
"true",
",",
"PlanBase",
":",
"NewPlanBase",
"(",
"false",
")",
"}",
"\n",
"}"
] |
// NewWhereFinal from SqlSelect statement.
|
[
"NewWhereFinal",
"from",
"SqlSelect",
"statement",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L890-L892
|
20,464
|
araddon/qlbridge
|
plan/plan.go
|
NewHaving
|
func NewHaving(stmt *rel.SqlSelect) *Having {
return &Having{Stmt: stmt, PlanBase: NewPlanBase(false)}
}
|
go
|
func NewHaving(stmt *rel.SqlSelect) *Having {
return &Having{Stmt: stmt, PlanBase: NewPlanBase(false)}
}
|
[
"func",
"NewHaving",
"(",
"stmt",
"*",
"rel",
".",
"SqlSelect",
")",
"*",
"Having",
"{",
"return",
"&",
"Having",
"{",
"Stmt",
":",
"stmt",
",",
"PlanBase",
":",
"NewPlanBase",
"(",
"false",
")",
"}",
"\n",
"}"
] |
// NewHaving from SqlSelect statement.
|
[
"NewHaving",
"from",
"SqlSelect",
"statement",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L895-L897
|
20,465
|
araddon/qlbridge
|
plan/plan.go
|
NewGroupBy
|
func NewGroupBy(stmt *rel.SqlSelect) *GroupBy {
return &GroupBy{Stmt: stmt, PlanBase: NewPlanBase(false)}
}
|
go
|
func NewGroupBy(stmt *rel.SqlSelect) *GroupBy {
return &GroupBy{Stmt: stmt, PlanBase: NewPlanBase(false)}
}
|
[
"func",
"NewGroupBy",
"(",
"stmt",
"*",
"rel",
".",
"SqlSelect",
")",
"*",
"GroupBy",
"{",
"return",
"&",
"GroupBy",
"{",
"Stmt",
":",
"stmt",
",",
"PlanBase",
":",
"NewPlanBase",
"(",
"false",
")",
"}",
"\n",
"}"
] |
// NewGroupBy from SqlSelect statement.
|
[
"NewGroupBy",
"from",
"SqlSelect",
"statement",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L900-L902
|
20,466
|
araddon/qlbridge
|
plan/plan.go
|
NewOrder
|
func NewOrder(stmt *rel.SqlSelect) *Order {
return &Order{Stmt: stmt, PlanBase: NewPlanBase(false)}
}
|
go
|
func NewOrder(stmt *rel.SqlSelect) *Order {
return &Order{Stmt: stmt, PlanBase: NewPlanBase(false)}
}
|
[
"func",
"NewOrder",
"(",
"stmt",
"*",
"rel",
".",
"SqlSelect",
")",
"*",
"Order",
"{",
"return",
"&",
"Order",
"{",
"Stmt",
":",
"stmt",
",",
"PlanBase",
":",
"NewPlanBase",
"(",
"false",
")",
"}",
"\n",
"}"
] |
// NewOrder from SqlSelect statement.
|
[
"NewOrder",
"from",
"SqlSelect",
"statement",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L905-L907
|
20,467
|
araddon/qlbridge
|
plan/plan.go
|
Equal
|
func (m *Into) Equal(t Task) bool {
if m == nil && t == nil {
return true
}
if m == nil && t != nil {
return false
}
if m != nil && t == nil {
return false
}
s, ok := t.(*Into)
if !ok {
return false
}
if !m.PlanBase.EqualBase(s.PlanBase) {
return false
}
return true
}
|
go
|
func (m *Into) Equal(t Task) bool {
if m == nil && t == nil {
return true
}
if m == nil && t != nil {
return false
}
if m != nil && t == nil {
return false
}
s, ok := t.(*Into)
if !ok {
return false
}
if !m.PlanBase.EqualBase(s.PlanBase) {
return false
}
return true
}
|
[
"func",
"(",
"m",
"*",
"Into",
")",
"Equal",
"(",
"t",
"Task",
")",
"bool",
"{",
"if",
"m",
"==",
"nil",
"&&",
"t",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"m",
"==",
"nil",
"&&",
"t",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"m",
"!=",
"nil",
"&&",
"t",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"s",
",",
"ok",
":=",
"t",
".",
"(",
"*",
"Into",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"!",
"m",
".",
"PlanBase",
".",
"EqualBase",
"(",
"s",
".",
"PlanBase",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// Equal compares equality of two tasks.
|
[
"Equal",
"compares",
"equality",
"of",
"two",
"tasks",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/plan.go#L910-L929
|
20,468
|
araddon/qlbridge
|
datasource/sqlite/sqlrewrite.go
|
rewrite
|
func (m *rewrite) rewrite() (string, error) {
var err error
if m.sel.Where != nil {
m.result.Where = m.sel.Where
m.result.Where.Expr, err = m.walkNode(m.sel.Where.Expr)
if err != nil {
return "", err
}
}
// Evaluate the Select columns make sure we can pass them down or polyfill
err = m.walkSelectList()
if err != nil {
u.Warnf("Could Not evaluate Columns/Aggs %s %v", m.sel.Columns.String(), err)
return "", err
}
m.result.From = m.sel.From
if len(m.sel.GroupBy) > 0 {
err = m.walkGroupBy()
if err != nil {
u.Warnf("Could Not evaluate GroupBys %s %v", m.sel.GroupBy.String(), err)
return "", err
}
}
if len(m.sel.OrderBy) > 0 {
// this should be same right?
m.result.OrderBy = m.sel.OrderBy
}
return m.result.String(), nil
}
|
go
|
func (m *rewrite) rewrite() (string, error) {
var err error
if m.sel.Where != nil {
m.result.Where = m.sel.Where
m.result.Where.Expr, err = m.walkNode(m.sel.Where.Expr)
if err != nil {
return "", err
}
}
// Evaluate the Select columns make sure we can pass them down or polyfill
err = m.walkSelectList()
if err != nil {
u.Warnf("Could Not evaluate Columns/Aggs %s %v", m.sel.Columns.String(), err)
return "", err
}
m.result.From = m.sel.From
if len(m.sel.GroupBy) > 0 {
err = m.walkGroupBy()
if err != nil {
u.Warnf("Could Not evaluate GroupBys %s %v", m.sel.GroupBy.String(), err)
return "", err
}
}
if len(m.sel.OrderBy) > 0 {
// this should be same right?
m.result.OrderBy = m.sel.OrderBy
}
return m.result.String(), nil
}
|
[
"func",
"(",
"m",
"*",
"rewrite",
")",
"rewrite",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"if",
"m",
".",
"sel",
".",
"Where",
"!=",
"nil",
"{",
"m",
".",
"result",
".",
"Where",
"=",
"m",
".",
"sel",
".",
"Where",
"\n",
"m",
".",
"result",
".",
"Where",
".",
"Expr",
",",
"err",
"=",
"m",
".",
"walkNode",
"(",
"m",
".",
"sel",
".",
"Where",
".",
"Expr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Evaluate the Select columns make sure we can pass them down or polyfill",
"err",
"=",
"m",
".",
"walkSelectList",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"m",
".",
"sel",
".",
"Columns",
".",
"String",
"(",
")",
",",
"err",
")",
"\n",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"m",
".",
"result",
".",
"From",
"=",
"m",
".",
"sel",
".",
"From",
"\n\n",
"if",
"len",
"(",
"m",
".",
"sel",
".",
"GroupBy",
")",
">",
"0",
"{",
"err",
"=",
"m",
".",
"walkGroupBy",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"m",
".",
"sel",
".",
"GroupBy",
".",
"String",
"(",
")",
",",
"err",
")",
"\n",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"m",
".",
"sel",
".",
"OrderBy",
")",
">",
"0",
"{",
"// this should be same right?",
"m",
".",
"result",
".",
"OrderBy",
"=",
"m",
".",
"sel",
".",
"OrderBy",
"\n",
"}",
"\n\n",
"return",
"m",
".",
"result",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// WalkSourceSelect An interface implemented by this connection allowing the planner
// to push down as much logic into mongo as possible
|
[
"WalkSourceSelect",
"An",
"interface",
"implemented",
"by",
"this",
"connection",
"allowing",
"the",
"planner",
"to",
"push",
"down",
"as",
"much",
"logic",
"into",
"mongo",
"as",
"possible"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/datasource/sqlite/sqlrewrite.go#L32-L66
|
20,469
|
araddon/qlbridge
|
rel/sql_rewrite.go
|
RewriteSelect
|
func RewriteSelect(m *SqlSelect) {
originalCols := m.Columns
m.Columns = make(Columns, 0, len(originalCols)+5)
rewriteIntoProjection(m, originalCols)
rewriteIntoProjection(m, m.GroupBy)
if m.Where != nil {
colsToAdd := expr.FindAllIdentityField(m.Where.Expr)
addIntoProjection(m, colsToAdd)
}
rewriteIntoProjection(m, m.OrderBy)
}
|
go
|
func RewriteSelect(m *SqlSelect) {
originalCols := m.Columns
m.Columns = make(Columns, 0, len(originalCols)+5)
rewriteIntoProjection(m, originalCols)
rewriteIntoProjection(m, m.GroupBy)
if m.Where != nil {
colsToAdd := expr.FindAllIdentityField(m.Where.Expr)
addIntoProjection(m, colsToAdd)
}
rewriteIntoProjection(m, m.OrderBy)
}
|
[
"func",
"RewriteSelect",
"(",
"m",
"*",
"SqlSelect",
")",
"{",
"originalCols",
":=",
"m",
".",
"Columns",
"\n",
"m",
".",
"Columns",
"=",
"make",
"(",
"Columns",
",",
"0",
",",
"len",
"(",
"originalCols",
")",
"+",
"5",
")",
"\n",
"rewriteIntoProjection",
"(",
"m",
",",
"originalCols",
")",
"\n",
"rewriteIntoProjection",
"(",
"m",
",",
"m",
".",
"GroupBy",
")",
"\n",
"if",
"m",
".",
"Where",
"!=",
"nil",
"{",
"colsToAdd",
":=",
"expr",
".",
"FindAllIdentityField",
"(",
"m",
".",
"Where",
".",
"Expr",
")",
"\n",
"addIntoProjection",
"(",
"m",
",",
"colsToAdd",
")",
"\n",
"}",
"\n",
"rewriteIntoProjection",
"(",
"m",
",",
"m",
".",
"OrderBy",
")",
"\n",
"}"
] |
// RewriteSelect We are removing Column Aliases "user_id as uid"
// as well as functions - used when we are going to defer projection, aggs
|
[
"RewriteSelect",
"We",
"are",
"removing",
"Column",
"Aliases",
"user_id",
"as",
"uid",
"as",
"well",
"as",
"functions",
"-",
"used",
"when",
"we",
"are",
"going",
"to",
"defer",
"projection",
"aggs"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/rel/sql_rewrite.go#L13-L23
|
20,470
|
araddon/qlbridge
|
rel/sql_rewrite.go
|
RewriteSqlSource
|
func RewriteSqlSource(m *SqlSource, parentStmt *SqlSelect) *SqlSelect {
if m.Source != nil {
return m.Source
}
// Rewrite this SqlSource for the given parent, ie
// 1) find the column names we need to request from source including those used in join/where
// 2) rewrite the where for this partial query
// 3) any columns in join expression that are not equal between
// sides should be aliased towards the left-hand join portion
// 4) if we need different sort for our join algo?
newCols := make(Columns, 0)
if !parentStmt.Star {
for idx, col := range parentStmt.Columns {
left, _, hasLeft := col.LeftRight()
if !hasLeft {
// Was not left/right qualified, so use as is? or is this an error?
// what is official sql grammar on this?
newCol := col.Copy()
newCol.ParentIndex = idx
newCol.Index = len(newCols)
newCols = append(newCols, newCol)
} else if hasLeft && left == m.Alias {
newCol := col.CopyRewrite(m.Alias)
newCol.ParentIndex = idx
newCol.SourceIndex = len(newCols)
newCol.Index = len(newCols)
newCols = append(newCols, newCol)
}
}
}
// TODO:
// - rewrite the Sort
// - rewrite the group-by
sql2 := &SqlSelect{Columns: newCols, Star: parentStmt.Star}
m.joinNodes = make([]expr.Node, 0)
if m.SubQuery != nil {
if len(m.SubQuery.From) != 1 {
u.Errorf("Not supported, nested subQuery %v", m.SubQuery.String())
} else {
sql2.From = append(sql2.From, &SqlSource{Name: m.SubQuery.From[0].Name})
}
} else {
sql2.From = append(sql2.From, &SqlSource{Name: m.Name})
}
for _, from := range parentStmt.From {
// We need to check each participant in the Join for possible
// columns which need to be re-written
sql2.Columns = columnsFromJoin(m, from.JoinExpr, sql2.Columns)
// We also need to create an expression used for evaluating
// the values of Join "Keys"
if from.JoinExpr != nil {
joinNodesForFrom(parentStmt, m, from.JoinExpr, 0)
}
}
if parentStmt.Where != nil {
node, cols := rewriteWhere(parentStmt, m, parentStmt.Where.Expr, make(Columns, 0))
if node != nil {
sql2.Where = &SqlWhere{Expr: node}
}
if len(cols) > 0 {
parentIdx := len(parentStmt.Columns)
for _, col := range cols {
col.Index = len(sql2.Columns)
col.ParentIndex = parentIdx
parentIdx++
sql2.Columns = append(sql2.Columns, col)
}
}
}
m.Source = sql2
m.cols = sql2.UnAliasedColumns()
return sql2
}
|
go
|
func RewriteSqlSource(m *SqlSource, parentStmt *SqlSelect) *SqlSelect {
if m.Source != nil {
return m.Source
}
// Rewrite this SqlSource for the given parent, ie
// 1) find the column names we need to request from source including those used in join/where
// 2) rewrite the where for this partial query
// 3) any columns in join expression that are not equal between
// sides should be aliased towards the left-hand join portion
// 4) if we need different sort for our join algo?
newCols := make(Columns, 0)
if !parentStmt.Star {
for idx, col := range parentStmt.Columns {
left, _, hasLeft := col.LeftRight()
if !hasLeft {
// Was not left/right qualified, so use as is? or is this an error?
// what is official sql grammar on this?
newCol := col.Copy()
newCol.ParentIndex = idx
newCol.Index = len(newCols)
newCols = append(newCols, newCol)
} else if hasLeft && left == m.Alias {
newCol := col.CopyRewrite(m.Alias)
newCol.ParentIndex = idx
newCol.SourceIndex = len(newCols)
newCol.Index = len(newCols)
newCols = append(newCols, newCol)
}
}
}
// TODO:
// - rewrite the Sort
// - rewrite the group-by
sql2 := &SqlSelect{Columns: newCols, Star: parentStmt.Star}
m.joinNodes = make([]expr.Node, 0)
if m.SubQuery != nil {
if len(m.SubQuery.From) != 1 {
u.Errorf("Not supported, nested subQuery %v", m.SubQuery.String())
} else {
sql2.From = append(sql2.From, &SqlSource{Name: m.SubQuery.From[0].Name})
}
} else {
sql2.From = append(sql2.From, &SqlSource{Name: m.Name})
}
for _, from := range parentStmt.From {
// We need to check each participant in the Join for possible
// columns which need to be re-written
sql2.Columns = columnsFromJoin(m, from.JoinExpr, sql2.Columns)
// We also need to create an expression used for evaluating
// the values of Join "Keys"
if from.JoinExpr != nil {
joinNodesForFrom(parentStmt, m, from.JoinExpr, 0)
}
}
if parentStmt.Where != nil {
node, cols := rewriteWhere(parentStmt, m, parentStmt.Where.Expr, make(Columns, 0))
if node != nil {
sql2.Where = &SqlWhere{Expr: node}
}
if len(cols) > 0 {
parentIdx := len(parentStmt.Columns)
for _, col := range cols {
col.Index = len(sql2.Columns)
col.ParentIndex = parentIdx
parentIdx++
sql2.Columns = append(sql2.Columns, col)
}
}
}
m.Source = sql2
m.cols = sql2.UnAliasedColumns()
return sql2
}
|
[
"func",
"RewriteSqlSource",
"(",
"m",
"*",
"SqlSource",
",",
"parentStmt",
"*",
"SqlSelect",
")",
"*",
"SqlSelect",
"{",
"if",
"m",
".",
"Source",
"!=",
"nil",
"{",
"return",
"m",
".",
"Source",
"\n",
"}",
"\n",
"// Rewrite this SqlSource for the given parent, ie",
"// 1) find the column names we need to request from source including those used in join/where",
"// 2) rewrite the where for this partial query",
"// 3) any columns in join expression that are not equal between",
"// sides should be aliased towards the left-hand join portion",
"// 4) if we need different sort for our join algo?",
"newCols",
":=",
"make",
"(",
"Columns",
",",
"0",
")",
"\n",
"if",
"!",
"parentStmt",
".",
"Star",
"{",
"for",
"idx",
",",
"col",
":=",
"range",
"parentStmt",
".",
"Columns",
"{",
"left",
",",
"_",
",",
"hasLeft",
":=",
"col",
".",
"LeftRight",
"(",
")",
"\n",
"if",
"!",
"hasLeft",
"{",
"// Was not left/right qualified, so use as is? or is this an error?",
"// what is official sql grammar on this?",
"newCol",
":=",
"col",
".",
"Copy",
"(",
")",
"\n",
"newCol",
".",
"ParentIndex",
"=",
"idx",
"\n",
"newCol",
".",
"Index",
"=",
"len",
"(",
"newCols",
")",
"\n",
"newCols",
"=",
"append",
"(",
"newCols",
",",
"newCol",
")",
"\n\n",
"}",
"else",
"if",
"hasLeft",
"&&",
"left",
"==",
"m",
".",
"Alias",
"{",
"newCol",
":=",
"col",
".",
"CopyRewrite",
"(",
"m",
".",
"Alias",
")",
"\n",
"newCol",
".",
"ParentIndex",
"=",
"idx",
"\n",
"newCol",
".",
"SourceIndex",
"=",
"len",
"(",
"newCols",
")",
"\n",
"newCol",
".",
"Index",
"=",
"len",
"(",
"newCols",
")",
"\n",
"newCols",
"=",
"append",
"(",
"newCols",
",",
"newCol",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// TODO:",
"// - rewrite the Sort",
"// - rewrite the group-by",
"sql2",
":=",
"&",
"SqlSelect",
"{",
"Columns",
":",
"newCols",
",",
"Star",
":",
"parentStmt",
".",
"Star",
"}",
"\n",
"m",
".",
"joinNodes",
"=",
"make",
"(",
"[",
"]",
"expr",
".",
"Node",
",",
"0",
")",
"\n",
"if",
"m",
".",
"SubQuery",
"!=",
"nil",
"{",
"if",
"len",
"(",
"m",
".",
"SubQuery",
".",
"From",
")",
"!=",
"1",
"{",
"u",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
".",
"SubQuery",
".",
"String",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"sql2",
".",
"From",
"=",
"append",
"(",
"sql2",
".",
"From",
",",
"&",
"SqlSource",
"{",
"Name",
":",
"m",
".",
"SubQuery",
".",
"From",
"[",
"0",
"]",
".",
"Name",
"}",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"sql2",
".",
"From",
"=",
"append",
"(",
"sql2",
".",
"From",
",",
"&",
"SqlSource",
"{",
"Name",
":",
"m",
".",
"Name",
"}",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"from",
":=",
"range",
"parentStmt",
".",
"From",
"{",
"// We need to check each participant in the Join for possible",
"// columns which need to be re-written",
"sql2",
".",
"Columns",
"=",
"columnsFromJoin",
"(",
"m",
",",
"from",
".",
"JoinExpr",
",",
"sql2",
".",
"Columns",
")",
"\n\n",
"// We also need to create an expression used for evaluating",
"// the values of Join \"Keys\"",
"if",
"from",
".",
"JoinExpr",
"!=",
"nil",
"{",
"joinNodesForFrom",
"(",
"parentStmt",
",",
"m",
",",
"from",
".",
"JoinExpr",
",",
"0",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"parentStmt",
".",
"Where",
"!=",
"nil",
"{",
"node",
",",
"cols",
":=",
"rewriteWhere",
"(",
"parentStmt",
",",
"m",
",",
"parentStmt",
".",
"Where",
".",
"Expr",
",",
"make",
"(",
"Columns",
",",
"0",
")",
")",
"\n",
"if",
"node",
"!=",
"nil",
"{",
"sql2",
".",
"Where",
"=",
"&",
"SqlWhere",
"{",
"Expr",
":",
"node",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"cols",
")",
">",
"0",
"{",
"parentIdx",
":=",
"len",
"(",
"parentStmt",
".",
"Columns",
")",
"\n",
"for",
"_",
",",
"col",
":=",
"range",
"cols",
"{",
"col",
".",
"Index",
"=",
"len",
"(",
"sql2",
".",
"Columns",
")",
"\n",
"col",
".",
"ParentIndex",
"=",
"parentIdx",
"\n",
"parentIdx",
"++",
"\n",
"sql2",
".",
"Columns",
"=",
"append",
"(",
"sql2",
".",
"Columns",
",",
"col",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"m",
".",
"Source",
"=",
"sql2",
"\n",
"m",
".",
"cols",
"=",
"sql2",
".",
"UnAliasedColumns",
"(",
")",
"\n",
"return",
"sql2",
"\n",
"}"
] |
// RewriteSqlSource this Source to act as a stand-alone query to backend
// @parentStmt = the parent statement that this a partial source to
|
[
"RewriteSqlSource",
"this",
"Source",
"to",
"act",
"as",
"a",
"stand",
"-",
"alone",
"query",
"to",
"backend"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/rel/sql_rewrite.go#L27-L106
|
20,471
|
araddon/qlbridge
|
rel/sql_rewrite.go
|
rewriteNode
|
func rewriteNode(from *SqlSource, node expr.Node) expr.Node {
switch nt := node.(type) {
case *expr.IdentityNode:
if left, right, ok := nt.LeftRight(); ok {
//u.Debugf("rewriteNode from.Name:%v l:%v r:%v", from.alias, left, right)
if left == from.alias {
in := expr.IdentityNode{Text: right}
//u.Warnf("nice, found it! in = %v", in)
return &in
}
}
case *expr.NumberNode, *expr.NullNode, *expr.StringNode, *expr.ValueNode:
//u.Warnf("skipping? %v", nt.String())
return nt
case *expr.BinaryNode:
switch nt.Operator.T {
case lex.TokenAnd, lex.TokenLogicAnd, lex.TokenLogicOr:
n1 := rewriteNode(from, nt.Args[0])
n2 := rewriteNode(from, nt.Args[1])
return &expr.BinaryNode{Operator: nt.Operator, Args: []expr.Node{n1, n2}}
case lex.TokenEqual, lex.TokenEqualEqual:
n := rewriteNode(from, nt.Args[0])
if n != nil {
return n
}
n = rewriteNode(from, nt.Args[1])
if n != nil {
return n
}
u.Warnf("Could not find node: %#v", node)
default:
u.Warnf("un-implemented op: %v", nt.Operator)
}
case *expr.FuncNode:
fn := expr.NewFuncNode(nt.Name, nt.F)
fn.Args = make([]expr.Node, len(nt.Args))
for i, arg := range nt.Args {
fn.Args[i] = rewriteNode(from, arg)
if fn.Args[i] == nil {
// What???
u.Warnf("error, nil node: %s", arg.String())
return nil
}
}
return fn
default:
u.Warnf("%T node types are not suppored yet for column rewrite", node)
}
return nil
}
|
go
|
func rewriteNode(from *SqlSource, node expr.Node) expr.Node {
switch nt := node.(type) {
case *expr.IdentityNode:
if left, right, ok := nt.LeftRight(); ok {
//u.Debugf("rewriteNode from.Name:%v l:%v r:%v", from.alias, left, right)
if left == from.alias {
in := expr.IdentityNode{Text: right}
//u.Warnf("nice, found it! in = %v", in)
return &in
}
}
case *expr.NumberNode, *expr.NullNode, *expr.StringNode, *expr.ValueNode:
//u.Warnf("skipping? %v", nt.String())
return nt
case *expr.BinaryNode:
switch nt.Operator.T {
case lex.TokenAnd, lex.TokenLogicAnd, lex.TokenLogicOr:
n1 := rewriteNode(from, nt.Args[0])
n2 := rewriteNode(from, nt.Args[1])
return &expr.BinaryNode{Operator: nt.Operator, Args: []expr.Node{n1, n2}}
case lex.TokenEqual, lex.TokenEqualEqual:
n := rewriteNode(from, nt.Args[0])
if n != nil {
return n
}
n = rewriteNode(from, nt.Args[1])
if n != nil {
return n
}
u.Warnf("Could not find node: %#v", node)
default:
u.Warnf("un-implemented op: %v", nt.Operator)
}
case *expr.FuncNode:
fn := expr.NewFuncNode(nt.Name, nt.F)
fn.Args = make([]expr.Node, len(nt.Args))
for i, arg := range nt.Args {
fn.Args[i] = rewriteNode(from, arg)
if fn.Args[i] == nil {
// What???
u.Warnf("error, nil node: %s", arg.String())
return nil
}
}
return fn
default:
u.Warnf("%T node types are not suppored yet for column rewrite", node)
}
return nil
}
|
[
"func",
"rewriteNode",
"(",
"from",
"*",
"SqlSource",
",",
"node",
"expr",
".",
"Node",
")",
"expr",
".",
"Node",
"{",
"switch",
"nt",
":=",
"node",
".",
"(",
"type",
")",
"{",
"case",
"*",
"expr",
".",
"IdentityNode",
":",
"if",
"left",
",",
"right",
",",
"ok",
":=",
"nt",
".",
"LeftRight",
"(",
")",
";",
"ok",
"{",
"//u.Debugf(\"rewriteNode from.Name:%v l:%v r:%v\", from.alias, left, right)",
"if",
"left",
"==",
"from",
".",
"alias",
"{",
"in",
":=",
"expr",
".",
"IdentityNode",
"{",
"Text",
":",
"right",
"}",
"\n",
"//u.Warnf(\"nice, found it! in = %v\", in)",
"return",
"&",
"in",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"*",
"expr",
".",
"NumberNode",
",",
"*",
"expr",
".",
"NullNode",
",",
"*",
"expr",
".",
"StringNode",
",",
"*",
"expr",
".",
"ValueNode",
":",
"//u.Warnf(\"skipping? %v\", nt.String())",
"return",
"nt",
"\n",
"case",
"*",
"expr",
".",
"BinaryNode",
":",
"switch",
"nt",
".",
"Operator",
".",
"T",
"{",
"case",
"lex",
".",
"TokenAnd",
",",
"lex",
".",
"TokenLogicAnd",
",",
"lex",
".",
"TokenLogicOr",
":",
"n1",
":=",
"rewriteNode",
"(",
"from",
",",
"nt",
".",
"Args",
"[",
"0",
"]",
")",
"\n",
"n2",
":=",
"rewriteNode",
"(",
"from",
",",
"nt",
".",
"Args",
"[",
"1",
"]",
")",
"\n",
"return",
"&",
"expr",
".",
"BinaryNode",
"{",
"Operator",
":",
"nt",
".",
"Operator",
",",
"Args",
":",
"[",
"]",
"expr",
".",
"Node",
"{",
"n1",
",",
"n2",
"}",
"}",
"\n",
"case",
"lex",
".",
"TokenEqual",
",",
"lex",
".",
"TokenEqualEqual",
":",
"n",
":=",
"rewriteNode",
"(",
"from",
",",
"nt",
".",
"Args",
"[",
"0",
"]",
")",
"\n",
"if",
"n",
"!=",
"nil",
"{",
"return",
"n",
"\n",
"}",
"\n",
"n",
"=",
"rewriteNode",
"(",
"from",
",",
"nt",
".",
"Args",
"[",
"1",
"]",
")",
"\n",
"if",
"n",
"!=",
"nil",
"{",
"return",
"n",
"\n",
"}",
"\n",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"node",
")",
"\n",
"default",
":",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"nt",
".",
"Operator",
")",
"\n",
"}",
"\n",
"case",
"*",
"expr",
".",
"FuncNode",
":",
"fn",
":=",
"expr",
".",
"NewFuncNode",
"(",
"nt",
".",
"Name",
",",
"nt",
".",
"F",
")",
"\n",
"fn",
".",
"Args",
"=",
"make",
"(",
"[",
"]",
"expr",
".",
"Node",
",",
"len",
"(",
"nt",
".",
"Args",
")",
")",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"nt",
".",
"Args",
"{",
"fn",
".",
"Args",
"[",
"i",
"]",
"=",
"rewriteNode",
"(",
"from",
",",
"arg",
")",
"\n",
"if",
"fn",
".",
"Args",
"[",
"i",
"]",
"==",
"nil",
"{",
"// What???",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"arg",
".",
"String",
"(",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"fn",
"\n",
"default",
":",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"node",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Remove any aliases
|
[
"Remove",
"any",
"aliases"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/rel/sql_rewrite.go#L378-L427
|
20,472
|
araddon/qlbridge
|
expr/builtins/filter.go
|
FiltersFromArgs
|
func FiltersFromArgs(filterVals []value.Value) []string {
filters := make([]string, 0, len(filterVals))
for _, fv := range filterVals {
switch fv := fv.(type) {
case value.Slice:
for _, fv := range fv.SliceValue() {
matchKey := fv.ToString()
if strings.Contains(matchKey, "%") {
matchKey = strings.Replace(matchKey, "%", "*", -1)
}
filters = append(filters, matchKey)
}
case value.StringValue:
matchKey := fv.ToString()
if strings.Contains(matchKey, "%") {
matchKey = strings.Replace(matchKey, "%", "*", -1)
}
filters = append(filters, matchKey)
}
}
return filters
}
|
go
|
func FiltersFromArgs(filterVals []value.Value) []string {
filters := make([]string, 0, len(filterVals))
for _, fv := range filterVals {
switch fv := fv.(type) {
case value.Slice:
for _, fv := range fv.SliceValue() {
matchKey := fv.ToString()
if strings.Contains(matchKey, "%") {
matchKey = strings.Replace(matchKey, "%", "*", -1)
}
filters = append(filters, matchKey)
}
case value.StringValue:
matchKey := fv.ToString()
if strings.Contains(matchKey, "%") {
matchKey = strings.Replace(matchKey, "%", "*", -1)
}
filters = append(filters, matchKey)
}
}
return filters
}
|
[
"func",
"FiltersFromArgs",
"(",
"filterVals",
"[",
"]",
"value",
".",
"Value",
")",
"[",
"]",
"string",
"{",
"filters",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"filterVals",
")",
")",
"\n",
"for",
"_",
",",
"fv",
":=",
"range",
"filterVals",
"{",
"switch",
"fv",
":=",
"fv",
".",
"(",
"type",
")",
"{",
"case",
"value",
".",
"Slice",
":",
"for",
"_",
",",
"fv",
":=",
"range",
"fv",
".",
"SliceValue",
"(",
")",
"{",
"matchKey",
":=",
"fv",
".",
"ToString",
"(",
")",
"\n",
"if",
"strings",
".",
"Contains",
"(",
"matchKey",
",",
"\"",
"\"",
")",
"{",
"matchKey",
"=",
"strings",
".",
"Replace",
"(",
"matchKey",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"filters",
"=",
"append",
"(",
"filters",
",",
"matchKey",
")",
"\n",
"}",
"\n",
"case",
"value",
".",
"StringValue",
":",
"matchKey",
":=",
"fv",
".",
"ToString",
"(",
")",
"\n",
"if",
"strings",
".",
"Contains",
"(",
"matchKey",
",",
"\"",
"\"",
")",
"{",
"matchKey",
"=",
"strings",
".",
"Replace",
"(",
"matchKey",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"filters",
"=",
"append",
"(",
"filters",
",",
"matchKey",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"filters",
"\n",
"}"
] |
// FilterFromArgs given set of values
|
[
"FilterFromArgs",
"given",
"set",
"of",
"values"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/builtins/filter.go#L37-L58
|
20,473
|
araddon/qlbridge
|
generators/elasticsearch/es2gen/bridgeutil.go
|
scalar
|
func scalar(node expr.Node) (interface{}, bool) {
switch n := node.(type) {
case *expr.StringNode:
return n.Text, true
case *expr.NumberNode:
if n.IsInt {
// ES supports string encoded ints
return n.Int64, true
}
return n.Float64, true
case *expr.ValueNode:
// Make sure this is a scalar value node
switch n.Value.Type() {
case value.BoolType, value.IntType, value.StringType, value.TimeType:
return n.String(), true
case value.NumberType:
nn, ok := n.Value.(floatval)
if !ok {
return nil, false
}
return nn.Float(), true
}
case *expr.IdentityNode:
if _, err := strconv.ParseBool(n.Text); err == nil {
return n.Text, true
}
}
return "", false
}
|
go
|
func scalar(node expr.Node) (interface{}, bool) {
switch n := node.(type) {
case *expr.StringNode:
return n.Text, true
case *expr.NumberNode:
if n.IsInt {
// ES supports string encoded ints
return n.Int64, true
}
return n.Float64, true
case *expr.ValueNode:
// Make sure this is a scalar value node
switch n.Value.Type() {
case value.BoolType, value.IntType, value.StringType, value.TimeType:
return n.String(), true
case value.NumberType:
nn, ok := n.Value.(floatval)
if !ok {
return nil, false
}
return nn.Float(), true
}
case *expr.IdentityNode:
if _, err := strconv.ParseBool(n.Text); err == nil {
return n.Text, true
}
}
return "", false
}
|
[
"func",
"scalar",
"(",
"node",
"expr",
".",
"Node",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"switch",
"n",
":=",
"node",
".",
"(",
"type",
")",
"{",
"case",
"*",
"expr",
".",
"StringNode",
":",
"return",
"n",
".",
"Text",
",",
"true",
"\n\n",
"case",
"*",
"expr",
".",
"NumberNode",
":",
"if",
"n",
".",
"IsInt",
"{",
"// ES supports string encoded ints",
"return",
"n",
".",
"Int64",
",",
"true",
"\n",
"}",
"\n",
"return",
"n",
".",
"Float64",
",",
"true",
"\n\n",
"case",
"*",
"expr",
".",
"ValueNode",
":",
"// Make sure this is a scalar value node",
"switch",
"n",
".",
"Value",
".",
"Type",
"(",
")",
"{",
"case",
"value",
".",
"BoolType",
",",
"value",
".",
"IntType",
",",
"value",
".",
"StringType",
",",
"value",
".",
"TimeType",
":",
"return",
"n",
".",
"String",
"(",
")",
",",
"true",
"\n",
"case",
"value",
".",
"NumberType",
":",
"nn",
",",
"ok",
":=",
"n",
".",
"Value",
".",
"(",
"floatval",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"return",
"nn",
".",
"Float",
"(",
")",
",",
"true",
"\n",
"}",
"\n",
"case",
"*",
"expr",
".",
"IdentityNode",
":",
"if",
"_",
",",
"err",
":=",
"strconv",
".",
"ParseBool",
"(",
"n",
".",
"Text",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"n",
".",
"Text",
",",
"true",
"\n",
"}",
"\n\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}"
] |
// scalar returns a JSONable representation of a scalar node type for use in ES
// filters.
//
// Does not support Null.
//
|
[
"scalar",
"returns",
"a",
"JSONable",
"representation",
"of",
"a",
"scalar",
"node",
"type",
"for",
"use",
"in",
"ES",
"filters",
".",
"Does",
"not",
"support",
"Null",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/generators/elasticsearch/es2gen/bridgeutil.go#L26-L58
|
20,474
|
araddon/qlbridge
|
plan/sql_rewrite.go
|
Eval
|
func (m *defaultTypeWriter) Eval(ctx expr.EvalContext, vals []value.Value) (value.Value, bool) {
if len(vals) == 0 || vals[0] == nil || vals[0].Nil() {
return nil, false
}
switch sv := vals[0].(type) {
case value.StringValue:
return sv, true
}
return value.NewStringValue(""), false
}
|
go
|
func (m *defaultTypeWriter) Eval(ctx expr.EvalContext, vals []value.Value) (value.Value, bool) {
if len(vals) == 0 || vals[0] == nil || vals[0].Nil() {
return nil, false
}
switch sv := vals[0].(type) {
case value.StringValue:
return sv, true
}
return value.NewStringValue(""), false
}
|
[
"func",
"(",
"m",
"*",
"defaultTypeWriter",
")",
"Eval",
"(",
"ctx",
"expr",
".",
"EvalContext",
",",
"vals",
"[",
"]",
"value",
".",
"Value",
")",
"(",
"value",
".",
"Value",
",",
"bool",
")",
"{",
"if",
"len",
"(",
"vals",
")",
"==",
"0",
"||",
"vals",
"[",
"0",
"]",
"==",
"nil",
"||",
"vals",
"[",
"0",
"]",
".",
"Nil",
"(",
")",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"switch",
"sv",
":=",
"vals",
"[",
"0",
"]",
".",
"(",
"type",
")",
"{",
"case",
"value",
".",
"StringValue",
":",
"return",
"sv",
",",
"true",
"\n",
"}",
"\n",
"return",
"value",
".",
"NewStringValue",
"(",
"\"",
"\"",
")",
",",
"false",
"\n",
"}"
] |
// defaultTypeWriter Convert a qlbridge value type to qlbridge value type
|
[
"defaultTypeWriter",
"Convert",
"a",
"qlbridge",
"value",
"type",
"to",
"qlbridge",
"value",
"type"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/plan/sql_rewrite.go#L26-L36
|
20,475
|
araddon/qlbridge
|
schema/apply_schema.go
|
Drop
|
func (m *InMemApplyer) Drop(s *Schema, v interface{}) error {
// Find the type of operation being updated.
switch v := v.(type) {
case *Table:
u.Debugf("%p:%s InfoSchema P:%p dropping table %q from %v", s, s.Name, s.InfoSchema, v.Name, s.Tables())
// s==v means schema is being dropped
m.reg.mu.Lock()
s.mu.Lock()
s.dropTable(v)
m.reg.schemas[s.Name] = s
s.refreshSchemaUnlocked()
s.mu.Unlock()
m.reg.mu.Unlock()
case *Schema:
u.Debugf("%p:%s InfoSchema P:%p dropping schema %q s==v?%v", s, s.Name, s.InfoSchema, v.Name, s == v)
// s==v means schema is being dropped
m.reg.mu.Lock()
s.mu.Lock()
delete(m.reg.schemas, s.Name)
names := make([]string, 0, len(m.reg.schemaNames))
for _, n := range m.reg.schemaNames {
if s.Name != n {
names = append(names, n)
}
}
m.reg.schemaNames = names
s.refreshSchemaUnlocked()
s.mu.Unlock()
m.reg.mu.Unlock()
default:
u.Errorf("invalid type %T", v)
return fmt.Errorf("Could not find %T", v)
}
return nil
}
|
go
|
func (m *InMemApplyer) Drop(s *Schema, v interface{}) error {
// Find the type of operation being updated.
switch v := v.(type) {
case *Table:
u.Debugf("%p:%s InfoSchema P:%p dropping table %q from %v", s, s.Name, s.InfoSchema, v.Name, s.Tables())
// s==v means schema is being dropped
m.reg.mu.Lock()
s.mu.Lock()
s.dropTable(v)
m.reg.schemas[s.Name] = s
s.refreshSchemaUnlocked()
s.mu.Unlock()
m.reg.mu.Unlock()
case *Schema:
u.Debugf("%p:%s InfoSchema P:%p dropping schema %q s==v?%v", s, s.Name, s.InfoSchema, v.Name, s == v)
// s==v means schema is being dropped
m.reg.mu.Lock()
s.mu.Lock()
delete(m.reg.schemas, s.Name)
names := make([]string, 0, len(m.reg.schemaNames))
for _, n := range m.reg.schemaNames {
if s.Name != n {
names = append(names, n)
}
}
m.reg.schemaNames = names
s.refreshSchemaUnlocked()
s.mu.Unlock()
m.reg.mu.Unlock()
default:
u.Errorf("invalid type %T", v)
return fmt.Errorf("Could not find %T", v)
}
return nil
}
|
[
"func",
"(",
"m",
"*",
"InMemApplyer",
")",
"Drop",
"(",
"s",
"*",
"Schema",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"// Find the type of operation being updated.",
"switch",
"v",
":=",
"v",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Table",
":",
"u",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"s",
",",
"s",
".",
"Name",
",",
"s",
".",
"InfoSchema",
",",
"v",
".",
"Name",
",",
"s",
".",
"Tables",
"(",
")",
")",
"\n",
"// s==v means schema is being dropped",
"m",
".",
"reg",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"dropTable",
"(",
"v",
")",
"\n",
"m",
".",
"reg",
".",
"schemas",
"[",
"s",
".",
"Name",
"]",
"=",
"s",
"\n",
"s",
".",
"refreshSchemaUnlocked",
"(",
")",
"\n",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"m",
".",
"reg",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"case",
"*",
"Schema",
":",
"u",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"s",
",",
"s",
".",
"Name",
",",
"s",
".",
"InfoSchema",
",",
"v",
".",
"Name",
",",
"s",
"==",
"v",
")",
"\n",
"// s==v means schema is being dropped",
"m",
".",
"reg",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n\n",
"delete",
"(",
"m",
".",
"reg",
".",
"schemas",
",",
"s",
".",
"Name",
")",
"\n",
"names",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"m",
".",
"reg",
".",
"schemaNames",
")",
")",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"m",
".",
"reg",
".",
"schemaNames",
"{",
"if",
"s",
".",
"Name",
"!=",
"n",
"{",
"names",
"=",
"append",
"(",
"names",
",",
"n",
")",
"\n",
"}",
"\n",
"}",
"\n",
"m",
".",
"reg",
".",
"schemaNames",
"=",
"names",
"\n\n",
"s",
".",
"refreshSchemaUnlocked",
"(",
")",
"\n",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"m",
".",
"reg",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"default",
":",
"u",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Drop we have a schema change to apply.
|
[
"Drop",
"we",
"have",
"a",
"schema",
"change",
"to",
"apply",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/schema/apply_schema.go#L108-L148
|
20,476
|
araddon/qlbridge
|
datasource/csv.go
|
NewCsvSource
|
func NewCsvSource(table string, indexCol int, ior io.Reader, exit <-chan bool) (*CsvDataSource, error) {
m := CsvDataSource{table: table, indexCol: indexCol}
if rc, ok := ior.(io.ReadCloser); ok {
m.rc = rc
}
buf := bufio.NewReader(ior)
first2, err := buf.Peek(2)
if err != nil {
u.Errorf("Error opening bufio.peek for csv reader %v", err)
return nil, err
}
// TODO: move this compression to the file-reader not here
if err == nil && len(first2) == 2 && bytes.Equal(first2, []byte{'\x1F', '\x8B'}) {
gr, err := gzip.NewReader(buf)
if err != nil {
u.Errorf("Could not open reader? %v", err)
return nil, err
}
m.gz = gr
m.csvr = csv.NewReader(gr)
} else {
m.csvr = csv.NewReader(buf)
}
m.csvr.TrailingComma = true // allow empty fields
// if flagCsvDelimiter == "|" {
// m.csvr.Comma = '|'
// } else if flagCsvDelimiter == "\t" || flagCsvDelimiter == "t" {
// m.csvr.Comma = '\t'
// }
headers, err := m.csvr.Read()
if err != nil {
u.Warnf("err csv %v", err)
return nil, err
}
//u.Debugf("headers: %v", headers)
m.headers = headers
m.colindex = make(map[string]int, len(headers))
for i, key := range headers {
key = strings.ToLower(key)
m.colindex[key] = i
m.headers[i] = key
}
m.loadTable()
//u.Infof("csv headers: %v colIndex: %v", headers, m.colindex)
return &m, nil
}
|
go
|
func NewCsvSource(table string, indexCol int, ior io.Reader, exit <-chan bool) (*CsvDataSource, error) {
m := CsvDataSource{table: table, indexCol: indexCol}
if rc, ok := ior.(io.ReadCloser); ok {
m.rc = rc
}
buf := bufio.NewReader(ior)
first2, err := buf.Peek(2)
if err != nil {
u.Errorf("Error opening bufio.peek for csv reader %v", err)
return nil, err
}
// TODO: move this compression to the file-reader not here
if err == nil && len(first2) == 2 && bytes.Equal(first2, []byte{'\x1F', '\x8B'}) {
gr, err := gzip.NewReader(buf)
if err != nil {
u.Errorf("Could not open reader? %v", err)
return nil, err
}
m.gz = gr
m.csvr = csv.NewReader(gr)
} else {
m.csvr = csv.NewReader(buf)
}
m.csvr.TrailingComma = true // allow empty fields
// if flagCsvDelimiter == "|" {
// m.csvr.Comma = '|'
// } else if flagCsvDelimiter == "\t" || flagCsvDelimiter == "t" {
// m.csvr.Comma = '\t'
// }
headers, err := m.csvr.Read()
if err != nil {
u.Warnf("err csv %v", err)
return nil, err
}
//u.Debugf("headers: %v", headers)
m.headers = headers
m.colindex = make(map[string]int, len(headers))
for i, key := range headers {
key = strings.ToLower(key)
m.colindex[key] = i
m.headers[i] = key
}
m.loadTable()
//u.Infof("csv headers: %v colIndex: %v", headers, m.colindex)
return &m, nil
}
|
[
"func",
"NewCsvSource",
"(",
"table",
"string",
",",
"indexCol",
"int",
",",
"ior",
"io",
".",
"Reader",
",",
"exit",
"<-",
"chan",
"bool",
")",
"(",
"*",
"CsvDataSource",
",",
"error",
")",
"{",
"m",
":=",
"CsvDataSource",
"{",
"table",
":",
"table",
",",
"indexCol",
":",
"indexCol",
"}",
"\n",
"if",
"rc",
",",
"ok",
":=",
"ior",
".",
"(",
"io",
".",
"ReadCloser",
")",
";",
"ok",
"{",
"m",
".",
"rc",
"=",
"rc",
"\n",
"}",
"\n\n",
"buf",
":=",
"bufio",
".",
"NewReader",
"(",
"ior",
")",
"\n\n",
"first2",
",",
"err",
":=",
"buf",
".",
"Peek",
"(",
"2",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"u",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// TODO: move this compression to the file-reader not here",
"if",
"err",
"==",
"nil",
"&&",
"len",
"(",
"first2",
")",
"==",
"2",
"&&",
"bytes",
".",
"Equal",
"(",
"first2",
",",
"[",
"]",
"byte",
"{",
"'\\x1F'",
",",
"'\\x8B'",
"}",
")",
"{",
"gr",
",",
"err",
":=",
"gzip",
".",
"NewReader",
"(",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"u",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"m",
".",
"gz",
"=",
"gr",
"\n",
"m",
".",
"csvr",
"=",
"csv",
".",
"NewReader",
"(",
"gr",
")",
"\n",
"}",
"else",
"{",
"m",
".",
"csvr",
"=",
"csv",
".",
"NewReader",
"(",
"buf",
")",
"\n",
"}",
"\n\n",
"m",
".",
"csvr",
".",
"TrailingComma",
"=",
"true",
"// allow empty fields",
"\n",
"// if flagCsvDelimiter == \"|\" {",
"// \tm.csvr.Comma = '|'",
"// } else if flagCsvDelimiter == \"\\t\" || flagCsvDelimiter == \"t\" {",
"// \tm.csvr.Comma = '\\t'",
"// }",
"headers",
",",
"err",
":=",
"m",
".",
"csvr",
".",
"Read",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"//u.Debugf(\"headers: %v\", headers)",
"m",
".",
"headers",
"=",
"headers",
"\n",
"m",
".",
"colindex",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
",",
"len",
"(",
"headers",
")",
")",
"\n",
"for",
"i",
",",
"key",
":=",
"range",
"headers",
"{",
"key",
"=",
"strings",
".",
"ToLower",
"(",
"key",
")",
"\n",
"m",
".",
"colindex",
"[",
"key",
"]",
"=",
"i",
"\n",
"m",
".",
"headers",
"[",
"i",
"]",
"=",
"key",
"\n",
"}",
"\n",
"m",
".",
"loadTable",
"(",
")",
"\n",
"//u.Infof(\"csv headers: %v colIndex: %v\", headers, m.colindex)",
"return",
"&",
"m",
",",
"nil",
"\n",
"}"
] |
// NewCsvSource reader assumes we are getting first row as headers
// - optionally may be gzipped
|
[
"NewCsvSource",
"reader",
"assumes",
"we",
"are",
"getting",
"first",
"row",
"as",
"headers",
"-",
"optionally",
"may",
"be",
"gzipped"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/datasource/csv.go#L48-L98
|
20,477
|
araddon/qlbridge
|
datasource/memdb/db.go
|
NewMemDbData
|
func NewMemDbData(name string, data [][]driver.Value, cols []string) (*MemDb, error) {
m, err := NewMemDb(name, cols)
if err != nil {
return nil, err
}
// Insert initial values
conn := newDbConn(m)
defer conn.Close()
for _, row := range data {
conn.Put(nil, nil, row)
}
// we are going to look at ~10 rows to create schema for it
if err = datasource.IntrospectTable(m.tbl, conn); err != nil {
u.Errorf("Could not introspect schema %v", err)
return nil, err
}
return m, nil
}
|
go
|
func NewMemDbData(name string, data [][]driver.Value, cols []string) (*MemDb, error) {
m, err := NewMemDb(name, cols)
if err != nil {
return nil, err
}
// Insert initial values
conn := newDbConn(m)
defer conn.Close()
for _, row := range data {
conn.Put(nil, nil, row)
}
// we are going to look at ~10 rows to create schema for it
if err = datasource.IntrospectTable(m.tbl, conn); err != nil {
u.Errorf("Could not introspect schema %v", err)
return nil, err
}
return m, nil
}
|
[
"func",
"NewMemDbData",
"(",
"name",
"string",
",",
"data",
"[",
"]",
"[",
"]",
"driver",
".",
"Value",
",",
"cols",
"[",
"]",
"string",
")",
"(",
"*",
"MemDb",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"NewMemDb",
"(",
"name",
",",
"cols",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// Insert initial values",
"conn",
":=",
"newDbConn",
"(",
"m",
")",
"\n",
"defer",
"conn",
".",
"Close",
"(",
")",
"\n",
"for",
"_",
",",
"row",
":=",
"range",
"data",
"{",
"conn",
".",
"Put",
"(",
"nil",
",",
"nil",
",",
"row",
")",
"\n",
"}",
"\n\n",
"// we are going to look at ~10 rows to create schema for it",
"if",
"err",
"=",
"datasource",
".",
"IntrospectTable",
"(",
"m",
".",
"tbl",
",",
"conn",
")",
";",
"err",
"!=",
"nil",
"{",
"u",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] |
// NewMemDbData creates a MemDb with given indexes, columns, and values
|
[
"NewMemDbData",
"creates",
"a",
"MemDb",
"with",
"given",
"indexes",
"columns",
"and",
"values"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/datasource/memdb/db.go#L57-L76
|
20,478
|
araddon/qlbridge
|
datasource/memdb/db.go
|
NewMemDb
|
func NewMemDb(name string, cols []string) (*MemDb, error) {
return NewMemDbForSchema(name, cols)
}
|
go
|
func NewMemDb(name string, cols []string) (*MemDb, error) {
return NewMemDbForSchema(name, cols)
}
|
[
"func",
"NewMemDb",
"(",
"name",
"string",
",",
"cols",
"[",
"]",
"string",
")",
"(",
"*",
"MemDb",
",",
"error",
")",
"{",
"return",
"NewMemDbForSchema",
"(",
"name",
",",
"cols",
")",
"\n",
"}"
] |
// NewMemDb creates a MemDb with given indexes, columns
|
[
"NewMemDb",
"creates",
"a",
"MemDb",
"with",
"given",
"indexes",
"columns"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/datasource/memdb/db.go#L79-L81
|
20,479
|
araddon/qlbridge
|
datasource/memdb/db.go
|
NewMemDbForSchema
|
func NewMemDbForSchema(name string, cols []string) (*MemDb, error) {
if len(cols) < 1 {
return nil, fmt.Errorf("must have columns provided")
}
m := &MemDb{}
m.exit = make(chan bool, 1)
var err error
m.tbl = schema.NewTable(name)
m.tbl.SetColumns(cols)
m.buildDefaultIndexes()
mdbSchema := makeMemDbSchema(m)
m.db, err = memdb.NewMemDB(mdbSchema)
return m, err
}
|
go
|
func NewMemDbForSchema(name string, cols []string) (*MemDb, error) {
if len(cols) < 1 {
return nil, fmt.Errorf("must have columns provided")
}
m := &MemDb{}
m.exit = make(chan bool, 1)
var err error
m.tbl = schema.NewTable(name)
m.tbl.SetColumns(cols)
m.buildDefaultIndexes()
mdbSchema := makeMemDbSchema(m)
m.db, err = memdb.NewMemDB(mdbSchema)
return m, err
}
|
[
"func",
"NewMemDbForSchema",
"(",
"name",
"string",
",",
"cols",
"[",
"]",
"string",
")",
"(",
"*",
"MemDb",
",",
"error",
")",
"{",
"if",
"len",
"(",
"cols",
")",
"<",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"m",
":=",
"&",
"MemDb",
"{",
"}",
"\n",
"m",
".",
"exit",
"=",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
"\n",
"var",
"err",
"error",
"\n",
"m",
".",
"tbl",
"=",
"schema",
".",
"NewTable",
"(",
"name",
")",
"\n",
"m",
".",
"tbl",
".",
"SetColumns",
"(",
"cols",
")",
"\n",
"m",
".",
"buildDefaultIndexes",
"(",
")",
"\n",
"mdbSchema",
":=",
"makeMemDbSchema",
"(",
"m",
")",
"\n",
"m",
".",
"db",
",",
"err",
"=",
"memdb",
".",
"NewMemDB",
"(",
"mdbSchema",
")",
"\n",
"return",
"m",
",",
"err",
"\n",
"}"
] |
// NewMemDbForSchema creates a MemDb with given indexes, columns
|
[
"NewMemDbForSchema",
"creates",
"a",
"MemDb",
"with",
"given",
"indexes",
"columns"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/datasource/memdb/db.go#L84-L98
|
20,480
|
araddon/qlbridge
|
datasource/memdb/db.go
|
DeleteExpression
|
func (m *dbConn) DeleteExpression(p interface{}, where expr.Node) (int, error) {
var deletedKeys []schema.Key
txn := m.db.Txn(true)
iter, err := txn.Get(m.md.tbl.Name, m.md.primaryIndex)
if err != nil {
txn.Abort()
u.Errorf("could not get values %v", err)
return 0, err
}
deleteLoop:
for {
item := iter.Next()
if item == nil {
break
}
msg, ok := item.(*datasource.SqlDriverMessage)
if !ok {
u.Warnf("wat? %T %#v", item, item)
err = fmt.Errorf("unexpected message type %T", item)
break
}
whereValue, ok := vm.Eval(msg.ToMsgMap(m.md.tbl.FieldPositions), where)
if !ok {
u.Debugf("could not evaluate where: %v", msg)
}
switch whereVal := whereValue.(type) {
case value.BoolValue:
if whereVal.Val() == false {
//this means do NOT delete
} else {
// Delete!
if err = txn.Delete(m.md.tbl.Name, msg); err != nil {
u.Errorf("could not delete %v", err)
break deleteLoop
}
indexVal := msg.Vals[0]
deletedKeys = append(deletedKeys, schema.NewKeyUint(makeId(indexVal)))
}
case nil:
// ??
u.Warnf("this should be fine, couldn't evaluate so don't delete %v", msg)
default:
if whereVal.Nil() {
// Doesn't match, so don't delete
} else {
u.Warnf("unknown where eval result? %T", whereVal)
}
}
}
if err != nil {
txn.Abort()
return 0, err
}
txn.Commit()
return len(deletedKeys), nil
}
|
go
|
func (m *dbConn) DeleteExpression(p interface{}, where expr.Node) (int, error) {
var deletedKeys []schema.Key
txn := m.db.Txn(true)
iter, err := txn.Get(m.md.tbl.Name, m.md.primaryIndex)
if err != nil {
txn.Abort()
u.Errorf("could not get values %v", err)
return 0, err
}
deleteLoop:
for {
item := iter.Next()
if item == nil {
break
}
msg, ok := item.(*datasource.SqlDriverMessage)
if !ok {
u.Warnf("wat? %T %#v", item, item)
err = fmt.Errorf("unexpected message type %T", item)
break
}
whereValue, ok := vm.Eval(msg.ToMsgMap(m.md.tbl.FieldPositions), where)
if !ok {
u.Debugf("could not evaluate where: %v", msg)
}
switch whereVal := whereValue.(type) {
case value.BoolValue:
if whereVal.Val() == false {
//this means do NOT delete
} else {
// Delete!
if err = txn.Delete(m.md.tbl.Name, msg); err != nil {
u.Errorf("could not delete %v", err)
break deleteLoop
}
indexVal := msg.Vals[0]
deletedKeys = append(deletedKeys, schema.NewKeyUint(makeId(indexVal)))
}
case nil:
// ??
u.Warnf("this should be fine, couldn't evaluate so don't delete %v", msg)
default:
if whereVal.Nil() {
// Doesn't match, so don't delete
} else {
u.Warnf("unknown where eval result? %T", whereVal)
}
}
}
if err != nil {
txn.Abort()
return 0, err
}
txn.Commit()
return len(deletedKeys), nil
}
|
[
"func",
"(",
"m",
"*",
"dbConn",
")",
"DeleteExpression",
"(",
"p",
"interface",
"{",
"}",
",",
"where",
"expr",
".",
"Node",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"deletedKeys",
"[",
"]",
"schema",
".",
"Key",
"\n",
"txn",
":=",
"m",
".",
"db",
".",
"Txn",
"(",
"true",
")",
"\n",
"iter",
",",
"err",
":=",
"txn",
".",
"Get",
"(",
"m",
".",
"md",
".",
"tbl",
".",
"Name",
",",
"m",
".",
"md",
".",
"primaryIndex",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"txn",
".",
"Abort",
"(",
")",
"\n",
"u",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"deleteLoop",
":",
"for",
"{",
"item",
":=",
"iter",
".",
"Next",
"(",
")",
"\n",
"if",
"item",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"msg",
",",
"ok",
":=",
"item",
".",
"(",
"*",
"datasource",
".",
"SqlDriverMessage",
")",
"\n",
"if",
"!",
"ok",
"{",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"item",
",",
"item",
")",
"\n",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"item",
")",
"\n",
"break",
"\n",
"}",
"\n",
"whereValue",
",",
"ok",
":=",
"vm",
".",
"Eval",
"(",
"msg",
".",
"ToMsgMap",
"(",
"m",
".",
"md",
".",
"tbl",
".",
"FieldPositions",
")",
",",
"where",
")",
"\n",
"if",
"!",
"ok",
"{",
"u",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"msg",
")",
"\n",
"}",
"\n",
"switch",
"whereVal",
":=",
"whereValue",
".",
"(",
"type",
")",
"{",
"case",
"value",
".",
"BoolValue",
":",
"if",
"whereVal",
".",
"Val",
"(",
")",
"==",
"false",
"{",
"//this means do NOT delete",
"}",
"else",
"{",
"// Delete!",
"if",
"err",
"=",
"txn",
".",
"Delete",
"(",
"m",
".",
"md",
".",
"tbl",
".",
"Name",
",",
"msg",
")",
";",
"err",
"!=",
"nil",
"{",
"u",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"break",
"deleteLoop",
"\n",
"}",
"\n",
"indexVal",
":=",
"msg",
".",
"Vals",
"[",
"0",
"]",
"\n",
"deletedKeys",
"=",
"append",
"(",
"deletedKeys",
",",
"schema",
".",
"NewKeyUint",
"(",
"makeId",
"(",
"indexVal",
")",
")",
")",
"\n",
"}",
"\n",
"case",
"nil",
":",
"// ??",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"msg",
")",
"\n",
"default",
":",
"if",
"whereVal",
".",
"Nil",
"(",
")",
"{",
"// Doesn't match, so don't delete",
"}",
"else",
"{",
"u",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"whereVal",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"txn",
".",
"Abort",
"(",
")",
"\n",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"txn",
".",
"Commit",
"(",
")",
"\n",
"return",
"len",
"(",
"deletedKeys",
")",
",",
"nil",
"\n",
"}"
] |
// Delete using a Where Expression
|
[
"Delete",
"using",
"a",
"Where",
"Expression"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/datasource/memdb/db.go#L269-L326
|
20,481
|
araddon/qlbridge
|
value/value.go
|
ValueFromString
|
func ValueFromString(vt string) ValueType {
switch vt {
case "nil", "null":
return NilType
case "error":
return ErrorType
case "unknown":
return UnknownType
case "value":
return ValueInterfaceType
case "number":
return NumberType
case "int":
return IntType
case "bool":
return BoolType
case "time":
return TimeType
case "[]byte":
return ByteSliceType
case "string":
return StringType
case "[]string":
return StringsType
case "map[string]value":
return MapValueType
case "map[string]int":
return MapIntType
case "map[string]string":
return MapStringType
case "map[string]number":
return MapNumberType
case "map[string]bool":
return MapBoolType
case "map[string]time":
return MapTimeType
case "[]value":
return SliceValueType
case "struct":
return StructType
case "json":
return JsonType
default:
return UnknownType
}
}
|
go
|
func ValueFromString(vt string) ValueType {
switch vt {
case "nil", "null":
return NilType
case "error":
return ErrorType
case "unknown":
return UnknownType
case "value":
return ValueInterfaceType
case "number":
return NumberType
case "int":
return IntType
case "bool":
return BoolType
case "time":
return TimeType
case "[]byte":
return ByteSliceType
case "string":
return StringType
case "[]string":
return StringsType
case "map[string]value":
return MapValueType
case "map[string]int":
return MapIntType
case "map[string]string":
return MapStringType
case "map[string]number":
return MapNumberType
case "map[string]bool":
return MapBoolType
case "map[string]time":
return MapTimeType
case "[]value":
return SliceValueType
case "struct":
return StructType
case "json":
return JsonType
default:
return UnknownType
}
}
|
[
"func",
"ValueFromString",
"(",
"vt",
"string",
")",
"ValueType",
"{",
"switch",
"vt",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"NilType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"ErrorType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"UnknownType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"ValueInterfaceType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"NumberType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"IntType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"BoolType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"TimeType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"ByteSliceType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"StringType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"StringsType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"MapValueType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"MapIntType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"MapStringType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"MapNumberType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"MapBoolType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"MapTimeType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"SliceValueType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"StructType",
"\n",
"case",
"\"",
"\"",
":",
"return",
"JsonType",
"\n",
"default",
":",
"return",
"UnknownType",
"\n",
"}",
"\n",
"}"
] |
// ValueFromString Given a string, convert to valuetype
|
[
"ValueFromString",
"Given",
"a",
"string",
"convert",
"to",
"valuetype"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/value/value.go#L241-L286
|
20,482
|
araddon/qlbridge
|
expr/node.go
|
FindAllIdentities
|
func FindAllIdentities(node Node) IdentityNodes {
in := make(IdentityNodes, 0)
return findIdentities(node, in)
}
|
go
|
func FindAllIdentities(node Node) IdentityNodes {
in := make(IdentityNodes, 0)
return findIdentities(node, in)
}
|
[
"func",
"FindAllIdentities",
"(",
"node",
"Node",
")",
"IdentityNodes",
"{",
"in",
":=",
"make",
"(",
"IdentityNodes",
",",
"0",
")",
"\n",
"return",
"findIdentities",
"(",
"node",
",",
"in",
")",
"\n",
"}"
] |
// FindAllIdentities gets all identity
|
[
"FindAllIdentities",
"gets",
"all",
"identity"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/node.go#L368-L371
|
20,483
|
araddon/qlbridge
|
expr/node.go
|
Strings
|
func (m IdentityNodes) Strings() []string {
s := make([]string, len(m))
for i, in := range m {
s[i] = in.Text
}
return s
}
|
go
|
func (m IdentityNodes) Strings() []string {
s := make([]string, len(m))
for i, in := range m {
s[i] = in.Text
}
return s
}
|
[
"func",
"(",
"m",
"IdentityNodes",
")",
"Strings",
"(",
")",
"[",
"]",
"string",
"{",
"s",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"m",
")",
")",
"\n",
"for",
"i",
",",
"in",
":=",
"range",
"m",
"{",
"s",
"[",
"i",
"]",
"=",
"in",
".",
"Text",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// Strings get all identity strings
|
[
"Strings",
"get",
"all",
"identity",
"strings"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/node.go#L418-L424
|
20,484
|
araddon/qlbridge
|
expr/node.go
|
LeftStrings
|
func (m IdentityNodes) LeftStrings() []string {
s := make([]string, len(m))
for i, in := range m {
l, r, hasLr := in.LeftRight()
if hasLr {
s[i] = l
} else {
s[i] = r
}
}
return s
}
|
go
|
func (m IdentityNodes) LeftStrings() []string {
s := make([]string, len(m))
for i, in := range m {
l, r, hasLr := in.LeftRight()
if hasLr {
s[i] = l
} else {
s[i] = r
}
}
return s
}
|
[
"func",
"(",
"m",
"IdentityNodes",
")",
"LeftStrings",
"(",
")",
"[",
"]",
"string",
"{",
"s",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"m",
")",
")",
"\n",
"for",
"i",
",",
"in",
":=",
"range",
"m",
"{",
"l",
",",
"r",
",",
"hasLr",
":=",
"in",
".",
"LeftRight",
"(",
")",
"\n",
"if",
"hasLr",
"{",
"s",
"[",
"i",
"]",
"=",
"l",
"\n",
"}",
"else",
"{",
"s",
"[",
"i",
"]",
"=",
"r",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// LeftStrings get all Left Identity fields.
|
[
"LeftStrings",
"get",
"all",
"Left",
"Identity",
"fields",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/node.go#L427-L438
|
20,485
|
araddon/qlbridge
|
expr/node.go
|
ValueTypeFromNode
|
func ValueTypeFromNode(n Node) value.ValueType {
switch nt := n.(type) {
case *FuncNode:
if nt == nil {
return value.UnknownType
}
if nt.F.CustomFunc == nil {
return value.UnknownType
}
return nt.F.Type()
case *StringNode:
return value.StringType
case *IdentityNode:
// Identity types will draw type from context.
return value.UnknownType
case *NumberNode:
return value.NumberType
case *BooleanNode:
return value.BoolType
case *BinaryNode:
switch nt.Operator.T {
case lex.TokenLogicAnd, lex.TokenAnd, lex.TokenLogicOr, lex.TokenOr,
lex.TokenEqual, lex.TokenEqualEqual:
return value.BoolType
case lex.TokenMultiply, lex.TokenMinus, lex.TokenAdd, lex.TokenDivide:
return value.NumberType
case lex.TokenModulus:
return value.IntType
case lex.TokenLT, lex.TokenLE, lex.TokenGT, lex.TokenGE:
return value.BoolType
}
}
return value.UnknownType
}
|
go
|
func ValueTypeFromNode(n Node) value.ValueType {
switch nt := n.(type) {
case *FuncNode:
if nt == nil {
return value.UnknownType
}
if nt.F.CustomFunc == nil {
return value.UnknownType
}
return nt.F.Type()
case *StringNode:
return value.StringType
case *IdentityNode:
// Identity types will draw type from context.
return value.UnknownType
case *NumberNode:
return value.NumberType
case *BooleanNode:
return value.BoolType
case *BinaryNode:
switch nt.Operator.T {
case lex.TokenLogicAnd, lex.TokenAnd, lex.TokenLogicOr, lex.TokenOr,
lex.TokenEqual, lex.TokenEqualEqual:
return value.BoolType
case lex.TokenMultiply, lex.TokenMinus, lex.TokenAdd, lex.TokenDivide:
return value.NumberType
case lex.TokenModulus:
return value.IntType
case lex.TokenLT, lex.TokenLE, lex.TokenGT, lex.TokenGE:
return value.BoolType
}
}
return value.UnknownType
}
|
[
"func",
"ValueTypeFromNode",
"(",
"n",
"Node",
")",
"value",
".",
"ValueType",
"{",
"switch",
"nt",
":=",
"n",
".",
"(",
"type",
")",
"{",
"case",
"*",
"FuncNode",
":",
"if",
"nt",
"==",
"nil",
"{",
"return",
"value",
".",
"UnknownType",
"\n",
"}",
"\n",
"if",
"nt",
".",
"F",
".",
"CustomFunc",
"==",
"nil",
"{",
"return",
"value",
".",
"UnknownType",
"\n",
"}",
"\n",
"return",
"nt",
".",
"F",
".",
"Type",
"(",
")",
"\n",
"case",
"*",
"StringNode",
":",
"return",
"value",
".",
"StringType",
"\n",
"case",
"*",
"IdentityNode",
":",
"// Identity types will draw type from context.",
"return",
"value",
".",
"UnknownType",
"\n",
"case",
"*",
"NumberNode",
":",
"return",
"value",
".",
"NumberType",
"\n",
"case",
"*",
"BooleanNode",
":",
"return",
"value",
".",
"BoolType",
"\n",
"case",
"*",
"BinaryNode",
":",
"switch",
"nt",
".",
"Operator",
".",
"T",
"{",
"case",
"lex",
".",
"TokenLogicAnd",
",",
"lex",
".",
"TokenAnd",
",",
"lex",
".",
"TokenLogicOr",
",",
"lex",
".",
"TokenOr",
",",
"lex",
".",
"TokenEqual",
",",
"lex",
".",
"TokenEqualEqual",
":",
"return",
"value",
".",
"BoolType",
"\n",
"case",
"lex",
".",
"TokenMultiply",
",",
"lex",
".",
"TokenMinus",
",",
"lex",
".",
"TokenAdd",
",",
"lex",
".",
"TokenDivide",
":",
"return",
"value",
".",
"NumberType",
"\n",
"case",
"lex",
".",
"TokenModulus",
":",
"return",
"value",
".",
"IntType",
"\n",
"case",
"lex",
".",
"TokenLT",
",",
"lex",
".",
"TokenLE",
",",
"lex",
".",
"TokenGT",
",",
"lex",
".",
"TokenGE",
":",
"return",
"value",
".",
"BoolType",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"value",
".",
"UnknownType",
"\n",
"}"
] |
// ValueTypeFromNode Infer Value type from Node
|
[
"ValueTypeFromNode",
"Infer",
"Value",
"type",
"from",
"Node"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/node.go#L483-L516
|
20,486
|
araddon/qlbridge
|
expr/node.go
|
NewFuncNode
|
func NewFuncNode(name string, f Func) *FuncNode {
return &FuncNode{Name: name, F: f}
}
|
go
|
func NewFuncNode(name string, f Func) *FuncNode {
return &FuncNode{Name: name, F: f}
}
|
[
"func",
"NewFuncNode",
"(",
"name",
"string",
",",
"f",
"Func",
")",
"*",
"FuncNode",
"{",
"return",
"&",
"FuncNode",
"{",
"Name",
":",
"name",
",",
"F",
":",
"f",
"}",
"\n",
"}"
] |
// NewFuncNode create new Function Expression Node.
|
[
"NewFuncNode",
"create",
"new",
"Function",
"Expression",
"Node",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/node.go#L519-L521
|
20,487
|
araddon/qlbridge
|
expr/node.go
|
Expr
|
func (m *FuncNode) Expr() *Expr {
fe := &Expr{Op: lex.TokenUdfExpr.String()}
if len(m.Args) > 0 {
fe.Args = []*Expr{{Identity: m.Name}}
fe.Args = append(fe.Args, ExprsFromNodes(m.Args)...)
}
return fe
}
|
go
|
func (m *FuncNode) Expr() *Expr {
fe := &Expr{Op: lex.TokenUdfExpr.String()}
if len(m.Args) > 0 {
fe.Args = []*Expr{{Identity: m.Name}}
fe.Args = append(fe.Args, ExprsFromNodes(m.Args)...)
}
return fe
}
|
[
"func",
"(",
"m",
"*",
"FuncNode",
")",
"Expr",
"(",
")",
"*",
"Expr",
"{",
"fe",
":=",
"&",
"Expr",
"{",
"Op",
":",
"lex",
".",
"TokenUdfExpr",
".",
"String",
"(",
")",
"}",
"\n",
"if",
"len",
"(",
"m",
".",
"Args",
")",
">",
"0",
"{",
"fe",
".",
"Args",
"=",
"[",
"]",
"*",
"Expr",
"{",
"{",
"Identity",
":",
"m",
".",
"Name",
"}",
"}",
"\n",
"fe",
".",
"Args",
"=",
"append",
"(",
"fe",
".",
"Args",
",",
"ExprsFromNodes",
"(",
"m",
".",
"Args",
")",
"...",
")",
"\n",
"}",
"\n",
"return",
"fe",
"\n",
"}"
] |
// Expr convert the FuncNode to Expr
|
[
"Expr",
"convert",
"the",
"FuncNode",
"to",
"Expr"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/node.go#L600-L607
|
20,488
|
araddon/qlbridge
|
expr/node.go
|
NewNumberStr
|
func NewNumberStr(text string) (*NumberNode, error) {
n := &NumberNode{Text: text}
return n, n.load()
}
|
go
|
func NewNumberStr(text string) (*NumberNode, error) {
n := &NumberNode{Text: text}
return n, n.load()
}
|
[
"func",
"NewNumberStr",
"(",
"text",
"string",
")",
"(",
"*",
"NumberNode",
",",
"error",
")",
"{",
"n",
":=",
"&",
"NumberNode",
"{",
"Text",
":",
"text",
"}",
"\n",
"return",
"n",
",",
"n",
".",
"load",
"(",
")",
"\n",
"}"
] |
// NewNumberStr is a little weird in that this Node accepts string @text
// and uses go to parse into Int, AND Float.
|
[
"NewNumberStr",
"is",
"a",
"little",
"weird",
"in",
"that",
"this",
"Node",
"accepts",
"string"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/node.go#L672-L675
|
20,489
|
araddon/qlbridge
|
expr/node.go
|
NewBooleanNode
|
func NewBooleanNode(operator lex.Token, args ...Node) *BooleanNode {
//u.Debugf("NewBinaryNode: %v %v %v", lhArg, operator, rhArg)
return &BooleanNode{Args: args, Operator: operator}
}
|
go
|
func NewBooleanNode(operator lex.Token, args ...Node) *BooleanNode {
//u.Debugf("NewBinaryNode: %v %v %v", lhArg, operator, rhArg)
return &BooleanNode{Args: args, Operator: operator}
}
|
[
"func",
"NewBooleanNode",
"(",
"operator",
"lex",
".",
"Token",
",",
"args",
"...",
"Node",
")",
"*",
"BooleanNode",
"{",
"//u.Debugf(\"NewBinaryNode: %v %v %v\", lhArg, operator, rhArg)",
"return",
"&",
"BooleanNode",
"{",
"Args",
":",
"args",
",",
"Operator",
":",
"operator",
"}",
"\n",
"}"
] |
// NewBooleanNode Create a boolean node
// @operator = AND, OR
// @args = nodes
|
[
"NewBooleanNode",
"Create",
"a",
"boolean",
"node"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/node.go#L1409-L1412
|
20,490
|
araddon/qlbridge
|
expr/node.go
|
NewTriNode
|
func NewTriNode(operator lex.Token, arg1, arg2, arg3 Node) *TriNode {
return &TriNode{Args: []Node{arg1, arg2, arg3}, Operator: operator}
}
|
go
|
func NewTriNode(operator lex.Token, arg1, arg2, arg3 Node) *TriNode {
return &TriNode{Args: []Node{arg1, arg2, arg3}, Operator: operator}
}
|
[
"func",
"NewTriNode",
"(",
"operator",
"lex",
".",
"Token",
",",
"arg1",
",",
"arg2",
",",
"arg3",
"Node",
")",
"*",
"TriNode",
"{",
"return",
"&",
"TriNode",
"{",
"Args",
":",
"[",
"]",
"Node",
"{",
"arg1",
",",
"arg2",
",",
"arg3",
"}",
",",
"Operator",
":",
"operator",
"}",
"\n",
"}"
] |
// Create a Tri node
//
// @arg1 [NOT] BETWEEN @arg2 AND @arg3
//
|
[
"Create",
"a",
"Tri",
"node"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/node.go#L1555-L1557
|
20,491
|
araddon/qlbridge
|
expr/node.go
|
NodeFromPb
|
func NodeFromPb(pb []byte) (Node, error) {
n := &NodePb{}
if err := proto.Unmarshal(pb, n); err != nil {
return nil, err
}
return NodeFromNodePb(n), nil
}
|
go
|
func NodeFromPb(pb []byte) (Node, error) {
n := &NodePb{}
if err := proto.Unmarshal(pb, n); err != nil {
return nil, err
}
return NodeFromNodePb(n), nil
}
|
[
"func",
"NodeFromPb",
"(",
"pb",
"[",
"]",
"byte",
")",
"(",
"Node",
",",
"error",
")",
"{",
"n",
":=",
"&",
"NodePb",
"{",
"}",
"\n",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"pb",
",",
"n",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"NodeFromNodePb",
"(",
"n",
")",
",",
"nil",
"\n",
"}"
] |
// NodeFromPb Create a node from pb
|
[
"NodeFromPb",
"Create",
"a",
"node",
"from",
"pb"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/node.go#L2032-L2038
|
20,492
|
araddon/qlbridge
|
expr/node.go
|
NodeFromNodePb
|
func NodeFromNodePb(n *NodePb) Node {
if n == nil {
return nil
}
switch {
case n.Bn != nil:
var bn *BinaryNode
return bn.FromPB(n)
case n.Booln != nil:
var bn *BooleanNode
return bn.FromPB(n)
case n.Un != nil:
var un *UnaryNode
return un.FromPB(n)
case n.Fn != nil:
var fn *FuncNode
return fn.FromPB(n)
case n.Tn != nil:
var tn *TriNode
return tn.FromPB(n)
case n.An != nil:
var an *ArrayNode
return an.FromPB(n)
case n.Nn != nil:
var nn *NumberNode
return nn.FromPB(n)
case n.Vn != nil:
var vn *ValueNode
return vn.FromPB(n)
case n.In != nil:
var in *IdentityNode
return in.FromPB(n)
case n.Sn != nil:
var sn *StringNode
return sn.FromPB(n)
case n.Incn != nil:
var in *IncludeNode
return in.FromPB(n)
case n.Niln != nil:
return &NullNode{}
}
return nil
}
|
go
|
func NodeFromNodePb(n *NodePb) Node {
if n == nil {
return nil
}
switch {
case n.Bn != nil:
var bn *BinaryNode
return bn.FromPB(n)
case n.Booln != nil:
var bn *BooleanNode
return bn.FromPB(n)
case n.Un != nil:
var un *UnaryNode
return un.FromPB(n)
case n.Fn != nil:
var fn *FuncNode
return fn.FromPB(n)
case n.Tn != nil:
var tn *TriNode
return tn.FromPB(n)
case n.An != nil:
var an *ArrayNode
return an.FromPB(n)
case n.Nn != nil:
var nn *NumberNode
return nn.FromPB(n)
case n.Vn != nil:
var vn *ValueNode
return vn.FromPB(n)
case n.In != nil:
var in *IdentityNode
return in.FromPB(n)
case n.Sn != nil:
var sn *StringNode
return sn.FromPB(n)
case n.Incn != nil:
var in *IncludeNode
return in.FromPB(n)
case n.Niln != nil:
return &NullNode{}
}
return nil
}
|
[
"func",
"NodeFromNodePb",
"(",
"n",
"*",
"NodePb",
")",
"Node",
"{",
"if",
"n",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"switch",
"{",
"case",
"n",
".",
"Bn",
"!=",
"nil",
":",
"var",
"bn",
"*",
"BinaryNode",
"\n",
"return",
"bn",
".",
"FromPB",
"(",
"n",
")",
"\n",
"case",
"n",
".",
"Booln",
"!=",
"nil",
":",
"var",
"bn",
"*",
"BooleanNode",
"\n",
"return",
"bn",
".",
"FromPB",
"(",
"n",
")",
"\n",
"case",
"n",
".",
"Un",
"!=",
"nil",
":",
"var",
"un",
"*",
"UnaryNode",
"\n",
"return",
"un",
".",
"FromPB",
"(",
"n",
")",
"\n",
"case",
"n",
".",
"Fn",
"!=",
"nil",
":",
"var",
"fn",
"*",
"FuncNode",
"\n",
"return",
"fn",
".",
"FromPB",
"(",
"n",
")",
"\n",
"case",
"n",
".",
"Tn",
"!=",
"nil",
":",
"var",
"tn",
"*",
"TriNode",
"\n",
"return",
"tn",
".",
"FromPB",
"(",
"n",
")",
"\n",
"case",
"n",
".",
"An",
"!=",
"nil",
":",
"var",
"an",
"*",
"ArrayNode",
"\n",
"return",
"an",
".",
"FromPB",
"(",
"n",
")",
"\n",
"case",
"n",
".",
"Nn",
"!=",
"nil",
":",
"var",
"nn",
"*",
"NumberNode",
"\n",
"return",
"nn",
".",
"FromPB",
"(",
"n",
")",
"\n",
"case",
"n",
".",
"Vn",
"!=",
"nil",
":",
"var",
"vn",
"*",
"ValueNode",
"\n",
"return",
"vn",
".",
"FromPB",
"(",
"n",
")",
"\n",
"case",
"n",
".",
"In",
"!=",
"nil",
":",
"var",
"in",
"*",
"IdentityNode",
"\n",
"return",
"in",
".",
"FromPB",
"(",
"n",
")",
"\n",
"case",
"n",
".",
"Sn",
"!=",
"nil",
":",
"var",
"sn",
"*",
"StringNode",
"\n",
"return",
"sn",
".",
"FromPB",
"(",
"n",
")",
"\n",
"case",
"n",
".",
"Incn",
"!=",
"nil",
":",
"var",
"in",
"*",
"IncludeNode",
"\n",
"return",
"in",
".",
"FromPB",
"(",
"n",
")",
"\n",
"case",
"n",
".",
"Niln",
"!=",
"nil",
":",
"return",
"&",
"NullNode",
"{",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// NodeFromNodePb Create a node from pb
|
[
"NodeFromNodePb",
"Create",
"a",
"node",
"from",
"pb"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/expr/node.go#L2041-L2083
|
20,493
|
araddon/qlbridge
|
lex/lexer.go
|
NewLexer
|
func NewLexer(input string, dialect *Dialect) *Lexer {
// Three tokens of buffering is sufficient for all state functions.
l := &Lexer{
input: input,
state: LexDialectForStatement,
tokens: make(chan Token, 3),
stack: make([]NamedStateFn, 0, 10),
dialect: dialect,
}
if len(dialect.IdentityQuoting) > 0 {
l.identityRunes = dialect.IdentityQuoting
} else {
l.identityRunes = IdentityQuoting
}
l.init()
return l
}
|
go
|
func NewLexer(input string, dialect *Dialect) *Lexer {
// Three tokens of buffering is sufficient for all state functions.
l := &Lexer{
input: input,
state: LexDialectForStatement,
tokens: make(chan Token, 3),
stack: make([]NamedStateFn, 0, 10),
dialect: dialect,
}
if len(dialect.IdentityQuoting) > 0 {
l.identityRunes = dialect.IdentityQuoting
} else {
l.identityRunes = IdentityQuoting
}
l.init()
return l
}
|
[
"func",
"NewLexer",
"(",
"input",
"string",
",",
"dialect",
"*",
"Dialect",
")",
"*",
"Lexer",
"{",
"// Three tokens of buffering is sufficient for all state functions.",
"l",
":=",
"&",
"Lexer",
"{",
"input",
":",
"input",
",",
"state",
":",
"LexDialectForStatement",
",",
"tokens",
":",
"make",
"(",
"chan",
"Token",
",",
"3",
")",
",",
"stack",
":",
"make",
"(",
"[",
"]",
"NamedStateFn",
",",
"0",
",",
"10",
")",
",",
"dialect",
":",
"dialect",
",",
"}",
"\n",
"if",
"len",
"(",
"dialect",
".",
"IdentityQuoting",
")",
">",
"0",
"{",
"l",
".",
"identityRunes",
"=",
"dialect",
".",
"IdentityQuoting",
"\n",
"}",
"else",
"{",
"l",
".",
"identityRunes",
"=",
"IdentityQuoting",
"\n",
"}",
"\n",
"l",
".",
"init",
"(",
")",
"\n",
"return",
"l",
"\n",
"}"
] |
// NewLexer Creates a new lexer for the input string
|
[
"NewLexer",
"Creates",
"a",
"new",
"lexer",
"for",
"the",
"input",
"string"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/lex/lexer.go#L65-L81
|
20,494
|
araddon/qlbridge
|
lex/lexer.go
|
ErrMsg
|
func (l *Lexer) ErrMsg(t Token, msg string) error {
raw := l.RawInput()
if len(raw) == l.pos {
raw = ""
} else if len(raw) > t.Pos {
if t.Pos > 0 {
raw = raw[t.Pos-1:]
} else {
raw = raw[t.Pos:]
}
if len(raw) > 20 {
raw = raw[:19]
}
} else {
raw = ""
}
if len(msg) > 0 {
return fmt.Errorf("%s Got %s near: %s", msg, t.String(), raw)
}
return fmt.Errorf("Unrecognized input at Line %v Column %v %s", t.Line, t.Column, raw)
}
|
go
|
func (l *Lexer) ErrMsg(t Token, msg string) error {
raw := l.RawInput()
if len(raw) == l.pos {
raw = ""
} else if len(raw) > t.Pos {
if t.Pos > 0 {
raw = raw[t.Pos-1:]
} else {
raw = raw[t.Pos:]
}
if len(raw) > 20 {
raw = raw[:19]
}
} else {
raw = ""
}
if len(msg) > 0 {
return fmt.Errorf("%s Got %s near: %s", msg, t.String(), raw)
}
return fmt.Errorf("Unrecognized input at Line %v Column %v %s", t.Line, t.Column, raw)
}
|
[
"func",
"(",
"l",
"*",
"Lexer",
")",
"ErrMsg",
"(",
"t",
"Token",
",",
"msg",
"string",
")",
"error",
"{",
"raw",
":=",
"l",
".",
"RawInput",
"(",
")",
"\n",
"if",
"len",
"(",
"raw",
")",
"==",
"l",
".",
"pos",
"{",
"raw",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"if",
"len",
"(",
"raw",
")",
">",
"t",
".",
"Pos",
"{",
"if",
"t",
".",
"Pos",
">",
"0",
"{",
"raw",
"=",
"raw",
"[",
"t",
".",
"Pos",
"-",
"1",
":",
"]",
"\n",
"}",
"else",
"{",
"raw",
"=",
"raw",
"[",
"t",
".",
"Pos",
":",
"]",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"raw",
")",
">",
"20",
"{",
"raw",
"=",
"raw",
"[",
":",
"19",
"]",
"\n",
"}",
"\n",
"}",
"else",
"{",
"raw",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"len",
"(",
"msg",
")",
">",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"msg",
",",
"t",
".",
"String",
"(",
")",
",",
"raw",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
".",
"Line",
",",
"t",
".",
"Column",
",",
"raw",
")",
"\n",
"}"
] |
// ErrMsg an error message helper which provides context of where in input string
// the error is occuring, line, column, current token info.
|
[
"ErrMsg",
"an",
"error",
"message",
"helper",
"which",
"provides",
"context",
"of",
"where",
"in",
"input",
"string",
"the",
"error",
"is",
"occuring",
"line",
"column",
"current",
"token",
"info",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/lex/lexer.go#L120-L141
|
20,495
|
araddon/qlbridge
|
lex/lexer.go
|
NextToken
|
func (l *Lexer) NextToken() Token {
for {
//u.Debugf("token: start=%v pos=%v peek5=%s", l.start, l.pos, l.PeekX(5))
select {
case token := <-l.tokens:
return token
default:
if l.state == nil && len(l.stack) > 0 {
l.state = l.pop()
} else if l.state == nil {
return Token{T: TokenEOF, V: ""}
}
l.state = l.state(l)
}
}
}
|
go
|
func (l *Lexer) NextToken() Token {
for {
//u.Debugf("token: start=%v pos=%v peek5=%s", l.start, l.pos, l.PeekX(5))
select {
case token := <-l.tokens:
return token
default:
if l.state == nil && len(l.stack) > 0 {
l.state = l.pop()
} else if l.state == nil {
return Token{T: TokenEOF, V: ""}
}
l.state = l.state(l)
}
}
}
|
[
"func",
"(",
"l",
"*",
"Lexer",
")",
"NextToken",
"(",
")",
"Token",
"{",
"for",
"{",
"//u.Debugf(\"token: start=%v pos=%v peek5=%s\", l.start, l.pos, l.PeekX(5))",
"select",
"{",
"case",
"token",
":=",
"<-",
"l",
".",
"tokens",
":",
"return",
"token",
"\n",
"default",
":",
"if",
"l",
".",
"state",
"==",
"nil",
"&&",
"len",
"(",
"l",
".",
"stack",
")",
">",
"0",
"{",
"l",
".",
"state",
"=",
"l",
".",
"pop",
"(",
")",
"\n",
"}",
"else",
"if",
"l",
".",
"state",
"==",
"nil",
"{",
"return",
"Token",
"{",
"T",
":",
"TokenEOF",
",",
"V",
":",
"\"",
"\"",
"}",
"\n",
"}",
"\n",
"l",
".",
"state",
"=",
"l",
".",
"state",
"(",
"l",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// NextToken returns the next token from the input.
|
[
"NextToken",
"returns",
"the",
"next",
"token",
"from",
"the",
"input",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/lex/lexer.go#L144-L159
|
20,496
|
araddon/qlbridge
|
lex/lexer.go
|
Push
|
func (l *Lexer) Push(name string, state StateFn) {
debugf("push %d %v", len(l.stack)+1, name)
if len(l.stack) < 500 {
l.stack = append(l.stack, NamedStateFn{name, state})
} else {
out := ""
if len(l.input) > 200 {
out = strings.Replace(l.input[0:199], "\n", " ", -1)
} else {
out = strings.Replace(l.input, "\n", " ", -1)
}
u.LogThrottle(u.WARN, 10, "Gracefully refusing to add more LexExpression: %s", out)
}
}
|
go
|
func (l *Lexer) Push(name string, state StateFn) {
debugf("push %d %v", len(l.stack)+1, name)
if len(l.stack) < 500 {
l.stack = append(l.stack, NamedStateFn{name, state})
} else {
out := ""
if len(l.input) > 200 {
out = strings.Replace(l.input[0:199], "\n", " ", -1)
} else {
out = strings.Replace(l.input, "\n", " ", -1)
}
u.LogThrottle(u.WARN, 10, "Gracefully refusing to add more LexExpression: %s", out)
}
}
|
[
"func",
"(",
"l",
"*",
"Lexer",
")",
"Push",
"(",
"name",
"string",
",",
"state",
"StateFn",
")",
"{",
"debugf",
"(",
"\"",
"\"",
",",
"len",
"(",
"l",
".",
"stack",
")",
"+",
"1",
",",
"name",
")",
"\n",
"if",
"len",
"(",
"l",
".",
"stack",
")",
"<",
"500",
"{",
"l",
".",
"stack",
"=",
"append",
"(",
"l",
".",
"stack",
",",
"NamedStateFn",
"{",
"name",
",",
"state",
"}",
")",
"\n",
"}",
"else",
"{",
"out",
":=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"l",
".",
"input",
")",
">",
"200",
"{",
"out",
"=",
"strings",
".",
"Replace",
"(",
"l",
".",
"input",
"[",
"0",
":",
"199",
"]",
",",
"\"",
"\\n",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"}",
"else",
"{",
"out",
"=",
"strings",
".",
"Replace",
"(",
"l",
".",
"input",
",",
"\"",
"\\n",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"u",
".",
"LogThrottle",
"(",
"u",
".",
"WARN",
",",
"10",
",",
"\"",
"\"",
",",
"out",
")",
"\n",
"}",
"\n",
"}"
] |
// Push a named StateFn onto stack.
|
[
"Push",
"a",
"named",
"StateFn",
"onto",
"stack",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/lex/lexer.go#L162-L175
|
20,497
|
araddon/qlbridge
|
lex/lexer.go
|
Peek
|
func (l *Lexer) Peek() rune {
r := l.Next()
l.backup()
return r
}
|
go
|
func (l *Lexer) Peek() rune {
r := l.Next()
l.backup()
return r
}
|
[
"func",
"(",
"l",
"*",
"Lexer",
")",
"Peek",
"(",
")",
"rune",
"{",
"r",
":=",
"l",
".",
"Next",
"(",
")",
"\n",
"l",
".",
"backup",
"(",
")",
"\n",
"return",
"r",
"\n",
"}"
] |
// Peek returns but does not consume the next rune in the input.
|
[
"Peek",
"returns",
"but",
"does",
"not",
"consume",
"the",
"next",
"rune",
"in",
"the",
"input",
"."
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/lex/lexer.go#L234-L238
|
20,498
|
araddon/qlbridge
|
lex/lexer.go
|
PeekX
|
func (l *Lexer) PeekX(x int) string {
if l.pos+x > len(l.input) {
return l.input[l.pos:]
}
return l.input[l.pos : l.pos+x]
}
|
go
|
func (l *Lexer) PeekX(x int) string {
if l.pos+x > len(l.input) {
return l.input[l.pos:]
}
return l.input[l.pos : l.pos+x]
}
|
[
"func",
"(",
"l",
"*",
"Lexer",
")",
"PeekX",
"(",
"x",
"int",
")",
"string",
"{",
"if",
"l",
".",
"pos",
"+",
"x",
">",
"len",
"(",
"l",
".",
"input",
")",
"{",
"return",
"l",
".",
"input",
"[",
"l",
".",
"pos",
":",
"]",
"\n",
"}",
"\n",
"return",
"l",
".",
"input",
"[",
"l",
".",
"pos",
":",
"l",
".",
"pos",
"+",
"x",
"]",
"\n",
"}"
] |
// PeekX grab the next x characters without consuming
|
[
"PeekX",
"grab",
"the",
"next",
"x",
"characters",
"without",
"consuming"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/lex/lexer.go#L241-L246
|
20,499
|
araddon/qlbridge
|
lex/lexer.go
|
peekRunePast
|
func (l *Lexer) peekRunePast(skip int) rune {
if l.pos+skip+1 > len(l.input) {
return rune(0)
}
for ; skip < len(l.input)-l.pos; skip++ {
r, ri := utf8.DecodeRuneInString(l.input[l.pos+skip:])
if ri != 1 {
skip += (ri - 1)
}
if !unicode.IsSpace(r) {
return r
}
}
return rune(0)
}
|
go
|
func (l *Lexer) peekRunePast(skip int) rune {
if l.pos+skip+1 > len(l.input) {
return rune(0)
}
for ; skip < len(l.input)-l.pos; skip++ {
r, ri := utf8.DecodeRuneInString(l.input[l.pos+skip:])
if ri != 1 {
skip += (ri - 1)
}
if !unicode.IsSpace(r) {
return r
}
}
return rune(0)
}
|
[
"func",
"(",
"l",
"*",
"Lexer",
")",
"peekRunePast",
"(",
"skip",
"int",
")",
"rune",
"{",
"if",
"l",
".",
"pos",
"+",
"skip",
"+",
"1",
">",
"len",
"(",
"l",
".",
"input",
")",
"{",
"return",
"rune",
"(",
"0",
")",
"\n",
"}",
"\n\n",
"for",
";",
"skip",
"<",
"len",
"(",
"l",
".",
"input",
")",
"-",
"l",
".",
"pos",
";",
"skip",
"++",
"{",
"r",
",",
"ri",
":=",
"utf8",
".",
"DecodeRuneInString",
"(",
"l",
".",
"input",
"[",
"l",
".",
"pos",
"+",
"skip",
":",
"]",
")",
"\n",
"if",
"ri",
"!=",
"1",
"{",
"skip",
"+=",
"(",
"ri",
"-",
"1",
")",
"\n",
"}",
"\n",
"if",
"!",
"unicode",
".",
"IsSpace",
"(",
"r",
")",
"{",
"return",
"r",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"rune",
"(",
"0",
")",
"\n",
"}"
] |
// get single character PAST
|
[
"get",
"single",
"character",
"PAST"
] |
23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac
|
https://github.com/araddon/qlbridge/blob/23bb6a4e8c9e82ba86952b8a1469ccff1bb296ac/lex/lexer.go#L249-L264
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.