repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
olivere/elastic | xpack_security_delete_role_mapping.go | Name | func (s *XPackSecurityDeleteRoleMappingService) Name(name string) *XPackSecurityDeleteRoleMappingService {
s.name = name
return s
} | go | func (s *XPackSecurityDeleteRoleMappingService) Name(name string) *XPackSecurityDeleteRoleMappingService {
s.name = name
return s
} | [
"func",
"(",
"s",
"*",
"XPackSecurityDeleteRoleMappingService",
")",
"Name",
"(",
"name",
"string",
")",
"*",
"XPackSecurityDeleteRoleMappingService",
"{",
"s",
".",
"name",
"=",
"name",
"\n",
"return",
"s",
"\n",
"}"
] | // Name is name of the role mapping to delete. | [
"Name",
"is",
"name",
"of",
"the",
"role",
"mapping",
"to",
"delete",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/xpack_security_delete_role_mapping.go#L32-L35 | train |
olivere/elastic | bulk_processor.go | NewBulkProcessorService | func NewBulkProcessorService(client *Client) *BulkProcessorService {
return &BulkProcessorService{
c: client,
numWorkers: 1,
bulkActions: 1000,
bulkSize: 5 << 20, // 5 MB
backoff: NewExponentialBackoff(
time.Duration(200)*time.Millisecond,
time.Duration(10000)*time.Millisecond,
),
retryItemStatusCodes: defaultRetryItemStatusCodes,
}
} | go | func NewBulkProcessorService(client *Client) *BulkProcessorService {
return &BulkProcessorService{
c: client,
numWorkers: 1,
bulkActions: 1000,
bulkSize: 5 << 20, // 5 MB
backoff: NewExponentialBackoff(
time.Duration(200)*time.Millisecond,
time.Duration(10000)*time.Millisecond,
),
retryItemStatusCodes: defaultRetryItemStatusCodes,
}
} | [
"func",
"NewBulkProcessorService",
"(",
"client",
"*",
"Client",
")",
"*",
"BulkProcessorService",
"{",
"return",
"&",
"BulkProcessorService",
"{",
"c",
":",
"client",
",",
"numWorkers",
":",
"1",
",",
"bulkActions",
":",
"1000",
",",
"bulkSize",
":",
"5",
"<<",
"20",
",",
"// 5 MB",
"backoff",
":",
"NewExponentialBackoff",
"(",
"time",
".",
"Duration",
"(",
"200",
")",
"*",
"time",
".",
"Millisecond",
",",
"time",
".",
"Duration",
"(",
"10000",
")",
"*",
"time",
".",
"Millisecond",
",",
")",
",",
"retryItemStatusCodes",
":",
"defaultRetryItemStatusCodes",
",",
"}",
"\n",
"}"
] | // NewBulkProcessorService creates a new BulkProcessorService. | [
"NewBulkProcessorService",
"creates",
"a",
"new",
"BulkProcessorService",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L58-L70 | train |
olivere/elastic | bulk_processor.go | Before | func (s *BulkProcessorService) Before(fn BulkBeforeFunc) *BulkProcessorService {
s.beforeFn = fn
return s
} | go | func (s *BulkProcessorService) Before(fn BulkBeforeFunc) *BulkProcessorService {
s.beforeFn = fn
return s
} | [
"func",
"(",
"s",
"*",
"BulkProcessorService",
")",
"Before",
"(",
"fn",
"BulkBeforeFunc",
")",
"*",
"BulkProcessorService",
"{",
"s",
".",
"beforeFn",
"=",
"fn",
"\n",
"return",
"s",
"\n",
"}"
] | // Before specifies a function to be executed before bulk requests get committed
// to Elasticsearch. | [
"Before",
"specifies",
"a",
"function",
"to",
"be",
"executed",
"before",
"bulk",
"requests",
"get",
"committed",
"to",
"Elasticsearch",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L82-L85 | train |
olivere/elastic | bulk_processor.go | After | func (s *BulkProcessorService) After(fn BulkAfterFunc) *BulkProcessorService {
s.afterFn = fn
return s
} | go | func (s *BulkProcessorService) After(fn BulkAfterFunc) *BulkProcessorService {
s.afterFn = fn
return s
} | [
"func",
"(",
"s",
"*",
"BulkProcessorService",
")",
"After",
"(",
"fn",
"BulkAfterFunc",
")",
"*",
"BulkProcessorService",
"{",
"s",
".",
"afterFn",
"=",
"fn",
"\n",
"return",
"s",
"\n",
"}"
] | // After specifies a function to be executed when bulk requests have been
// committed to Elasticsearch. The After callback executes both when the
// commit was successful as well as on failures. | [
"After",
"specifies",
"a",
"function",
"to",
"be",
"executed",
"when",
"bulk",
"requests",
"have",
"been",
"committed",
"to",
"Elasticsearch",
".",
"The",
"After",
"callback",
"executes",
"both",
"when",
"the",
"commit",
"was",
"successful",
"as",
"well",
"as",
"on",
"failures",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L90-L93 | train |
olivere/elastic | bulk_processor.go | Name | func (s *BulkProcessorService) Name(name string) *BulkProcessorService {
s.name = name
return s
} | go | func (s *BulkProcessorService) Name(name string) *BulkProcessorService {
s.name = name
return s
} | [
"func",
"(",
"s",
"*",
"BulkProcessorService",
")",
"Name",
"(",
"name",
"string",
")",
"*",
"BulkProcessorService",
"{",
"s",
".",
"name",
"=",
"name",
"\n",
"return",
"s",
"\n",
"}"
] | // Name is an optional name to identify this bulk processor. | [
"Name",
"is",
"an",
"optional",
"name",
"to",
"identify",
"this",
"bulk",
"processor",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L96-L99 | train |
olivere/elastic | bulk_processor.go | Workers | func (s *BulkProcessorService) Workers(num int) *BulkProcessorService {
s.numWorkers = num
return s
} | go | func (s *BulkProcessorService) Workers(num int) *BulkProcessorService {
s.numWorkers = num
return s
} | [
"func",
"(",
"s",
"*",
"BulkProcessorService",
")",
"Workers",
"(",
"num",
"int",
")",
"*",
"BulkProcessorService",
"{",
"s",
".",
"numWorkers",
"=",
"num",
"\n",
"return",
"s",
"\n",
"}"
] | // Workers is the number of concurrent workers allowed to be
// executed. Defaults to 1 and must be greater or equal to 1. | [
"Workers",
"is",
"the",
"number",
"of",
"concurrent",
"workers",
"allowed",
"to",
"be",
"executed",
".",
"Defaults",
"to",
"1",
"and",
"must",
"be",
"greater",
"or",
"equal",
"to",
"1",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L103-L106 | train |
olivere/elastic | bulk_processor.go | BulkActions | func (s *BulkProcessorService) BulkActions(bulkActions int) *BulkProcessorService {
s.bulkActions = bulkActions
return s
} | go | func (s *BulkProcessorService) BulkActions(bulkActions int) *BulkProcessorService {
s.bulkActions = bulkActions
return s
} | [
"func",
"(",
"s",
"*",
"BulkProcessorService",
")",
"BulkActions",
"(",
"bulkActions",
"int",
")",
"*",
"BulkProcessorService",
"{",
"s",
".",
"bulkActions",
"=",
"bulkActions",
"\n",
"return",
"s",
"\n",
"}"
] | // BulkActions specifies when to flush based on the number of actions
// currently added. Defaults to 1000 and can be set to -1 to be disabled. | [
"BulkActions",
"specifies",
"when",
"to",
"flush",
"based",
"on",
"the",
"number",
"of",
"actions",
"currently",
"added",
".",
"Defaults",
"to",
"1000",
"and",
"can",
"be",
"set",
"to",
"-",
"1",
"to",
"be",
"disabled",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L110-L113 | train |
olivere/elastic | bulk_processor.go | FlushInterval | func (s *BulkProcessorService) FlushInterval(interval time.Duration) *BulkProcessorService {
s.flushInterval = interval
return s
} | go | func (s *BulkProcessorService) FlushInterval(interval time.Duration) *BulkProcessorService {
s.flushInterval = interval
return s
} | [
"func",
"(",
"s",
"*",
"BulkProcessorService",
")",
"FlushInterval",
"(",
"interval",
"time",
".",
"Duration",
")",
"*",
"BulkProcessorService",
"{",
"s",
".",
"flushInterval",
"=",
"interval",
"\n",
"return",
"s",
"\n",
"}"
] | // FlushInterval specifies when to flush at the end of the given interval.
// This is disabled by default. If you want the bulk processor to
// operate completely asynchronously, set both BulkActions and BulkSize to
// -1 and set the FlushInterval to a meaningful interval. | [
"FlushInterval",
"specifies",
"when",
"to",
"flush",
"at",
"the",
"end",
"of",
"the",
"given",
"interval",
".",
"This",
"is",
"disabled",
"by",
"default",
".",
"If",
"you",
"want",
"the",
"bulk",
"processor",
"to",
"operate",
"completely",
"asynchronously",
"set",
"both",
"BulkActions",
"and",
"BulkSize",
"to",
"-",
"1",
"and",
"set",
"the",
"FlushInterval",
"to",
"a",
"meaningful",
"interval",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L126-L129 | train |
olivere/elastic | bulk_processor.go | Stats | func (s *BulkProcessorService) Stats(wantStats bool) *BulkProcessorService {
s.wantStats = wantStats
return s
} | go | func (s *BulkProcessorService) Stats(wantStats bool) *BulkProcessorService {
s.wantStats = wantStats
return s
} | [
"func",
"(",
"s",
"*",
"BulkProcessorService",
")",
"Stats",
"(",
"wantStats",
"bool",
")",
"*",
"BulkProcessorService",
"{",
"s",
".",
"wantStats",
"=",
"wantStats",
"\n",
"return",
"s",
"\n",
"}"
] | // Stats tells bulk processor to gather stats while running.
// Use Stats to return the stats. This is disabled by default. | [
"Stats",
"tells",
"bulk",
"processor",
"to",
"gather",
"stats",
"while",
"running",
".",
"Use",
"Stats",
"to",
"return",
"the",
"stats",
".",
"This",
"is",
"disabled",
"by",
"default",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L133-L136 | train |
olivere/elastic | bulk_processor.go | Backoff | func (s *BulkProcessorService) Backoff(backoff Backoff) *BulkProcessorService {
s.backoff = backoff
return s
} | go | func (s *BulkProcessorService) Backoff(backoff Backoff) *BulkProcessorService {
s.backoff = backoff
return s
} | [
"func",
"(",
"s",
"*",
"BulkProcessorService",
")",
"Backoff",
"(",
"backoff",
"Backoff",
")",
"*",
"BulkProcessorService",
"{",
"s",
".",
"backoff",
"=",
"backoff",
"\n",
"return",
"s",
"\n",
"}"
] | // Backoff sets the backoff strategy to use for errors. | [
"Backoff",
"sets",
"the",
"backoff",
"strategy",
"to",
"use",
"for",
"errors",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L139-L142 | train |
olivere/elastic | bulk_processor.go | RetryItemStatusCodes | func (s *BulkProcessorService) RetryItemStatusCodes(retryItemStatusCodes ...int) *BulkProcessorService {
s.retryItemStatusCodes = retryItemStatusCodes
return s
} | go | func (s *BulkProcessorService) RetryItemStatusCodes(retryItemStatusCodes ...int) *BulkProcessorService {
s.retryItemStatusCodes = retryItemStatusCodes
return s
} | [
"func",
"(",
"s",
"*",
"BulkProcessorService",
")",
"RetryItemStatusCodes",
"(",
"retryItemStatusCodes",
"...",
"int",
")",
"*",
"BulkProcessorService",
"{",
"s",
".",
"retryItemStatusCodes",
"=",
"retryItemStatusCodes",
"\n",
"return",
"s",
"\n",
"}"
] | // RetryItemStatusCodes sets an array of status codes that indicate that a bulk
// response line item should be retried. | [
"RetryItemStatusCodes",
"sets",
"an",
"array",
"of",
"status",
"codes",
"that",
"indicate",
"that",
"a",
"bulk",
"response",
"line",
"item",
"should",
"be",
"retried",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L146-L149 | train |
olivere/elastic | bulk_processor.go | newBulkProcessorStats | func newBulkProcessorStats(workers int) *BulkProcessorStats {
stats := &BulkProcessorStats{
Workers: make([]*BulkProcessorWorkerStats, workers),
}
for i := 0; i < workers; i++ {
stats.Workers[i] = &BulkProcessorWorkerStats{}
}
return stats
} | go | func newBulkProcessorStats(workers int) *BulkProcessorStats {
stats := &BulkProcessorStats{
Workers: make([]*BulkProcessorWorkerStats, workers),
}
for i := 0; i < workers; i++ {
stats.Workers[i] = &BulkProcessorWorkerStats{}
}
return stats
} | [
"func",
"newBulkProcessorStats",
"(",
"workers",
"int",
")",
"*",
"BulkProcessorStats",
"{",
"stats",
":=",
"&",
"BulkProcessorStats",
"{",
"Workers",
":",
"make",
"(",
"[",
"]",
"*",
"BulkProcessorWorkerStats",
",",
"workers",
")",
",",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"workers",
";",
"i",
"++",
"{",
"stats",
".",
"Workers",
"[",
"i",
"]",
"=",
"&",
"BulkProcessorWorkerStats",
"{",
"}",
"\n",
"}",
"\n",
"return",
"stats",
"\n",
"}"
] | // newBulkProcessorStats initializes and returns a BulkProcessorStats struct. | [
"newBulkProcessorStats",
"initializes",
"and",
"returns",
"a",
"BulkProcessorStats",
"struct",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L217-L225 | train |
olivere/elastic | bulk_processor.go | Start | func (p *BulkProcessor) Start(ctx context.Context) error {
p.startedMu.Lock()
defer p.startedMu.Unlock()
if p.started {
return nil
}
// We must have at least one worker.
if p.numWorkers < 1 {
p.numWorkers = 1
}
p.requestsC = make(chan BulkableRequest)
p.executionId = 0
p.stats = newBulkProcessorStats(p.numWorkers)
p.stopReconnC = make(chan struct{})
// Create and start up workers.
p.workers = make([]*bulkWorker, p.numWorkers)
for i := 0; i < p.numWorkers; i++ {
p.workerWg.Add(1)
p.workers[i] = newBulkWorker(p, i)
go p.workers[i].work(ctx)
}
// Start the ticker for flush (if enabled)
if int64(p.flushInterval) > 0 {
p.flusherStopC = make(chan struct{})
go p.flusher(p.flushInterval)
}
p.started = true
return nil
} | go | func (p *BulkProcessor) Start(ctx context.Context) error {
p.startedMu.Lock()
defer p.startedMu.Unlock()
if p.started {
return nil
}
// We must have at least one worker.
if p.numWorkers < 1 {
p.numWorkers = 1
}
p.requestsC = make(chan BulkableRequest)
p.executionId = 0
p.stats = newBulkProcessorStats(p.numWorkers)
p.stopReconnC = make(chan struct{})
// Create and start up workers.
p.workers = make([]*bulkWorker, p.numWorkers)
for i := 0; i < p.numWorkers; i++ {
p.workerWg.Add(1)
p.workers[i] = newBulkWorker(p, i)
go p.workers[i].work(ctx)
}
// Start the ticker for flush (if enabled)
if int64(p.flushInterval) > 0 {
p.flusherStopC = make(chan struct{})
go p.flusher(p.flushInterval)
}
p.started = true
return nil
} | [
"func",
"(",
"p",
"*",
"BulkProcessor",
")",
"Start",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"p",
".",
"startedMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"startedMu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"p",
".",
"started",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// We must have at least one worker.",
"if",
"p",
".",
"numWorkers",
"<",
"1",
"{",
"p",
".",
"numWorkers",
"=",
"1",
"\n",
"}",
"\n\n",
"p",
".",
"requestsC",
"=",
"make",
"(",
"chan",
"BulkableRequest",
")",
"\n",
"p",
".",
"executionId",
"=",
"0",
"\n",
"p",
".",
"stats",
"=",
"newBulkProcessorStats",
"(",
"p",
".",
"numWorkers",
")",
"\n",
"p",
".",
"stopReconnC",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n\n",
"// Create and start up workers.",
"p",
".",
"workers",
"=",
"make",
"(",
"[",
"]",
"*",
"bulkWorker",
",",
"p",
".",
"numWorkers",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"p",
".",
"numWorkers",
";",
"i",
"++",
"{",
"p",
".",
"workerWg",
".",
"Add",
"(",
"1",
")",
"\n",
"p",
".",
"workers",
"[",
"i",
"]",
"=",
"newBulkWorker",
"(",
"p",
",",
"i",
")",
"\n",
"go",
"p",
".",
"workers",
"[",
"i",
"]",
".",
"work",
"(",
"ctx",
")",
"\n",
"}",
"\n\n",
"// Start the ticker for flush (if enabled)",
"if",
"int64",
"(",
"p",
".",
"flushInterval",
")",
">",
"0",
"{",
"p",
".",
"flusherStopC",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"p",
".",
"flusher",
"(",
"p",
".",
"flushInterval",
")",
"\n",
"}",
"\n\n",
"p",
".",
"started",
"=",
"true",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Start starts the bulk processor. If the processor is already started,
// nil is returned. | [
"Start",
"starts",
"the",
"bulk",
"processor",
".",
"If",
"the",
"processor",
"is",
"already",
"started",
"nil",
"is",
"returned",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L313-L348 | train |
olivere/elastic | bulk_processor.go | Close | func (p *BulkProcessor) Close() error {
p.startedMu.Lock()
defer p.startedMu.Unlock()
// Already stopped? Do nothing.
if !p.started {
return nil
}
// Tell connection checkers to stop
if p.stopReconnC != nil {
close(p.stopReconnC)
p.stopReconnC = nil
}
// Stop flusher (if enabled)
if p.flusherStopC != nil {
p.flusherStopC <- struct{}{}
<-p.flusherStopC
close(p.flusherStopC)
p.flusherStopC = nil
}
// Stop all workers.
close(p.requestsC)
p.workerWg.Wait()
p.started = false
return nil
} | go | func (p *BulkProcessor) Close() error {
p.startedMu.Lock()
defer p.startedMu.Unlock()
// Already stopped? Do nothing.
if !p.started {
return nil
}
// Tell connection checkers to stop
if p.stopReconnC != nil {
close(p.stopReconnC)
p.stopReconnC = nil
}
// Stop flusher (if enabled)
if p.flusherStopC != nil {
p.flusherStopC <- struct{}{}
<-p.flusherStopC
close(p.flusherStopC)
p.flusherStopC = nil
}
// Stop all workers.
close(p.requestsC)
p.workerWg.Wait()
p.started = false
return nil
} | [
"func",
"(",
"p",
"*",
"BulkProcessor",
")",
"Close",
"(",
")",
"error",
"{",
"p",
".",
"startedMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"startedMu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Already stopped? Do nothing.",
"if",
"!",
"p",
".",
"started",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Tell connection checkers to stop",
"if",
"p",
".",
"stopReconnC",
"!=",
"nil",
"{",
"close",
"(",
"p",
".",
"stopReconnC",
")",
"\n",
"p",
".",
"stopReconnC",
"=",
"nil",
"\n",
"}",
"\n\n",
"// Stop flusher (if enabled)",
"if",
"p",
".",
"flusherStopC",
"!=",
"nil",
"{",
"p",
".",
"flusherStopC",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n",
"<-",
"p",
".",
"flusherStopC",
"\n",
"close",
"(",
"p",
".",
"flusherStopC",
")",
"\n",
"p",
".",
"flusherStopC",
"=",
"nil",
"\n",
"}",
"\n\n",
"// Stop all workers.",
"close",
"(",
"p",
".",
"requestsC",
")",
"\n",
"p",
".",
"workerWg",
".",
"Wait",
"(",
")",
"\n\n",
"p",
".",
"started",
"=",
"false",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Close stops the bulk processor previously started with Do.
// If it is already stopped, this is a no-op and nil is returned.
//
// By implementing Close, BulkProcessor implements the io.Closer interface. | [
"Close",
"stops",
"the",
"bulk",
"processor",
"previously",
"started",
"with",
"Do",
".",
"If",
"it",
"is",
"already",
"stopped",
"this",
"is",
"a",
"no",
"-",
"op",
"and",
"nil",
"is",
"returned",
".",
"By",
"implementing",
"Close",
"BulkProcessor",
"implements",
"the",
"io",
".",
"Closer",
"interface",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L359-L389 | train |
olivere/elastic | bulk_processor.go | Flush | func (p *BulkProcessor) Flush() error {
p.statsMu.Lock()
p.stats.Flushed++
p.statsMu.Unlock()
for _, w := range p.workers {
w.flushC <- struct{}{}
<-w.flushAckC // wait for completion
}
return nil
} | go | func (p *BulkProcessor) Flush() error {
p.statsMu.Lock()
p.stats.Flushed++
p.statsMu.Unlock()
for _, w := range p.workers {
w.flushC <- struct{}{}
<-w.flushAckC // wait for completion
}
return nil
} | [
"func",
"(",
"p",
"*",
"BulkProcessor",
")",
"Flush",
"(",
")",
"error",
"{",
"p",
".",
"statsMu",
".",
"Lock",
"(",
")",
"\n",
"p",
".",
"stats",
".",
"Flushed",
"++",
"\n",
"p",
".",
"statsMu",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"_",
",",
"w",
":=",
"range",
"p",
".",
"workers",
"{",
"w",
".",
"flushC",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n",
"<-",
"w",
".",
"flushAckC",
"// wait for completion",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Flush manually asks all workers to commit their outstanding requests.
// It returns only when all workers acknowledge completion. | [
"Flush",
"manually",
"asks",
"all",
"workers",
"to",
"commit",
"their",
"outstanding",
"requests",
".",
"It",
"returns",
"only",
"when",
"all",
"workers",
"acknowledge",
"completion",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L409-L419 | train |
olivere/elastic | bulk_processor.go | flusher | func (p *BulkProcessor) flusher(interval time.Duration) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
select {
case <-ticker.C: // Periodic flush
p.Flush() // TODO swallow errors here?
case <-p.flusherStopC:
p.flusherStopC <- struct{}{}
return
}
}
} | go | func (p *BulkProcessor) flusher(interval time.Duration) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
select {
case <-ticker.C: // Periodic flush
p.Flush() // TODO swallow errors here?
case <-p.flusherStopC:
p.flusherStopC <- struct{}{}
return
}
}
} | [
"func",
"(",
"p",
"*",
"BulkProcessor",
")",
"flusher",
"(",
"interval",
"time",
".",
"Duration",
")",
"{",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"interval",
")",
"\n",
"defer",
"ticker",
".",
"Stop",
"(",
")",
"\n\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"ticker",
".",
"C",
":",
"// Periodic flush",
"p",
".",
"Flush",
"(",
")",
"// TODO swallow errors here?",
"\n\n",
"case",
"<-",
"p",
".",
"flusherStopC",
":",
"p",
".",
"flusherStopC",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // flusher is a single goroutine that periodically asks all workers to
// commit their outstanding bulk requests. It is only started if
// FlushInterval is greater than 0. | [
"flusher",
"is",
"a",
"single",
"goroutine",
"that",
"periodically",
"asks",
"all",
"workers",
"to",
"commit",
"their",
"outstanding",
"bulk",
"requests",
".",
"It",
"is",
"only",
"started",
"if",
"FlushInterval",
"is",
"greater",
"than",
"0",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L424-L438 | train |
olivere/elastic | bulk_processor.go | newBulkWorker | func newBulkWorker(p *BulkProcessor, i int) *bulkWorker {
return &bulkWorker{
p: p,
i: i,
bulkActions: p.bulkActions,
bulkSize: p.bulkSize,
service: NewBulkService(p.c),
flushC: make(chan struct{}),
flushAckC: make(chan struct{}),
}
} | go | func newBulkWorker(p *BulkProcessor, i int) *bulkWorker {
return &bulkWorker{
p: p,
i: i,
bulkActions: p.bulkActions,
bulkSize: p.bulkSize,
service: NewBulkService(p.c),
flushC: make(chan struct{}),
flushAckC: make(chan struct{}),
}
} | [
"func",
"newBulkWorker",
"(",
"p",
"*",
"BulkProcessor",
",",
"i",
"int",
")",
"*",
"bulkWorker",
"{",
"return",
"&",
"bulkWorker",
"{",
"p",
":",
"p",
",",
"i",
":",
"i",
",",
"bulkActions",
":",
"p",
".",
"bulkActions",
",",
"bulkSize",
":",
"p",
".",
"bulkSize",
",",
"service",
":",
"NewBulkService",
"(",
"p",
".",
"c",
")",
",",
"flushC",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"flushAckC",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"}",
"\n",
"}"
] | // newBulkWorker creates a new bulkWorker instance. | [
"newBulkWorker",
"creates",
"a",
"new",
"bulkWorker",
"instance",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L456-L466 | train |
olivere/elastic | bulk_processor.go | work | func (w *bulkWorker) work(ctx context.Context) {
defer func() {
w.p.workerWg.Done()
close(w.flushAckC)
close(w.flushC)
}()
var stop bool
for !stop {
var err error
select {
case req, open := <-w.p.requestsC:
if open {
// Received a new request
if _, err = req.Source(); err == nil {
w.service.Add(req)
if w.commitRequired() {
err = w.commit(ctx)
}
}
} else {
// Channel closed: Stop.
stop = true
if w.service.NumberOfActions() > 0 {
err = w.commit(ctx)
}
}
case <-w.flushC:
// Commit outstanding requests
if w.service.NumberOfActions() > 0 {
err = w.commit(ctx)
}
w.flushAckC <- struct{}{}
}
if err != nil {
w.p.c.errorf("elastic: bulk processor %q was unable to perform work: %v", w.p.name, err)
if !stop {
waitForActive := func() {
// Add back pressure to prevent Add calls from filling up the request queue
ready := make(chan struct{})
go w.waitForActiveConnection(ready)
<-ready
}
if _, ok := err.(net.Error); ok {
waitForActive()
} else if IsConnErr(err) {
waitForActive()
}
}
}
}
} | go | func (w *bulkWorker) work(ctx context.Context) {
defer func() {
w.p.workerWg.Done()
close(w.flushAckC)
close(w.flushC)
}()
var stop bool
for !stop {
var err error
select {
case req, open := <-w.p.requestsC:
if open {
// Received a new request
if _, err = req.Source(); err == nil {
w.service.Add(req)
if w.commitRequired() {
err = w.commit(ctx)
}
}
} else {
// Channel closed: Stop.
stop = true
if w.service.NumberOfActions() > 0 {
err = w.commit(ctx)
}
}
case <-w.flushC:
// Commit outstanding requests
if w.service.NumberOfActions() > 0 {
err = w.commit(ctx)
}
w.flushAckC <- struct{}{}
}
if err != nil {
w.p.c.errorf("elastic: bulk processor %q was unable to perform work: %v", w.p.name, err)
if !stop {
waitForActive := func() {
// Add back pressure to prevent Add calls from filling up the request queue
ready := make(chan struct{})
go w.waitForActiveConnection(ready)
<-ready
}
if _, ok := err.(net.Error); ok {
waitForActive()
} else if IsConnErr(err) {
waitForActive()
}
}
}
}
} | [
"func",
"(",
"w",
"*",
"bulkWorker",
")",
"work",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"w",
".",
"p",
".",
"workerWg",
".",
"Done",
"(",
")",
"\n",
"close",
"(",
"w",
".",
"flushAckC",
")",
"\n",
"close",
"(",
"w",
".",
"flushC",
")",
"\n",
"}",
"(",
")",
"\n\n",
"var",
"stop",
"bool",
"\n",
"for",
"!",
"stop",
"{",
"var",
"err",
"error",
"\n",
"select",
"{",
"case",
"req",
",",
"open",
":=",
"<-",
"w",
".",
"p",
".",
"requestsC",
":",
"if",
"open",
"{",
"// Received a new request",
"if",
"_",
",",
"err",
"=",
"req",
".",
"Source",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"w",
".",
"service",
".",
"Add",
"(",
"req",
")",
"\n",
"if",
"w",
".",
"commitRequired",
"(",
")",
"{",
"err",
"=",
"w",
".",
"commit",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// Channel closed: Stop.",
"stop",
"=",
"true",
"\n",
"if",
"w",
".",
"service",
".",
"NumberOfActions",
"(",
")",
">",
"0",
"{",
"err",
"=",
"w",
".",
"commit",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"case",
"<-",
"w",
".",
"flushC",
":",
"// Commit outstanding requests",
"if",
"w",
".",
"service",
".",
"NumberOfActions",
"(",
")",
">",
"0",
"{",
"err",
"=",
"w",
".",
"commit",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"w",
".",
"flushAckC",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"w",
".",
"p",
".",
"c",
".",
"errorf",
"(",
"\"",
"\"",
",",
"w",
".",
"p",
".",
"name",
",",
"err",
")",
"\n",
"if",
"!",
"stop",
"{",
"waitForActive",
":=",
"func",
"(",
")",
"{",
"// Add back pressure to prevent Add calls from filling up the request queue",
"ready",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"w",
".",
"waitForActiveConnection",
"(",
"ready",
")",
"\n",
"<-",
"ready",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"net",
".",
"Error",
")",
";",
"ok",
"{",
"waitForActive",
"(",
")",
"\n",
"}",
"else",
"if",
"IsConnErr",
"(",
"err",
")",
"{",
"waitForActive",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // work waits for bulk requests and manual flush calls on the respective
// channels and is invoked as a goroutine when the bulk processor is started. | [
"work",
"waits",
"for",
"bulk",
"requests",
"and",
"manual",
"flush",
"calls",
"on",
"the",
"respective",
"channels",
"and",
"is",
"invoked",
"as",
"a",
"goroutine",
"when",
"the",
"bulk",
"processor",
"is",
"started",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L470-L522 | train |
olivere/elastic | bulk_processor.go | commit | func (w *bulkWorker) commit(ctx context.Context) error {
var res *BulkResponse
// commitFunc will commit bulk requests and, on failure, be retried
// via exponential backoff
commitFunc := func() error {
var err error
// Save requests because they will be reset in service.Do
reqs := w.service.requests
res, err = w.service.Do(ctx)
if err == nil {
// Overall bulk request was OK. But each bulk response item also has a status
if w.p.retryItemStatusCodes != nil && len(w.p.retryItemStatusCodes) > 0 {
// Check res.Items since some might be soft failures
if res.Items != nil && res.Errors {
// res.Items will be 1 to 1 with reqs in same order
for i, item := range res.Items {
for _, result := range item {
if _, found := w.p.retryItemStatusCodes[result.Status]; found {
w.service.Add(reqs[i])
if err == nil {
err = ErrBulkItemRetry
}
}
}
}
}
}
}
return err
}
// notifyFunc will be called if retry fails
notifyFunc := func(err error) {
w.p.c.errorf("elastic: bulk processor %q failed but may retry: %v", w.p.name, err)
}
id := atomic.AddInt64(&w.p.executionId, 1)
// Update # documents in queue before eventual retries
w.p.statsMu.Lock()
if w.p.wantStats {
w.p.stats.Workers[w.i].Queued = int64(len(w.service.requests))
}
w.p.statsMu.Unlock()
// Save requests because they will be reset in commitFunc
reqs := w.service.requests
// Invoke before callback
if w.p.beforeFn != nil {
w.p.beforeFn(id, reqs)
}
// Commit bulk requests
err := RetryNotify(commitFunc, w.p.backoff, notifyFunc)
w.updateStats(res)
if err != nil {
w.p.c.errorf("elastic: bulk processor %q failed: %v", w.p.name, err)
}
// Invoke after callback
if w.p.afterFn != nil {
w.p.afterFn(id, reqs, res, err)
}
return err
} | go | func (w *bulkWorker) commit(ctx context.Context) error {
var res *BulkResponse
// commitFunc will commit bulk requests and, on failure, be retried
// via exponential backoff
commitFunc := func() error {
var err error
// Save requests because they will be reset in service.Do
reqs := w.service.requests
res, err = w.service.Do(ctx)
if err == nil {
// Overall bulk request was OK. But each bulk response item also has a status
if w.p.retryItemStatusCodes != nil && len(w.p.retryItemStatusCodes) > 0 {
// Check res.Items since some might be soft failures
if res.Items != nil && res.Errors {
// res.Items will be 1 to 1 with reqs in same order
for i, item := range res.Items {
for _, result := range item {
if _, found := w.p.retryItemStatusCodes[result.Status]; found {
w.service.Add(reqs[i])
if err == nil {
err = ErrBulkItemRetry
}
}
}
}
}
}
}
return err
}
// notifyFunc will be called if retry fails
notifyFunc := func(err error) {
w.p.c.errorf("elastic: bulk processor %q failed but may retry: %v", w.p.name, err)
}
id := atomic.AddInt64(&w.p.executionId, 1)
// Update # documents in queue before eventual retries
w.p.statsMu.Lock()
if w.p.wantStats {
w.p.stats.Workers[w.i].Queued = int64(len(w.service.requests))
}
w.p.statsMu.Unlock()
// Save requests because they will be reset in commitFunc
reqs := w.service.requests
// Invoke before callback
if w.p.beforeFn != nil {
w.p.beforeFn(id, reqs)
}
// Commit bulk requests
err := RetryNotify(commitFunc, w.p.backoff, notifyFunc)
w.updateStats(res)
if err != nil {
w.p.c.errorf("elastic: bulk processor %q failed: %v", w.p.name, err)
}
// Invoke after callback
if w.p.afterFn != nil {
w.p.afterFn(id, reqs, res, err)
}
return err
} | [
"func",
"(",
"w",
"*",
"bulkWorker",
")",
"commit",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"var",
"res",
"*",
"BulkResponse",
"\n\n",
"// commitFunc will commit bulk requests and, on failure, be retried",
"// via exponential backoff",
"commitFunc",
":=",
"func",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"// Save requests because they will be reset in service.Do",
"reqs",
":=",
"w",
".",
"service",
".",
"requests",
"\n",
"res",
",",
"err",
"=",
"w",
".",
"service",
".",
"Do",
"(",
"ctx",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// Overall bulk request was OK. But each bulk response item also has a status",
"if",
"w",
".",
"p",
".",
"retryItemStatusCodes",
"!=",
"nil",
"&&",
"len",
"(",
"w",
".",
"p",
".",
"retryItemStatusCodes",
")",
">",
"0",
"{",
"// Check res.Items since some might be soft failures",
"if",
"res",
".",
"Items",
"!=",
"nil",
"&&",
"res",
".",
"Errors",
"{",
"// res.Items will be 1 to 1 with reqs in same order",
"for",
"i",
",",
"item",
":=",
"range",
"res",
".",
"Items",
"{",
"for",
"_",
",",
"result",
":=",
"range",
"item",
"{",
"if",
"_",
",",
"found",
":=",
"w",
".",
"p",
".",
"retryItemStatusCodes",
"[",
"result",
".",
"Status",
"]",
";",
"found",
"{",
"w",
".",
"service",
".",
"Add",
"(",
"reqs",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"ErrBulkItemRetry",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"// notifyFunc will be called if retry fails",
"notifyFunc",
":=",
"func",
"(",
"err",
"error",
")",
"{",
"w",
".",
"p",
".",
"c",
".",
"errorf",
"(",
"\"",
"\"",
",",
"w",
".",
"p",
".",
"name",
",",
"err",
")",
"\n",
"}",
"\n\n",
"id",
":=",
"atomic",
".",
"AddInt64",
"(",
"&",
"w",
".",
"p",
".",
"executionId",
",",
"1",
")",
"\n\n",
"// Update # documents in queue before eventual retries",
"w",
".",
"p",
".",
"statsMu",
".",
"Lock",
"(",
")",
"\n",
"if",
"w",
".",
"p",
".",
"wantStats",
"{",
"w",
".",
"p",
".",
"stats",
".",
"Workers",
"[",
"w",
".",
"i",
"]",
".",
"Queued",
"=",
"int64",
"(",
"len",
"(",
"w",
".",
"service",
".",
"requests",
")",
")",
"\n",
"}",
"\n",
"w",
".",
"p",
".",
"statsMu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Save requests because they will be reset in commitFunc",
"reqs",
":=",
"w",
".",
"service",
".",
"requests",
"\n\n",
"// Invoke before callback",
"if",
"w",
".",
"p",
".",
"beforeFn",
"!=",
"nil",
"{",
"w",
".",
"p",
".",
"beforeFn",
"(",
"id",
",",
"reqs",
")",
"\n",
"}",
"\n\n",
"// Commit bulk requests",
"err",
":=",
"RetryNotify",
"(",
"commitFunc",
",",
"w",
".",
"p",
".",
"backoff",
",",
"notifyFunc",
")",
"\n",
"w",
".",
"updateStats",
"(",
"res",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"w",
".",
"p",
".",
"c",
".",
"errorf",
"(",
"\"",
"\"",
",",
"w",
".",
"p",
".",
"name",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Invoke after callback",
"if",
"w",
".",
"p",
".",
"afterFn",
"!=",
"nil",
"{",
"w",
".",
"p",
".",
"afterFn",
"(",
"id",
",",
"reqs",
",",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // commit commits the bulk requests in the given service,
// invoking callbacks as specified. | [
"commit",
"commits",
"the",
"bulk",
"requests",
"in",
"the",
"given",
"service",
"invoking",
"callbacks",
"as",
"specified",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L526-L592 | train |
olivere/elastic | bulk_processor.go | commitRequired | func (w *bulkWorker) commitRequired() bool {
if w.bulkActions >= 0 && w.service.NumberOfActions() >= w.bulkActions {
return true
}
if w.bulkSize >= 0 && w.service.EstimatedSizeInBytes() >= int64(w.bulkSize) {
return true
}
return false
} | go | func (w *bulkWorker) commitRequired() bool {
if w.bulkActions >= 0 && w.service.NumberOfActions() >= w.bulkActions {
return true
}
if w.bulkSize >= 0 && w.service.EstimatedSizeInBytes() >= int64(w.bulkSize) {
return true
}
return false
} | [
"func",
"(",
"w",
"*",
"bulkWorker",
")",
"commitRequired",
"(",
")",
"bool",
"{",
"if",
"w",
".",
"bulkActions",
">=",
"0",
"&&",
"w",
".",
"service",
".",
"NumberOfActions",
"(",
")",
">=",
"w",
".",
"bulkActions",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"w",
".",
"bulkSize",
">=",
"0",
"&&",
"w",
".",
"service",
".",
"EstimatedSizeInBytes",
"(",
")",
">=",
"int64",
"(",
"w",
".",
"bulkSize",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // commitRequired returns true if the service has to commit its
// bulk requests. This can be either because the number of actions
// or the estimated size in bytes is larger than specified in the
// BulkProcessorService. | [
"commitRequired",
"returns",
"true",
"if",
"the",
"service",
"has",
"to",
"commit",
"its",
"bulk",
"requests",
".",
"This",
"can",
"be",
"either",
"because",
"the",
"number",
"of",
"actions",
"or",
"the",
"estimated",
"size",
"in",
"bytes",
"is",
"larger",
"than",
"specified",
"in",
"the",
"BulkProcessorService",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/bulk_processor.go#L648-L656 | train |
olivere/elastic | search_request.go | SearchType | func (r *SearchRequest) SearchType(searchType string) *SearchRequest {
r.searchType = searchType
return r
} | go | func (r *SearchRequest) SearchType(searchType string) *SearchRequest {
r.searchType = searchType
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"SearchType",
"(",
"searchType",
"string",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchType",
"=",
"searchType",
"\n",
"return",
"r",
"\n",
"}"
] | // SearchType must be one of "dfs_query_then_fetch", "dfs_query_and_fetch",
// "query_then_fetch", or "query_and_fetch". | [
"SearchType",
"must",
"be",
"one",
"of",
"dfs_query_then_fetch",
"dfs_query_and_fetch",
"query_then_fetch",
"or",
"query_and_fetch",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L43-L46 | train |
olivere/elastic | search_request.go | Index | func (r *SearchRequest) Index(indices ...string) *SearchRequest {
r.indices = append(r.indices, indices...)
return r
} | go | func (r *SearchRequest) Index(indices ...string) *SearchRequest {
r.indices = append(r.indices, indices...)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"Index",
"(",
"indices",
"...",
"string",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"indices",
"=",
"append",
"(",
"r",
".",
"indices",
",",
"indices",
"...",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Index specifies the indices to use in the request. | [
"Index",
"specifies",
"the",
"indices",
"to",
"use",
"in",
"the",
"request",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L59-L62 | train |
olivere/elastic | search_request.go | Routing | func (r *SearchRequest) Routing(routing string) *SearchRequest {
r.routing = &routing
return r
} | go | func (r *SearchRequest) Routing(routing string) *SearchRequest {
r.routing = &routing
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"Routing",
"(",
"routing",
"string",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"routing",
"=",
"&",
"routing",
"\n",
"return",
"r",
"\n",
"}"
] | // Routing specifies the routing parameter. It is a comma-separated list. | [
"Routing",
"specifies",
"the",
"routing",
"parameter",
".",
"It",
"is",
"a",
"comma",
"-",
"separated",
"list",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L79-L82 | train |
olivere/elastic | search_request.go | Routings | func (r *SearchRequest) Routings(routings ...string) *SearchRequest {
if routings != nil {
routings := strings.Join(routings, ",")
r.routing = &routings
} else {
r.routing = nil
}
return r
} | go | func (r *SearchRequest) Routings(routings ...string) *SearchRequest {
if routings != nil {
routings := strings.Join(routings, ",")
r.routing = &routings
} else {
r.routing = nil
}
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"Routings",
"(",
"routings",
"...",
"string",
")",
"*",
"SearchRequest",
"{",
"if",
"routings",
"!=",
"nil",
"{",
"routings",
":=",
"strings",
".",
"Join",
"(",
"routings",
",",
"\"",
"\"",
")",
"\n",
"r",
".",
"routing",
"=",
"&",
"routings",
"\n",
"}",
"else",
"{",
"r",
".",
"routing",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] | // Routings to be used in the request. | [
"Routings",
"to",
"be",
"used",
"in",
"the",
"request",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L85-L93 | train |
olivere/elastic | search_request.go | Preference | func (r *SearchRequest) Preference(preference string) *SearchRequest {
r.preference = &preference
return r
} | go | func (r *SearchRequest) Preference(preference string) *SearchRequest {
r.preference = &preference
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"Preference",
"(",
"preference",
"string",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"preference",
"=",
"&",
"preference",
"\n",
"return",
"r",
"\n",
"}"
] | // Preference to execute the search. Defaults to randomize across shards.
// Can be set to "_local" to prefer local shards, "_primary" to execute
// only on primary shards, or a custom value, which guarantees that the
// same order will be used across different requests. | [
"Preference",
"to",
"execute",
"the",
"search",
".",
"Defaults",
"to",
"randomize",
"across",
"shards",
".",
"Can",
"be",
"set",
"to",
"_local",
"to",
"prefer",
"local",
"shards",
"_primary",
"to",
"execute",
"only",
"on",
"primary",
"shards",
"or",
"a",
"custom",
"value",
"which",
"guarantees",
"that",
"the",
"same",
"order",
"will",
"be",
"used",
"across",
"different",
"requests",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L99-L102 | train |
olivere/elastic | search_request.go | RequestCache | func (r *SearchRequest) RequestCache(requestCache bool) *SearchRequest {
r.requestCache = &requestCache
return r
} | go | func (r *SearchRequest) RequestCache(requestCache bool) *SearchRequest {
r.requestCache = &requestCache
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"RequestCache",
"(",
"requestCache",
"bool",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"requestCache",
"=",
"&",
"requestCache",
"\n",
"return",
"r",
"\n",
"}"
] | // RequestCache specifies if this request should use the request cache
// or not, assuming that it can. By default, will default to the index
// level setting if request cache is enabled or not. | [
"RequestCache",
"specifies",
"if",
"this",
"request",
"should",
"use",
"the",
"request",
"cache",
"or",
"not",
"assuming",
"that",
"it",
"can",
".",
"By",
"default",
"will",
"default",
"to",
"the",
"index",
"level",
"setting",
"if",
"request",
"cache",
"is",
"enabled",
"or",
"not",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L107-L110 | train |
olivere/elastic | search_request.go | TerminateAfter | func (r *SearchRequest) TerminateAfter(docs int) *SearchRequest {
r.searchSource = r.searchSource.TerminateAfter(docs)
return r
} | go | func (r *SearchRequest) TerminateAfter(docs int) *SearchRequest {
r.searchSource = r.searchSource.TerminateAfter(docs)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"TerminateAfter",
"(",
"docs",
"int",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"TerminateAfter",
"(",
"docs",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // TerminateAfter, when set, specifies an optional document count,
// upon collecting which the search query will terminate early. | [
"TerminateAfter",
"when",
"set",
"specifies",
"an",
"optional",
"document",
"count",
"upon",
"collecting",
"which",
"the",
"search",
"query",
"will",
"terminate",
"early",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L166-L169 | train |
olivere/elastic | search_request.go | Query | func (r *SearchRequest) Query(query Query) *SearchRequest {
r.searchSource = r.searchSource.Query(query)
return r
} | go | func (r *SearchRequest) Query(query Query) *SearchRequest {
r.searchSource = r.searchSource.Query(query)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"Query",
"(",
"query",
"Query",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"Query",
"(",
"query",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Query for the search. | [
"Query",
"for",
"the",
"search",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L172-L175 | train |
olivere/elastic | search_request.go | MinScore | func (r *SearchRequest) MinScore(minScore float64) *SearchRequest {
r.searchSource = r.searchSource.MinScore(minScore)
return r
} | go | func (r *SearchRequest) MinScore(minScore float64) *SearchRequest {
r.searchSource = r.searchSource.MinScore(minScore)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"MinScore",
"(",
"minScore",
"float64",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"MinScore",
"(",
"minScore",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // MinScore below which documents are filtered out. | [
"MinScore",
"below",
"which",
"documents",
"are",
"filtered",
"out",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L187-L190 | train |
olivere/elastic | search_request.go | Explain | func (r *SearchRequest) Explain(explain bool) *SearchRequest {
r.searchSource = r.searchSource.Explain(explain)
return r
} | go | func (r *SearchRequest) Explain(explain bool) *SearchRequest {
r.searchSource = r.searchSource.Explain(explain)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"Explain",
"(",
"explain",
"bool",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"Explain",
"(",
"explain",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Explain indicates whether to return an explanation for each hit. | [
"Explain",
"indicates",
"whether",
"to",
"return",
"an",
"explanation",
"for",
"each",
"hit",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L205-L208 | train |
olivere/elastic | search_request.go | Version | func (r *SearchRequest) Version(version bool) *SearchRequest {
r.searchSource = r.searchSource.Version(version)
return r
} | go | func (r *SearchRequest) Version(version bool) *SearchRequest {
r.searchSource = r.searchSource.Version(version)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"Version",
"(",
"version",
"bool",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"Version",
"(",
"version",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Version indicates whether each hit should be returned with
// its version. | [
"Version",
"indicates",
"whether",
"each",
"hit",
"should",
"be",
"returned",
"with",
"its",
"version",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L212-L215 | train |
olivere/elastic | search_request.go | IndexBoost | func (r *SearchRequest) IndexBoost(index string, boost float64) *SearchRequest {
r.searchSource = r.searchSource.IndexBoost(index, boost)
return r
} | go | func (r *SearchRequest) IndexBoost(index string, boost float64) *SearchRequest {
r.searchSource = r.searchSource.IndexBoost(index, boost)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"IndexBoost",
"(",
"index",
"string",
",",
"boost",
"float64",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"IndexBoost",
"(",
"index",
",",
"boost",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // IndexBoost sets a boost a specific index will receive when
// the query is executed against it. | [
"IndexBoost",
"sets",
"a",
"boost",
"a",
"specific",
"index",
"will",
"receive",
"when",
"the",
"query",
"is",
"executed",
"against",
"it",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L219-L222 | train |
olivere/elastic | search_request.go | Stats | func (r *SearchRequest) Stats(statsGroup ...string) *SearchRequest {
r.searchSource = r.searchSource.Stats(statsGroup...)
return r
} | go | func (r *SearchRequest) Stats(statsGroup ...string) *SearchRequest {
r.searchSource = r.searchSource.Stats(statsGroup...)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"Stats",
"(",
"statsGroup",
"...",
"string",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"Stats",
"(",
"statsGroup",
"...",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Stats groups that this request will be aggregated under. | [
"Stats",
"groups",
"that",
"this",
"request",
"will",
"be",
"aggregated",
"under",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L225-L228 | train |
olivere/elastic | search_request.go | DocValueField | func (r *SearchRequest) DocValueField(field string) *SearchRequest {
r.searchSource = r.searchSource.DocvalueField(field)
return r
} | go | func (r *SearchRequest) DocValueField(field string) *SearchRequest {
r.searchSource = r.searchSource.DocvalueField(field)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"DocValueField",
"(",
"field",
"string",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"DocvalueField",
"(",
"field",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // DocValueField adds a docvalue based field to load and return.
// The field does not have to be stored, but it's recommended to use
// non analyzed or numeric fields. | [
"DocValueField",
"adds",
"a",
"docvalue",
"based",
"field",
"to",
"load",
"and",
"return",
".",
"The",
"field",
"does",
"not",
"have",
"to",
"be",
"stored",
"but",
"it",
"s",
"recommended",
"to",
"use",
"non",
"analyzed",
"or",
"numeric",
"fields",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L255-L258 | train |
olivere/elastic | search_request.go | DocValueFieldWithFormat | func (r *SearchRequest) DocValueFieldWithFormat(field DocvalueField) *SearchRequest {
r.searchSource = r.searchSource.DocvalueFieldWithFormat(field)
return r
} | go | func (r *SearchRequest) DocValueFieldWithFormat(field DocvalueField) *SearchRequest {
r.searchSource = r.searchSource.DocvalueFieldWithFormat(field)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"DocValueFieldWithFormat",
"(",
"field",
"DocvalueField",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"DocvalueFieldWithFormat",
"(",
"field",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // DocValueFieldWithFormat adds a docvalue based field to load and return.
// The field does not have to be stored, but it's recommended to use
// non analyzed or numeric fields. | [
"DocValueFieldWithFormat",
"adds",
"a",
"docvalue",
"based",
"field",
"to",
"load",
"and",
"return",
".",
"The",
"field",
"does",
"not",
"have",
"to",
"be",
"stored",
"but",
"it",
"s",
"recommended",
"to",
"use",
"non",
"analyzed",
"or",
"numeric",
"fields",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L263-L266 | train |
olivere/elastic | search_request.go | DocValueFields | func (r *SearchRequest) DocValueFields(fields ...string) *SearchRequest {
r.searchSource = r.searchSource.DocvalueFields(fields...)
return r
} | go | func (r *SearchRequest) DocValueFields(fields ...string) *SearchRequest {
r.searchSource = r.searchSource.DocvalueFields(fields...)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"DocValueFields",
"(",
"fields",
"...",
"string",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"DocvalueFields",
"(",
"fields",
"...",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // DocValueFields adds one or more docvalue based field to load and return.
// The fields do not have to be stored, but it's recommended to use
// non analyzed or numeric fields. | [
"DocValueFields",
"adds",
"one",
"or",
"more",
"docvalue",
"based",
"field",
"to",
"load",
"and",
"return",
".",
"The",
"fields",
"do",
"not",
"have",
"to",
"be",
"stored",
"but",
"it",
"s",
"recommended",
"to",
"use",
"non",
"analyzed",
"or",
"numeric",
"fields",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L271-L274 | train |
olivere/elastic | search_request.go | DocValueFieldsWithFormat | func (r *SearchRequest) DocValueFieldsWithFormat(fields ...DocvalueField) *SearchRequest {
r.searchSource = r.searchSource.DocvalueFieldsWithFormat(fields...)
return r
} | go | func (r *SearchRequest) DocValueFieldsWithFormat(fields ...DocvalueField) *SearchRequest {
r.searchSource = r.searchSource.DocvalueFieldsWithFormat(fields...)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"DocValueFieldsWithFormat",
"(",
"fields",
"...",
"DocvalueField",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"DocvalueFieldsWithFormat",
"(",
"fields",
"...",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // DocValueFieldsWithFormat adds one or more docvalue based field to load and return.
// The fields do not have to be stored, but it's recommended to use
// non analyzed or numeric fields. | [
"DocValueFieldsWithFormat",
"adds",
"one",
"or",
"more",
"docvalue",
"based",
"field",
"to",
"load",
"and",
"return",
".",
"The",
"fields",
"do",
"not",
"have",
"to",
"be",
"stored",
"but",
"it",
"s",
"recommended",
"to",
"use",
"non",
"analyzed",
"or",
"numeric",
"fields",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L279-L282 | train |
olivere/elastic | search_request.go | NoStoredFields | func (r *SearchRequest) NoStoredFields() *SearchRequest {
r.searchSource = r.searchSource.NoStoredFields()
return r
} | go | func (r *SearchRequest) NoStoredFields() *SearchRequest {
r.searchSource = r.searchSource.NoStoredFields()
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"NoStoredFields",
"(",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"NoStoredFields",
"(",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // NoStoredFields indicates that no fields should be loaded,
// resulting in only id and type to be returned per field. | [
"NoStoredFields",
"indicates",
"that",
"no",
"fields",
"should",
"be",
"loaded",
"resulting",
"in",
"only",
"id",
"and",
"type",
"to",
"be",
"returned",
"per",
"field",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L293-L296 | train |
olivere/elastic | search_request.go | ScriptField | func (r *SearchRequest) ScriptField(field *ScriptField) *SearchRequest {
r.searchSource = r.searchSource.ScriptField(field)
return r
} | go | func (r *SearchRequest) ScriptField(field *ScriptField) *SearchRequest {
r.searchSource = r.searchSource.ScriptField(field)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"ScriptField",
"(",
"field",
"*",
"ScriptField",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"ScriptField",
"(",
"field",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // ScriptField adds a script based field to load and return.
// The field does not have to be stored, but it's recommended
// to use non analyzed or numeric fields. | [
"ScriptField",
"adds",
"a",
"script",
"based",
"field",
"to",
"load",
"and",
"return",
".",
"The",
"field",
"does",
"not",
"have",
"to",
"be",
"stored",
"but",
"it",
"s",
"recommended",
"to",
"use",
"non",
"analyzed",
"or",
"numeric",
"fields",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L308-L311 | train |
olivere/elastic | search_request.go | ScriptFields | func (r *SearchRequest) ScriptFields(fields ...*ScriptField) *SearchRequest {
r.searchSource = r.searchSource.ScriptFields(fields...)
return r
} | go | func (r *SearchRequest) ScriptFields(fields ...*ScriptField) *SearchRequest {
r.searchSource = r.searchSource.ScriptFields(fields...)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"ScriptFields",
"(",
"fields",
"...",
"*",
"ScriptField",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"ScriptFields",
"(",
"fields",
"...",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // ScriptFields adds one or more script based field to load and return.
// The fields do not have to be stored, but it's recommended
// to use non analyzed or numeric fields. | [
"ScriptFields",
"adds",
"one",
"or",
"more",
"script",
"based",
"field",
"to",
"load",
"and",
"return",
".",
"The",
"fields",
"do",
"not",
"have",
"to",
"be",
"stored",
"but",
"it",
"s",
"recommended",
"to",
"use",
"non",
"analyzed",
"or",
"numeric",
"fields",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L316-L319 | train |
olivere/elastic | search_request.go | SearchAfter | func (r *SearchRequest) SearchAfter(sortValues ...interface{}) *SearchRequest {
r.searchSource = r.searchSource.SearchAfter(sortValues...)
return r
} | go | func (r *SearchRequest) SearchAfter(sortValues ...interface{}) *SearchRequest {
r.searchSource = r.searchSource.SearchAfter(sortValues...)
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"SearchAfter",
"(",
"sortValues",
"...",
"interface",
"{",
"}",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"SearchAfter",
"(",
"sortValues",
"...",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // SearchAfter sets the sort values that indicates which docs this
// request should "search after". | [
"SearchAfter",
"sets",
"the",
"sort",
"values",
"that",
"indicates",
"which",
"docs",
"this",
"request",
"should",
"search",
"after",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L341-L344 | train |
olivere/elastic | search_request.go | ClearRescorers | func (r *SearchRequest) ClearRescorers() *SearchRequest {
r.searchSource = r.searchSource.ClearRescorers()
return r
} | go | func (r *SearchRequest) ClearRescorers() *SearchRequest {
r.searchSource = r.searchSource.ClearRescorers()
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"ClearRescorers",
"(",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"searchSource",
"=",
"r",
".",
"searchSource",
".",
"ClearRescorers",
"(",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // ClearRescorers removes all rescorers from the search. | [
"ClearRescorers",
"removes",
"all",
"rescorers",
"from",
"the",
"search",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L398-L401 | train |
olivere/elastic | search_request.go | BatchedReduceSize | func (r *SearchRequest) BatchedReduceSize(size int) *SearchRequest {
r.batchedReduceSize = &size
return r
} | go | func (r *SearchRequest) BatchedReduceSize(size int) *SearchRequest {
r.batchedReduceSize = &size
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"BatchedReduceSize",
"(",
"size",
"int",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"batchedReduceSize",
"=",
"&",
"size",
"\n",
"return",
"r",
"\n",
"}"
] | // BatchedReduceSize specifies the number of shard results that should be
// reduced at once on the coordinating node. This value should be used
// as a protection mechanism to reduce the memory overhead per search request
// if the potential number of shards in the request can be large. | [
"BatchedReduceSize",
"specifies",
"the",
"number",
"of",
"shard",
"results",
"that",
"should",
"be",
"reduced",
"at",
"once",
"on",
"the",
"coordinating",
"node",
".",
"This",
"value",
"should",
"be",
"used",
"as",
"a",
"protection",
"mechanism",
"to",
"reduce",
"the",
"memory",
"overhead",
"per",
"search",
"request",
"if",
"the",
"potential",
"number",
"of",
"shards",
"in",
"the",
"request",
"can",
"be",
"large",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L428-L431 | train |
olivere/elastic | search_request.go | MaxConcurrentShardRequests | func (r *SearchRequest) MaxConcurrentShardRequests(size int) *SearchRequest {
r.maxConcurrentShardRequests = &size
return r
} | go | func (r *SearchRequest) MaxConcurrentShardRequests(size int) *SearchRequest {
r.maxConcurrentShardRequests = &size
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"MaxConcurrentShardRequests",
"(",
"size",
"int",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"maxConcurrentShardRequests",
"=",
"&",
"size",
"\n",
"return",
"r",
"\n",
"}"
] | // MaxConcurrentShardRequests sets the number of shard requests that should
// be executed concurrently. This value should be used as a protection
// mechanism to reduce the number of shard requests fired per high level
// search request. Searches that hit the entire cluster can be throttled
// with this number to reduce the cluster load. The default grows with
// the number of nodes in the cluster but is at most 256. | [
"MaxConcurrentShardRequests",
"sets",
"the",
"number",
"of",
"shard",
"requests",
"that",
"should",
"be",
"executed",
"concurrently",
".",
"This",
"value",
"should",
"be",
"used",
"as",
"a",
"protection",
"mechanism",
"to",
"reduce",
"the",
"number",
"of",
"shard",
"requests",
"fired",
"per",
"high",
"level",
"search",
"request",
".",
"Searches",
"that",
"hit",
"the",
"entire",
"cluster",
"can",
"be",
"throttled",
"with",
"this",
"number",
"to",
"reduce",
"the",
"cluster",
"load",
".",
"The",
"default",
"grows",
"with",
"the",
"number",
"of",
"nodes",
"in",
"the",
"cluster",
"but",
"is",
"at",
"most",
"256",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L439-L442 | train |
olivere/elastic | search_request.go | PreFilterShardSize | func (r *SearchRequest) PreFilterShardSize(size int) *SearchRequest {
r.preFilterShardSize = &size
return r
} | go | func (r *SearchRequest) PreFilterShardSize(size int) *SearchRequest {
r.preFilterShardSize = &size
return r
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"PreFilterShardSize",
"(",
"size",
"int",
")",
"*",
"SearchRequest",
"{",
"r",
".",
"preFilterShardSize",
"=",
"&",
"size",
"\n",
"return",
"r",
"\n",
"}"
] | // PreFilterShardSize sets a threshold that enforces a pre-filter roundtrip
// to pre-filter search shards based on query rewriting if the number of
// shards the search request expands to exceeds the threshold.
// This filter roundtrip can limit the number of shards significantly if for
// instance a shard can not match any documents based on it's rewrite
// method ie. if date filters are mandatory to match but the shard
// bounds and the query are disjoint. The default is 128. | [
"PreFilterShardSize",
"sets",
"a",
"threshold",
"that",
"enforces",
"a",
"pre",
"-",
"filter",
"roundtrip",
"to",
"pre",
"-",
"filter",
"search",
"shards",
"based",
"on",
"query",
"rewriting",
"if",
"the",
"number",
"of",
"shards",
"the",
"search",
"request",
"expands",
"to",
"exceeds",
"the",
"threshold",
".",
"This",
"filter",
"roundtrip",
"can",
"limit",
"the",
"number",
"of",
"shards",
"significantly",
"if",
"for",
"instance",
"a",
"shard",
"can",
"not",
"match",
"any",
"documents",
"based",
"on",
"it",
"s",
"rewrite",
"method",
"ie",
".",
"if",
"date",
"filters",
"are",
"mandatory",
"to",
"match",
"but",
"the",
"shard",
"bounds",
"and",
"the",
"query",
"are",
"disjoint",
".",
"The",
"default",
"is",
"128",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L451-L454 | train |
olivere/elastic | search_request.go | sourceAsMap | func (r *SearchRequest) sourceAsMap() (interface{}, error) {
if r.source == nil {
// Default: No custom source specified
return r.searchSource.Source()
}
switch t := r.source.(type) {
default:
body, err := json.Marshal(r.source)
if err != nil {
return "", err
}
return RawStringQuery(body), nil
case *SearchSource:
return t.Source()
case json.RawMessage:
return RawStringQuery(string(t)), nil
case *json.RawMessage:
return RawStringQuery(string(*t)), nil
case string:
return RawStringQuery(t), nil
case *string:
if t != nil {
return RawStringQuery(*t), nil
}
return RawStringQuery("{}"), nil
}
} | go | func (r *SearchRequest) sourceAsMap() (interface{}, error) {
if r.source == nil {
// Default: No custom source specified
return r.searchSource.Source()
}
switch t := r.source.(type) {
default:
body, err := json.Marshal(r.source)
if err != nil {
return "", err
}
return RawStringQuery(body), nil
case *SearchSource:
return t.Source()
case json.RawMessage:
return RawStringQuery(string(t)), nil
case *json.RawMessage:
return RawStringQuery(string(*t)), nil
case string:
return RawStringQuery(t), nil
case *string:
if t != nil {
return RawStringQuery(*t), nil
}
return RawStringQuery("{}"), nil
}
} | [
"func",
"(",
"r",
"*",
"SearchRequest",
")",
"sourceAsMap",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"r",
".",
"source",
"==",
"nil",
"{",
"// Default: No custom source specified",
"return",
"r",
".",
"searchSource",
".",
"Source",
"(",
")",
"\n",
"}",
"\n",
"switch",
"t",
":=",
"r",
".",
"source",
".",
"(",
"type",
")",
"{",
"default",
":",
"body",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"r",
".",
"source",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"RawStringQuery",
"(",
"body",
")",
",",
"nil",
"\n",
"case",
"*",
"SearchSource",
":",
"return",
"t",
".",
"Source",
"(",
")",
"\n",
"case",
"json",
".",
"RawMessage",
":",
"return",
"RawStringQuery",
"(",
"string",
"(",
"t",
")",
")",
",",
"nil",
"\n",
"case",
"*",
"json",
".",
"RawMessage",
":",
"return",
"RawStringQuery",
"(",
"string",
"(",
"*",
"t",
")",
")",
",",
"nil",
"\n",
"case",
"string",
":",
"return",
"RawStringQuery",
"(",
"t",
")",
",",
"nil",
"\n",
"case",
"*",
"string",
":",
"if",
"t",
"!=",
"nil",
"{",
"return",
"RawStringQuery",
"(",
"*",
"t",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"RawStringQuery",
"(",
"\"",
"\"",
")",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // source returns the search source. It is used by Reindex. | [
"source",
"returns",
"the",
"search",
"source",
".",
"It",
"is",
"used",
"by",
"Reindex",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_request.go#L560-L586 | train |
olivere/elastic | delete.go | Parent | func (s *DeleteService) Parent(parent string) *DeleteService {
s.parent = parent
return s
} | go | func (s *DeleteService) Parent(parent string) *DeleteService {
s.parent = parent
return s
} | [
"func",
"(",
"s",
"*",
"DeleteService",
")",
"Parent",
"(",
"parent",
"string",
")",
"*",
"DeleteService",
"{",
"s",
".",
"parent",
"=",
"parent",
"\n",
"return",
"s",
"\n",
"}"
] | // Parent is the ID of parent document. | [
"Parent",
"is",
"the",
"ID",
"of",
"parent",
"document",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/delete.go#L99-L102 | train |
olivere/elastic | script.go | Params | func (s *Script) Params(params map[string]interface{}) *Script {
s.params = params
return s
} | go | func (s *Script) Params(params map[string]interface{}) *Script {
s.params = params
return s
} | [
"func",
"(",
"s",
"*",
"Script",
")",
"Params",
"(",
"params",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"*",
"Script",
"{",
"s",
".",
"params",
"=",
"params",
"\n",
"return",
"s",
"\n",
"}"
] | // Params sets the map of parameters this script will be executed with. | [
"Params",
"sets",
"the",
"map",
"of",
"parameters",
"this",
"script",
"will",
"be",
"executed",
"with",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/script.go#L80-L83 | train |
olivere/elastic | script.go | Source | func (s *Script) Source() (interface{}, error) {
if s.typ == "" && s.lang == "" && len(s.params) == 0 {
return s.script, nil
}
source := make(map[string]interface{})
// Beginning with 6.0, the type can only be "source" or "id"
if s.typ == "" || s.typ == "inline" {
src, err := s.rawScriptSource(s.script)
if err != nil {
return nil, err
}
source["source"] = src
} else {
source["id"] = s.script
}
if s.lang != "" {
source["lang"] = s.lang
}
if len(s.params) > 0 {
source["params"] = s.params
}
return source, nil
} | go | func (s *Script) Source() (interface{}, error) {
if s.typ == "" && s.lang == "" && len(s.params) == 0 {
return s.script, nil
}
source := make(map[string]interface{})
// Beginning with 6.0, the type can only be "source" or "id"
if s.typ == "" || s.typ == "inline" {
src, err := s.rawScriptSource(s.script)
if err != nil {
return nil, err
}
source["source"] = src
} else {
source["id"] = s.script
}
if s.lang != "" {
source["lang"] = s.lang
}
if len(s.params) > 0 {
source["params"] = s.params
}
return source, nil
} | [
"func",
"(",
"s",
"*",
"Script",
")",
"Source",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"s",
".",
"typ",
"==",
"\"",
"\"",
"&&",
"s",
".",
"lang",
"==",
"\"",
"\"",
"&&",
"len",
"(",
"s",
".",
"params",
")",
"==",
"0",
"{",
"return",
"s",
".",
"script",
",",
"nil",
"\n",
"}",
"\n",
"source",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"// Beginning with 6.0, the type can only be \"source\" or \"id\"",
"if",
"s",
".",
"typ",
"==",
"\"",
"\"",
"||",
"s",
".",
"typ",
"==",
"\"",
"\"",
"{",
"src",
",",
"err",
":=",
"s",
".",
"rawScriptSource",
"(",
"s",
".",
"script",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"source",
"[",
"\"",
"\"",
"]",
"=",
"src",
"\n",
"}",
"else",
"{",
"source",
"[",
"\"",
"\"",
"]",
"=",
"s",
".",
"script",
"\n",
"}",
"\n",
"if",
"s",
".",
"lang",
"!=",
"\"",
"\"",
"{",
"source",
"[",
"\"",
"\"",
"]",
"=",
"s",
".",
"lang",
"\n",
"}",
"\n",
"if",
"len",
"(",
"s",
".",
"params",
")",
">",
"0",
"{",
"source",
"[",
"\"",
"\"",
"]",
"=",
"s",
".",
"params",
"\n",
"}",
"\n",
"return",
"source",
",",
"nil",
"\n",
"}"
] | // Source returns the JSON serializable data for this Script. | [
"Source",
"returns",
"the",
"JSON",
"serializable",
"data",
"for",
"this",
"Script",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/script.go#L86-L108 | train |
olivere/elastic | script.go | NewScriptField | func NewScriptField(fieldName string, script *Script) *ScriptField {
return &ScriptField{FieldName: fieldName, script: script}
} | go | func NewScriptField(fieldName string, script *Script) *ScriptField {
return &ScriptField{FieldName: fieldName, script: script}
} | [
"func",
"NewScriptField",
"(",
"fieldName",
"string",
",",
"script",
"*",
"Script",
")",
"*",
"ScriptField",
"{",
"return",
"&",
"ScriptField",
"{",
"FieldName",
":",
"fieldName",
",",
"script",
":",
"script",
"}",
"\n",
"}"
] | // NewScriptField creates and initializes a new ScriptField. | [
"NewScriptField",
"creates",
"and",
"initializes",
"a",
"new",
"ScriptField",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/script.go#L133-L135 | train |
olivere/elastic | script.go | Source | func (f *ScriptField) Source() (interface{}, error) {
if f.script == nil {
return nil, errors.New("ScriptField expects script")
}
source := make(map[string]interface{})
src, err := f.script.Source()
if err != nil {
return nil, err
}
source["script"] = src
return source, nil
} | go | func (f *ScriptField) Source() (interface{}, error) {
if f.script == nil {
return nil, errors.New("ScriptField expects script")
}
source := make(map[string]interface{})
src, err := f.script.Source()
if err != nil {
return nil, err
}
source["script"] = src
return source, nil
} | [
"func",
"(",
"f",
"*",
"ScriptField",
")",
"Source",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"f",
".",
"script",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"source",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"src",
",",
"err",
":=",
"f",
".",
"script",
".",
"Source",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"source",
"[",
"\"",
"\"",
"]",
"=",
"src",
"\n",
"return",
"source",
",",
"nil",
"\n",
"}"
] | // Source returns the serializable JSON for the ScriptField. | [
"Source",
"returns",
"the",
"serializable",
"JSON",
"for",
"the",
"ScriptField",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/script.go#L138-L149 | train |
olivere/elastic | search_queries_geo_polygon.go | NewGeoPolygonQuery | func NewGeoPolygonQuery(name string) *GeoPolygonQuery {
return &GeoPolygonQuery{
name: name,
points: make([]*GeoPoint, 0),
}
} | go | func NewGeoPolygonQuery(name string) *GeoPolygonQuery {
return &GeoPolygonQuery{
name: name,
points: make([]*GeoPoint, 0),
}
} | [
"func",
"NewGeoPolygonQuery",
"(",
"name",
"string",
")",
"*",
"GeoPolygonQuery",
"{",
"return",
"&",
"GeoPolygonQuery",
"{",
"name",
":",
"name",
",",
"points",
":",
"make",
"(",
"[",
"]",
"*",
"GeoPoint",
",",
"0",
")",
",",
"}",
"\n",
"}"
] | // NewGeoPolygonQuery creates and initializes a new GeoPolygonQuery. | [
"NewGeoPolygonQuery",
"creates",
"and",
"initializes",
"a",
"new",
"GeoPolygonQuery",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_geo_polygon.go#L18-L23 | train |
olivere/elastic | search_queries_geo_polygon.go | AddPoint | func (q *GeoPolygonQuery) AddPoint(lat, lon float64) *GeoPolygonQuery {
q.points = append(q.points, GeoPointFromLatLon(lat, lon))
return q
} | go | func (q *GeoPolygonQuery) AddPoint(lat, lon float64) *GeoPolygonQuery {
q.points = append(q.points, GeoPointFromLatLon(lat, lon))
return q
} | [
"func",
"(",
"q",
"*",
"GeoPolygonQuery",
")",
"AddPoint",
"(",
"lat",
",",
"lon",
"float64",
")",
"*",
"GeoPolygonQuery",
"{",
"q",
".",
"points",
"=",
"append",
"(",
"q",
".",
"points",
",",
"GeoPointFromLatLon",
"(",
"lat",
",",
"lon",
")",
")",
"\n",
"return",
"q",
"\n",
"}"
] | // AddPoint adds a point from latitude and longitude. | [
"AddPoint",
"adds",
"a",
"point",
"from",
"latitude",
"and",
"longitude",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_geo_polygon.go#L26-L29 | train |
olivere/elastic | search_queries_geo_polygon.go | AddGeoPoint | func (q *GeoPolygonQuery) AddGeoPoint(point *GeoPoint) *GeoPolygonQuery {
q.points = append(q.points, point)
return q
} | go | func (q *GeoPolygonQuery) AddGeoPoint(point *GeoPoint) *GeoPolygonQuery {
q.points = append(q.points, point)
return q
} | [
"func",
"(",
"q",
"*",
"GeoPolygonQuery",
")",
"AddGeoPoint",
"(",
"point",
"*",
"GeoPoint",
")",
"*",
"GeoPolygonQuery",
"{",
"q",
".",
"points",
"=",
"append",
"(",
"q",
".",
"points",
",",
"point",
")",
"\n",
"return",
"q",
"\n",
"}"
] | // AddGeoPoint adds a GeoPoint. | [
"AddGeoPoint",
"adds",
"a",
"GeoPoint",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/search_queries_geo_polygon.go#L32-L35 | train |
olivere/elastic | indices_flush_synced.go | UnmarshalJSON | func (resp *IndicesSyncedFlushResponse) UnmarshalJSON(data []byte) error {
m := make(map[string]json.RawMessage)
err := json.Unmarshal(data, &m)
if err != nil {
return err
}
resp.Index = make(map[string]*IndicesShardsSyncedFlushResult)
for k, v := range m {
if k == "_shards" {
if err := json.Unmarshal(v, &resp.Shards); err != nil {
return err
}
} else {
ix := new(IndicesShardsSyncedFlushResult)
if err := json.Unmarshal(v, &ix); err != nil {
return err
}
resp.Index[k] = ix
}
}
return nil
} | go | func (resp *IndicesSyncedFlushResponse) UnmarshalJSON(data []byte) error {
m := make(map[string]json.RawMessage)
err := json.Unmarshal(data, &m)
if err != nil {
return err
}
resp.Index = make(map[string]*IndicesShardsSyncedFlushResult)
for k, v := range m {
if k == "_shards" {
if err := json.Unmarshal(v, &resp.Shards); err != nil {
return err
}
} else {
ix := new(IndicesShardsSyncedFlushResult)
if err := json.Unmarshal(v, &ix); err != nil {
return err
}
resp.Index[k] = ix
}
}
return nil
} | [
"func",
"(",
"resp",
"*",
"IndicesSyncedFlushResponse",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"json",
".",
"RawMessage",
")",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"resp",
".",
"Index",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"IndicesShardsSyncedFlushResult",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"m",
"{",
"if",
"k",
"==",
"\"",
"\"",
"{",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"resp",
".",
"Shards",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"ix",
":=",
"new",
"(",
"IndicesShardsSyncedFlushResult",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"v",
",",
"&",
"ix",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"resp",
".",
"Index",
"[",
"k",
"]",
"=",
"ix",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON parses the output from Synced Flush API. | [
"UnmarshalJSON",
"parses",
"the",
"output",
"from",
"Synced",
"Flush",
"API",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_flush_synced.go#L209-L230 | train |
olivere/elastic | indices_segments.go | Index | func (s *IndicesSegmentsService) Index(indices ...string) *IndicesSegmentsService {
s.index = append(s.index, indices...)
return s
} | go | func (s *IndicesSegmentsService) Index(indices ...string) *IndicesSegmentsService {
s.index = append(s.index, indices...)
return s
} | [
"func",
"(",
"s",
"*",
"IndicesSegmentsService",
")",
"Index",
"(",
"indices",
"...",
"string",
")",
"*",
"IndicesSegmentsService",
"{",
"s",
".",
"index",
"=",
"append",
"(",
"s",
".",
"index",
",",
"indices",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] | // Index is a comma-separated list of index names; use `_all` or empty string
// to perform the operation on all indices. | [
"Index",
"is",
"a",
"comma",
"-",
"separated",
"list",
"of",
"index",
"names",
";",
"use",
"_all",
"or",
"empty",
"string",
"to",
"perform",
"the",
"operation",
"on",
"all",
"indices",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_segments.go#L45-L48 | train |
olivere/elastic | indices_segments.go | Human | func (s *IndicesSegmentsService) Human(human bool) *IndicesSegmentsService {
s.human = &human
return s
} | go | func (s *IndicesSegmentsService) Human(human bool) *IndicesSegmentsService {
s.human = &human
return s
} | [
"func",
"(",
"s",
"*",
"IndicesSegmentsService",
")",
"Human",
"(",
"human",
"bool",
")",
"*",
"IndicesSegmentsService",
"{",
"s",
".",
"human",
"=",
"&",
"human",
"\n",
"return",
"s",
"\n",
"}"
] | // Human, when set to true, returns time and byte-values in human-readable format. | [
"Human",
"when",
"set",
"to",
"true",
"returns",
"time",
"and",
"byte",
"-",
"values",
"in",
"human",
"-",
"readable",
"format",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_segments.go#L73-L76 | train |
olivere/elastic | indices_segments.go | Verbose | func (s *IndicesSegmentsService) Verbose(verbose bool) *IndicesSegmentsService {
s.verbose = &verbose
return s
} | go | func (s *IndicesSegmentsService) Verbose(verbose bool) *IndicesSegmentsService {
s.verbose = &verbose
return s
} | [
"func",
"(",
"s",
"*",
"IndicesSegmentsService",
")",
"Verbose",
"(",
"verbose",
"bool",
")",
"*",
"IndicesSegmentsService",
"{",
"s",
".",
"verbose",
"=",
"&",
"verbose",
"\n",
"return",
"s",
"\n",
"}"
] | // Verbose, when set to true, includes detailed memory usage by Lucene. | [
"Verbose",
"when",
"set",
"to",
"true",
"includes",
"detailed",
"memory",
"usage",
"by",
"Lucene",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/indices_segments.go#L85-L88 | train |
olivere/elastic | suggester_context.go | NewContextSuggester | func NewContextSuggester(name string) *ContextSuggester {
return &ContextSuggester{
name: name,
contextQueries: make([]SuggesterContextQuery, 0),
}
} | go | func NewContextSuggester(name string) *ContextSuggester {
return &ContextSuggester{
name: name,
contextQueries: make([]SuggesterContextQuery, 0),
}
} | [
"func",
"NewContextSuggester",
"(",
"name",
"string",
")",
"*",
"ContextSuggester",
"{",
"return",
"&",
"ContextSuggester",
"{",
"name",
":",
"name",
",",
"contextQueries",
":",
"make",
"(",
"[",
"]",
"SuggesterContextQuery",
",",
"0",
")",
",",
"}",
"\n",
"}"
] | // Creates a new context suggester. | [
"Creates",
"a",
"new",
"context",
"suggester",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/suggester_context.go#L28-L33 | train |
olivere/elastic | suggester_context.go | Source | func (q *ContextSuggester) Source(includeName bool) (interface{}, error) {
cs := &contextSuggesterRequest{}
if q.prefix != "" {
cs.Prefix = q.prefix
}
suggester := make(map[string]interface{})
cs.Completion = suggester
if q.field != "" {
suggester["field"] = q.field
}
if q.size != nil {
suggester["size"] = *q.size
}
switch len(q.contextQueries) {
case 0:
case 1:
src, err := q.contextQueries[0].Source()
if err != nil {
return nil, err
}
suggester["contexts"] = src
default:
ctxq := make(map[string]interface{})
for _, query := range q.contextQueries {
src, err := query.Source()
if err != nil {
return nil, err
}
// Merge the dictionary into ctxq
m, ok := src.(map[string]interface{})
if !ok {
return nil, errors.New("elastic: context query is not a map")
}
for k, v := range m {
ctxq[k] = v
}
}
suggester["contexts"] = ctxq
}
if !includeName {
return cs, nil
}
source := make(map[string]interface{})
source[q.name] = cs
return source, nil
} | go | func (q *ContextSuggester) Source(includeName bool) (interface{}, error) {
cs := &contextSuggesterRequest{}
if q.prefix != "" {
cs.Prefix = q.prefix
}
suggester := make(map[string]interface{})
cs.Completion = suggester
if q.field != "" {
suggester["field"] = q.field
}
if q.size != nil {
suggester["size"] = *q.size
}
switch len(q.contextQueries) {
case 0:
case 1:
src, err := q.contextQueries[0].Source()
if err != nil {
return nil, err
}
suggester["contexts"] = src
default:
ctxq := make(map[string]interface{})
for _, query := range q.contextQueries {
src, err := query.Source()
if err != nil {
return nil, err
}
// Merge the dictionary into ctxq
m, ok := src.(map[string]interface{})
if !ok {
return nil, errors.New("elastic: context query is not a map")
}
for k, v := range m {
ctxq[k] = v
}
}
suggester["contexts"] = ctxq
}
if !includeName {
return cs, nil
}
source := make(map[string]interface{})
source[q.name] = cs
return source, nil
} | [
"func",
"(",
"q",
"*",
"ContextSuggester",
")",
"Source",
"(",
"includeName",
"bool",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"cs",
":=",
"&",
"contextSuggesterRequest",
"{",
"}",
"\n\n",
"if",
"q",
".",
"prefix",
"!=",
"\"",
"\"",
"{",
"cs",
".",
"Prefix",
"=",
"q",
".",
"prefix",
"\n",
"}",
"\n\n",
"suggester",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"cs",
".",
"Completion",
"=",
"suggester",
"\n\n",
"if",
"q",
".",
"field",
"!=",
"\"",
"\"",
"{",
"suggester",
"[",
"\"",
"\"",
"]",
"=",
"q",
".",
"field",
"\n",
"}",
"\n",
"if",
"q",
".",
"size",
"!=",
"nil",
"{",
"suggester",
"[",
"\"",
"\"",
"]",
"=",
"*",
"q",
".",
"size",
"\n",
"}",
"\n",
"switch",
"len",
"(",
"q",
".",
"contextQueries",
")",
"{",
"case",
"0",
":",
"case",
"1",
":",
"src",
",",
"err",
":=",
"q",
".",
"contextQueries",
"[",
"0",
"]",
".",
"Source",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"suggester",
"[",
"\"",
"\"",
"]",
"=",
"src",
"\n",
"default",
":",
"ctxq",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"query",
":=",
"range",
"q",
".",
"contextQueries",
"{",
"src",
",",
"err",
":=",
"query",
".",
"Source",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// Merge the dictionary into ctxq",
"m",
",",
"ok",
":=",
"src",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"m",
"{",
"ctxq",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"suggester",
"[",
"\"",
"\"",
"]",
"=",
"ctxq",
"\n",
"}",
"\n\n",
"if",
"!",
"includeName",
"{",
"return",
"cs",
",",
"nil",
"\n",
"}",
"\n\n",
"source",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"source",
"[",
"q",
".",
"name",
"]",
"=",
"cs",
"\n",
"return",
"source",
",",
"nil",
"\n",
"}"
] | // Creates the source for the context suggester. | [
"Creates",
"the",
"source",
"for",
"the",
"context",
"suggester",
"."
] | 0534a7b1bf47b1ccf57e905491a641709f8a623d | https://github.com/olivere/elastic/blob/0534a7b1bf47b1ccf57e905491a641709f8a623d/suggester_context.go#L74-L124 | train |
open-policy-agent/opa | download/config.go | ValidateAndInjectDefaults | func (c *Config) ValidateAndInjectDefaults() error {
min := defaultMinDelaySeconds
max := defaultMaxDelaySeconds
// reject bad min/max values
if c.Polling.MaxDelaySeconds != nil && c.Polling.MinDelaySeconds != nil {
if *c.Polling.MaxDelaySeconds < *c.Polling.MinDelaySeconds {
return fmt.Errorf("max polling delay must be >= min polling delay")
}
min = *c.Polling.MinDelaySeconds
max = *c.Polling.MaxDelaySeconds
} else if c.Polling.MaxDelaySeconds == nil && c.Polling.MinDelaySeconds != nil {
return fmt.Errorf("polling configuration missing 'max_delay_seconds'")
} else if c.Polling.MinDelaySeconds == nil && c.Polling.MaxDelaySeconds != nil {
return fmt.Errorf("polling configuration missing 'min_delay_seconds'")
}
// scale to seconds
minSeconds := int64(time.Duration(min) * time.Second)
c.Polling.MinDelaySeconds = &minSeconds
maxSeconds := int64(time.Duration(max) * time.Second)
c.Polling.MaxDelaySeconds = &maxSeconds
return nil
} | go | func (c *Config) ValidateAndInjectDefaults() error {
min := defaultMinDelaySeconds
max := defaultMaxDelaySeconds
// reject bad min/max values
if c.Polling.MaxDelaySeconds != nil && c.Polling.MinDelaySeconds != nil {
if *c.Polling.MaxDelaySeconds < *c.Polling.MinDelaySeconds {
return fmt.Errorf("max polling delay must be >= min polling delay")
}
min = *c.Polling.MinDelaySeconds
max = *c.Polling.MaxDelaySeconds
} else if c.Polling.MaxDelaySeconds == nil && c.Polling.MinDelaySeconds != nil {
return fmt.Errorf("polling configuration missing 'max_delay_seconds'")
} else if c.Polling.MinDelaySeconds == nil && c.Polling.MaxDelaySeconds != nil {
return fmt.Errorf("polling configuration missing 'min_delay_seconds'")
}
// scale to seconds
minSeconds := int64(time.Duration(min) * time.Second)
c.Polling.MinDelaySeconds = &minSeconds
maxSeconds := int64(time.Duration(max) * time.Second)
c.Polling.MaxDelaySeconds = &maxSeconds
return nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"ValidateAndInjectDefaults",
"(",
")",
"error",
"{",
"min",
":=",
"defaultMinDelaySeconds",
"\n",
"max",
":=",
"defaultMaxDelaySeconds",
"\n\n",
"// reject bad min/max values",
"if",
"c",
".",
"Polling",
".",
"MaxDelaySeconds",
"!=",
"nil",
"&&",
"c",
".",
"Polling",
".",
"MinDelaySeconds",
"!=",
"nil",
"{",
"if",
"*",
"c",
".",
"Polling",
".",
"MaxDelaySeconds",
"<",
"*",
"c",
".",
"Polling",
".",
"MinDelaySeconds",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"min",
"=",
"*",
"c",
".",
"Polling",
".",
"MinDelaySeconds",
"\n",
"max",
"=",
"*",
"c",
".",
"Polling",
".",
"MaxDelaySeconds",
"\n",
"}",
"else",
"if",
"c",
".",
"Polling",
".",
"MaxDelaySeconds",
"==",
"nil",
"&&",
"c",
".",
"Polling",
".",
"MinDelaySeconds",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"c",
".",
"Polling",
".",
"MinDelaySeconds",
"==",
"nil",
"&&",
"c",
".",
"Polling",
".",
"MaxDelaySeconds",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// scale to seconds",
"minSeconds",
":=",
"int64",
"(",
"time",
".",
"Duration",
"(",
"min",
")",
"*",
"time",
".",
"Second",
")",
"\n",
"c",
".",
"Polling",
".",
"MinDelaySeconds",
"=",
"&",
"minSeconds",
"\n\n",
"maxSeconds",
":=",
"int64",
"(",
"time",
".",
"Duration",
"(",
"max",
")",
"*",
"time",
".",
"Second",
")",
"\n",
"c",
".",
"Polling",
".",
"MaxDelaySeconds",
"=",
"&",
"maxSeconds",
"\n\n",
"return",
"nil",
"\n\n",
"}"
] | // ValidateAndInjectDefaults checks for configuration errors and ensures all
// values are set on the Config object. | [
"ValidateAndInjectDefaults",
"checks",
"for",
"configuration",
"errors",
"and",
"ensures",
"all",
"values",
"are",
"set",
"on",
"the",
"Config",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/download/config.go#L30-L57 | train |
open-policy-agent/opa | topdown/input.go | makeTree | func makeTree(k ast.Ref, v *ast.Term) ast.Object {
var obj ast.Object
for i := len(k) - 1; i >= 1; i-- {
obj = ast.NewObject(ast.Item(k[i], v))
v = &ast.Term{Value: obj}
}
obj = ast.NewObject(ast.Item(k[0], v))
return obj
} | go | func makeTree(k ast.Ref, v *ast.Term) ast.Object {
var obj ast.Object
for i := len(k) - 1; i >= 1; i-- {
obj = ast.NewObject(ast.Item(k[i], v))
v = &ast.Term{Value: obj}
}
obj = ast.NewObject(ast.Item(k[0], v))
return obj
} | [
"func",
"makeTree",
"(",
"k",
"ast",
".",
"Ref",
",",
"v",
"*",
"ast",
".",
"Term",
")",
"ast",
".",
"Object",
"{",
"var",
"obj",
"ast",
".",
"Object",
"\n",
"for",
"i",
":=",
"len",
"(",
"k",
")",
"-",
"1",
";",
"i",
">=",
"1",
";",
"i",
"--",
"{",
"obj",
"=",
"ast",
".",
"NewObject",
"(",
"ast",
".",
"Item",
"(",
"k",
"[",
"i",
"]",
",",
"v",
")",
")",
"\n",
"v",
"=",
"&",
"ast",
".",
"Term",
"{",
"Value",
":",
"obj",
"}",
"\n",
"}",
"\n",
"obj",
"=",
"ast",
".",
"NewObject",
"(",
"ast",
".",
"Item",
"(",
"k",
"[",
"0",
"]",
",",
"v",
")",
")",
"\n",
"return",
"obj",
"\n",
"}"
] | // makeTree returns an object that represents a document where the value v is
// the leaf and elements in k represent intermediate objects. | [
"makeTree",
"returns",
"an",
"object",
"that",
"represents",
"a",
"document",
"where",
"the",
"value",
"v",
"is",
"the",
"leaf",
"and",
"elements",
"in",
"k",
"represent",
"intermediate",
"objects",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/input.go#L66-L74 | train |
open-policy-agent/opa | storage/path.go | ParsePath | func ParsePath(str string) (path Path, ok bool) {
if len(str) == 0 {
return nil, false
}
if str[0] != '/' {
return nil, false
}
if len(str) == 1 {
return Path{}, true
}
parts := strings.Split(str[1:], "/")
return parts, true
} | go | func ParsePath(str string) (path Path, ok bool) {
if len(str) == 0 {
return nil, false
}
if str[0] != '/' {
return nil, false
}
if len(str) == 1 {
return Path{}, true
}
parts := strings.Split(str[1:], "/")
return parts, true
} | [
"func",
"ParsePath",
"(",
"str",
"string",
")",
"(",
"path",
"Path",
",",
"ok",
"bool",
")",
"{",
"if",
"len",
"(",
"str",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"if",
"str",
"[",
"0",
"]",
"!=",
"'/'",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"str",
")",
"==",
"1",
"{",
"return",
"Path",
"{",
"}",
",",
"true",
"\n",
"}",
"\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"str",
"[",
"1",
":",
"]",
",",
"\"",
"\"",
")",
"\n",
"return",
"parts",
",",
"true",
"\n",
"}"
] | // ParsePath returns a new path for the given str. | [
"ParsePath",
"returns",
"a",
"new",
"path",
"for",
"the",
"given",
"str",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/path.go#L20-L32 | train |
open-policy-agent/opa | storage/path.go | ParsePathEscaped | func ParsePathEscaped(str string) (path Path, ok bool) {
path, ok = ParsePath(str)
if !ok {
return
}
for i := range path {
segment, err := url.PathUnescape(path[i])
if err == nil {
path[i] = segment
}
}
return
} | go | func ParsePathEscaped(str string) (path Path, ok bool) {
path, ok = ParsePath(str)
if !ok {
return
}
for i := range path {
segment, err := url.PathUnescape(path[i])
if err == nil {
path[i] = segment
}
}
return
} | [
"func",
"ParsePathEscaped",
"(",
"str",
"string",
")",
"(",
"path",
"Path",
",",
"ok",
"bool",
")",
"{",
"path",
",",
"ok",
"=",
"ParsePath",
"(",
"str",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"path",
"{",
"segment",
",",
"err",
":=",
"url",
".",
"PathUnescape",
"(",
"path",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"path",
"[",
"i",
"]",
"=",
"segment",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // ParsePathEscaped returns a new path for the given escaped str. | [
"ParsePathEscaped",
"returns",
"a",
"new",
"path",
"for",
"the",
"given",
"escaped",
"str",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/path.go#L35-L47 | train |
open-policy-agent/opa | storage/path.go | NewPathForRef | func NewPathForRef(ref ast.Ref) (path Path, err error) {
if len(ref) == 0 {
return nil, fmt.Errorf("empty reference (indicates error in caller)")
}
if len(ref) == 1 {
return Path{}, nil
}
for _, term := range ref[1:] {
switch v := term.Value.(type) {
case ast.String:
path = append(path, string(v))
case ast.Number:
path = append(path, v.String())
case ast.Boolean, ast.Null:
return nil, &Error{
Code: NotFoundErr,
Message: fmt.Sprintf("%v: does not exist", ref),
}
case ast.Array, ast.Object, ast.Set:
return nil, fmt.Errorf("composites cannot be base document keys: %v", ref)
default:
return nil, fmt.Errorf("unresolved reference (indicates error in caller): %v", ref)
}
}
return path, nil
} | go | func NewPathForRef(ref ast.Ref) (path Path, err error) {
if len(ref) == 0 {
return nil, fmt.Errorf("empty reference (indicates error in caller)")
}
if len(ref) == 1 {
return Path{}, nil
}
for _, term := range ref[1:] {
switch v := term.Value.(type) {
case ast.String:
path = append(path, string(v))
case ast.Number:
path = append(path, v.String())
case ast.Boolean, ast.Null:
return nil, &Error{
Code: NotFoundErr,
Message: fmt.Sprintf("%v: does not exist", ref),
}
case ast.Array, ast.Object, ast.Set:
return nil, fmt.Errorf("composites cannot be base document keys: %v", ref)
default:
return nil, fmt.Errorf("unresolved reference (indicates error in caller): %v", ref)
}
}
return path, nil
} | [
"func",
"NewPathForRef",
"(",
"ref",
"ast",
".",
"Ref",
")",
"(",
"path",
"Path",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"ref",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"ref",
")",
"==",
"1",
"{",
"return",
"Path",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"term",
":=",
"range",
"ref",
"[",
"1",
":",
"]",
"{",
"switch",
"v",
":=",
"term",
".",
"Value",
".",
"(",
"type",
")",
"{",
"case",
"ast",
".",
"String",
":",
"path",
"=",
"append",
"(",
"path",
",",
"string",
"(",
"v",
")",
")",
"\n",
"case",
"ast",
".",
"Number",
":",
"path",
"=",
"append",
"(",
"path",
",",
"v",
".",
"String",
"(",
")",
")",
"\n",
"case",
"ast",
".",
"Boolean",
",",
"ast",
".",
"Null",
":",
"return",
"nil",
",",
"&",
"Error",
"{",
"Code",
":",
"NotFoundErr",
",",
"Message",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ref",
")",
",",
"}",
"\n",
"case",
"ast",
".",
"Array",
",",
"ast",
".",
"Object",
",",
"ast",
".",
"Set",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ref",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ref",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"path",
",",
"nil",
"\n",
"}"
] | // NewPathForRef returns a new path for the given ref. | [
"NewPathForRef",
"returns",
"a",
"new",
"path",
"for",
"the",
"given",
"ref",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/path.go#L50-L79 | train |
open-policy-agent/opa | storage/path.go | Compare | func (p Path) Compare(other Path) (cmp int) {
min := len(p)
if len(other) < min {
min = len(other)
}
for i := 0; i < min; i++ {
if cmp := strings.Compare(p[i], other[i]); cmp != 0 {
return cmp
}
}
if len(p) < len(other) {
return -1
}
if len(p) == len(other) {
return 0
}
return 1
} | go | func (p Path) Compare(other Path) (cmp int) {
min := len(p)
if len(other) < min {
min = len(other)
}
for i := 0; i < min; i++ {
if cmp := strings.Compare(p[i], other[i]); cmp != 0 {
return cmp
}
}
if len(p) < len(other) {
return -1
}
if len(p) == len(other) {
return 0
}
return 1
} | [
"func",
"(",
"p",
"Path",
")",
"Compare",
"(",
"other",
"Path",
")",
"(",
"cmp",
"int",
")",
"{",
"min",
":=",
"len",
"(",
"p",
")",
"\n",
"if",
"len",
"(",
"other",
")",
"<",
"min",
"{",
"min",
"=",
"len",
"(",
"other",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"min",
";",
"i",
"++",
"{",
"if",
"cmp",
":=",
"strings",
".",
"Compare",
"(",
"p",
"[",
"i",
"]",
",",
"other",
"[",
"i",
"]",
")",
";",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"p",
")",
"<",
"len",
"(",
"other",
")",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"if",
"len",
"(",
"p",
")",
"==",
"len",
"(",
"other",
")",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"}"
] | // Compare performs lexigraphical comparison on p and other and returns -1 if p
// is less than other, 0 if p is equal to other, or 1 if p is greater than
// other. | [
"Compare",
"performs",
"lexigraphical",
"comparison",
"on",
"p",
"and",
"other",
"and",
"returns",
"-",
"1",
"if",
"p",
"is",
"less",
"than",
"other",
"0",
"if",
"p",
"is",
"equal",
"to",
"other",
"or",
"1",
"if",
"p",
"is",
"greater",
"than",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/path.go#L84-L101 | train |
open-policy-agent/opa | storage/path.go | HasPrefix | func (p Path) HasPrefix(other Path) bool {
if len(other) > len(p) {
return false
}
for i := range other {
if p[i] != other[i] {
return false
}
}
return true
} | go | func (p Path) HasPrefix(other Path) bool {
if len(other) > len(p) {
return false
}
for i := range other {
if p[i] != other[i] {
return false
}
}
return true
} | [
"func",
"(",
"p",
"Path",
")",
"HasPrefix",
"(",
"other",
"Path",
")",
"bool",
"{",
"if",
"len",
"(",
"other",
")",
">",
"len",
"(",
"p",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"other",
"{",
"if",
"p",
"[",
"i",
"]",
"!=",
"other",
"[",
"i",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // HasPrefix returns true if p starts with other. | [
"HasPrefix",
"returns",
"true",
"if",
"p",
"starts",
"with",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/path.go#L109-L119 | train |
open-policy-agent/opa | storage/path.go | Ref | func (p Path) Ref(head *ast.Term) (ref ast.Ref) {
ref = make(ast.Ref, len(p)+1)
ref[0] = head
for i := range p {
idx, err := strconv.ParseInt(p[i], 10, 64)
if err == nil {
ref[i+1] = ast.IntNumberTerm(int(idx))
} else {
ref[i+1] = ast.StringTerm(p[i])
}
}
return ref
} | go | func (p Path) Ref(head *ast.Term) (ref ast.Ref) {
ref = make(ast.Ref, len(p)+1)
ref[0] = head
for i := range p {
idx, err := strconv.ParseInt(p[i], 10, 64)
if err == nil {
ref[i+1] = ast.IntNumberTerm(int(idx))
} else {
ref[i+1] = ast.StringTerm(p[i])
}
}
return ref
} | [
"func",
"(",
"p",
"Path",
")",
"Ref",
"(",
"head",
"*",
"ast",
".",
"Term",
")",
"(",
"ref",
"ast",
".",
"Ref",
")",
"{",
"ref",
"=",
"make",
"(",
"ast",
".",
"Ref",
",",
"len",
"(",
"p",
")",
"+",
"1",
")",
"\n",
"ref",
"[",
"0",
"]",
"=",
"head",
"\n",
"for",
"i",
":=",
"range",
"p",
"{",
"idx",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"p",
"[",
"i",
"]",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"ref",
"[",
"i",
"+",
"1",
"]",
"=",
"ast",
".",
"IntNumberTerm",
"(",
"int",
"(",
"idx",
")",
")",
"\n",
"}",
"else",
"{",
"ref",
"[",
"i",
"+",
"1",
"]",
"=",
"ast",
".",
"StringTerm",
"(",
"p",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ref",
"\n",
"}"
] | // Ref returns a ref that represents p rooted at head. | [
"Ref",
"returns",
"a",
"ref",
"that",
"represents",
"p",
"rooted",
"at",
"head",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/path.go#L122-L134 | train |
open-policy-agent/opa | storage/path.go | MustParsePath | func MustParsePath(s string) Path {
path, ok := ParsePath(s)
if !ok {
panic(s)
}
return path
} | go | func MustParsePath(s string) Path {
path, ok := ParsePath(s)
if !ok {
panic(s)
}
return path
} | [
"func",
"MustParsePath",
"(",
"s",
"string",
")",
"Path",
"{",
"path",
",",
"ok",
":=",
"ParsePath",
"(",
"s",
")",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"s",
")",
"\n",
"}",
"\n",
"return",
"path",
"\n",
"}"
] | // MustParsePath returns a new Path for s. If s cannot be parsed, this function
// will panic. This is mostly for test purposes. | [
"MustParsePath",
"returns",
"a",
"new",
"Path",
"for",
"s",
".",
"If",
"s",
"cannot",
"be",
"parsed",
"this",
"function",
"will",
"panic",
".",
"This",
"is",
"mostly",
"for",
"test",
"purposes",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/path.go#L146-L152 | train |
open-policy-agent/opa | ast/parser_internal.go | currentLocation | func currentLocation(c *current) *Location {
return NewLocation(c.text, c.globalStore[filenameKey].(string), c.pos.line, c.pos.col)
} | go | func currentLocation(c *current) *Location {
return NewLocation(c.text, c.globalStore[filenameKey].(string), c.pos.line, c.pos.col)
} | [
"func",
"currentLocation",
"(",
"c",
"*",
"current",
")",
"*",
"Location",
"{",
"return",
"NewLocation",
"(",
"c",
".",
"text",
",",
"c",
".",
"globalStore",
"[",
"filenameKey",
"]",
".",
"(",
"string",
")",
",",
"c",
".",
"pos",
".",
"line",
",",
"c",
".",
"pos",
".",
"col",
")",
"\n",
"}"
] | // currentLocation converts the parser context to a Location object. | [
"currentLocation",
"converts",
"the",
"parser",
"context",
"to",
"a",
"Location",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_internal.go#L34-L36 | train |
open-policy-agent/opa | topdown/errors.go | IsCancel | func IsCancel(err error) bool {
if e, ok := err.(*Error); ok {
return e.Code == CancelErr
}
return false
} | go | func IsCancel(err error) bool {
if e, ok := err.(*Error); ok {
return e.Code == CancelErr
}
return false
} | [
"func",
"IsCancel",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"Error",
")",
";",
"ok",
"{",
"return",
"e",
".",
"Code",
"==",
"CancelErr",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsCancel returns true if err was caused by cancellation. | [
"IsCancel",
"returns",
"true",
"if",
"err",
"was",
"caused",
"by",
"cancellation",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/errors.go#L55-L60 | train |
open-policy-agent/opa | storage/storage.go | NewTransactionOrDie | func NewTransactionOrDie(ctx context.Context, store Store, params ...TransactionParams) Transaction {
txn, err := store.NewTransaction(ctx, params...)
if err != nil {
panic(err)
}
return txn
} | go | func NewTransactionOrDie(ctx context.Context, store Store, params ...TransactionParams) Transaction {
txn, err := store.NewTransaction(ctx, params...)
if err != nil {
panic(err)
}
return txn
} | [
"func",
"NewTransactionOrDie",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"Store",
",",
"params",
"...",
"TransactionParams",
")",
"Transaction",
"{",
"txn",
",",
"err",
":=",
"store",
".",
"NewTransaction",
"(",
"ctx",
",",
"params",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"txn",
"\n",
"}"
] | // NewTransactionOrDie is a helper function to create a new transaction. If the
// storage layer cannot create a new transaction, this function will panic. This
// function should only be used for tests. | [
"NewTransactionOrDie",
"is",
"a",
"helper",
"function",
"to",
"create",
"a",
"new",
"transaction",
".",
"If",
"the",
"storage",
"layer",
"cannot",
"create",
"a",
"new",
"transaction",
"this",
"function",
"will",
"panic",
".",
"This",
"function",
"should",
"only",
"be",
"used",
"for",
"tests",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/storage.go#L14-L20 | train |
open-policy-agent/opa | storage/storage.go | ReadOne | func ReadOne(ctx context.Context, store Store, path Path) (interface{}, error) {
txn, err := store.NewTransaction(ctx)
if err != nil {
return nil, err
}
defer store.Abort(ctx, txn)
return store.Read(ctx, txn, path)
} | go | func ReadOne(ctx context.Context, store Store, path Path) (interface{}, error) {
txn, err := store.NewTransaction(ctx)
if err != nil {
return nil, err
}
defer store.Abort(ctx, txn)
return store.Read(ctx, txn, path)
} | [
"func",
"ReadOne",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"Store",
",",
"path",
"Path",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"txn",
",",
"err",
":=",
"store",
".",
"NewTransaction",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"store",
".",
"Abort",
"(",
"ctx",
",",
"txn",
")",
"\n\n",
"return",
"store",
".",
"Read",
"(",
"ctx",
",",
"txn",
",",
"path",
")",
"\n",
"}"
] | // ReadOne is a convenience function to read a single value from the provided Store. It
// will create a new Transaction to perform the read with, and clean up after itself
// should an error occur. | [
"ReadOne",
"is",
"a",
"convenience",
"function",
"to",
"read",
"a",
"single",
"value",
"from",
"the",
"provided",
"Store",
".",
"It",
"will",
"create",
"a",
"new",
"Transaction",
"to",
"perform",
"the",
"read",
"with",
"and",
"clean",
"up",
"after",
"itself",
"should",
"an",
"error",
"occur",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/storage.go#L25-L33 | train |
open-policy-agent/opa | storage/storage.go | WriteOne | func WriteOne(ctx context.Context, store Store, op PatchOp, path Path, value interface{}) error {
txn, err := store.NewTransaction(ctx, WriteParams)
if err != nil {
return err
}
if err := store.Write(ctx, txn, op, path, value); err != nil {
store.Abort(ctx, txn)
return err
}
return store.Commit(ctx, txn)
} | go | func WriteOne(ctx context.Context, store Store, op PatchOp, path Path, value interface{}) error {
txn, err := store.NewTransaction(ctx, WriteParams)
if err != nil {
return err
}
if err := store.Write(ctx, txn, op, path, value); err != nil {
store.Abort(ctx, txn)
return err
}
return store.Commit(ctx, txn)
} | [
"func",
"WriteOne",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"Store",
",",
"op",
"PatchOp",
",",
"path",
"Path",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"txn",
",",
"err",
":=",
"store",
".",
"NewTransaction",
"(",
"ctx",
",",
"WriteParams",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"store",
".",
"Write",
"(",
"ctx",
",",
"txn",
",",
"op",
",",
"path",
",",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"store",
".",
"Abort",
"(",
"ctx",
",",
"txn",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"store",
".",
"Commit",
"(",
"ctx",
",",
"txn",
")",
"\n",
"}"
] | // WriteOne is a convenience function to write a single value to the provided Store. It
// will create a new Transaction to perform the write with, and clean up after itself
// should an error occur. | [
"WriteOne",
"is",
"a",
"convenience",
"function",
"to",
"write",
"a",
"single",
"value",
"to",
"the",
"provided",
"Store",
".",
"It",
"will",
"create",
"a",
"new",
"Transaction",
"to",
"perform",
"the",
"write",
"with",
"and",
"clean",
"up",
"after",
"itself",
"should",
"an",
"error",
"occur",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/storage.go#L38-L50 | train |
open-policy-agent/opa | storage/storage.go | MakeDir | func MakeDir(ctx context.Context, store Store, txn Transaction, path Path) (err error) {
if len(path) == 0 {
return nil
}
node, err := store.Read(ctx, txn, path)
if err != nil {
if !IsNotFound(err) {
return err
}
if err := MakeDir(ctx, store, txn, path[:len(path)-1]); err != nil {
return err
} else if err := store.Write(ctx, txn, AddOp, path, map[string]interface{}{}); err != nil {
return err
}
return nil
}
if _, ok := node.(map[string]interface{}); ok {
return nil
}
return writeConflictError(path)
} | go | func MakeDir(ctx context.Context, store Store, txn Transaction, path Path) (err error) {
if len(path) == 0 {
return nil
}
node, err := store.Read(ctx, txn, path)
if err != nil {
if !IsNotFound(err) {
return err
}
if err := MakeDir(ctx, store, txn, path[:len(path)-1]); err != nil {
return err
} else if err := store.Write(ctx, txn, AddOp, path, map[string]interface{}{}); err != nil {
return err
}
return nil
}
if _, ok := node.(map[string]interface{}); ok {
return nil
}
return writeConflictError(path)
} | [
"func",
"MakeDir",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"Store",
",",
"txn",
"Transaction",
",",
"path",
"Path",
")",
"(",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"path",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"node",
",",
"err",
":=",
"store",
".",
"Read",
"(",
"ctx",
",",
"txn",
",",
"path",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"!",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"MakeDir",
"(",
"ctx",
",",
"store",
",",
"txn",
",",
"path",
"[",
":",
"len",
"(",
"path",
")",
"-",
"1",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"else",
"if",
"err",
":=",
"store",
".",
"Write",
"(",
"ctx",
",",
"txn",
",",
"AddOp",
",",
"path",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"node",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"writeConflictError",
"(",
"path",
")",
"\n\n",
"}"
] | // MakeDir inserts an empty object at path. If the parent path does not exist,
// MakeDir will create it recursively. | [
"MakeDir",
"inserts",
"an",
"empty",
"object",
"at",
"path",
".",
"If",
"the",
"parent",
"path",
"does",
"not",
"exist",
"MakeDir",
"will",
"create",
"it",
"recursively",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/storage.go#L54-L82 | train |
open-policy-agent/opa | storage/storage.go | Txn | func Txn(ctx context.Context, store Store, params TransactionParams, f func(Transaction) error) error {
txn, err := store.NewTransaction(ctx, params)
if err != nil {
return err
}
if err := f(txn); err != nil {
store.Abort(ctx, txn)
return err
}
return store.Commit(ctx, txn)
} | go | func Txn(ctx context.Context, store Store, params TransactionParams, f func(Transaction) error) error {
txn, err := store.NewTransaction(ctx, params)
if err != nil {
return err
}
if err := f(txn); err != nil {
store.Abort(ctx, txn)
return err
}
return store.Commit(ctx, txn)
} | [
"func",
"Txn",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"Store",
",",
"params",
"TransactionParams",
",",
"f",
"func",
"(",
"Transaction",
")",
"error",
")",
"error",
"{",
"txn",
",",
"err",
":=",
"store",
".",
"NewTransaction",
"(",
"ctx",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"f",
"(",
"txn",
")",
";",
"err",
"!=",
"nil",
"{",
"store",
".",
"Abort",
"(",
"ctx",
",",
"txn",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"store",
".",
"Commit",
"(",
"ctx",
",",
"txn",
")",
"\n",
"}"
] | // Txn is a convenience function that executes f inside a new transaction
// opened on the store. If the function returns an error, the transaction is
// aborted and the error is returned. Otherwise, the transaction is committed
// and the result of the commit is returned. | [
"Txn",
"is",
"a",
"convenience",
"function",
"that",
"executes",
"f",
"inside",
"a",
"new",
"transaction",
"opened",
"on",
"the",
"store",
".",
"If",
"the",
"function",
"returns",
"an",
"error",
"the",
"transaction",
"is",
"aborted",
"and",
"the",
"error",
"is",
"returned",
".",
"Otherwise",
"the",
"transaction",
"is",
"committed",
"and",
"the",
"result",
"of",
"the",
"commit",
"is",
"returned",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/storage.go#L88-L101 | train |
open-policy-agent/opa | storage/storage.go | NonEmpty | func NonEmpty(ctx context.Context, store Store, txn Transaction) func([]string) (bool, error) {
return func(path []string) (bool, error) {
if _, err := store.Read(ctx, txn, Path(path)); err == nil {
return true, nil
} else if !IsNotFound(err) {
return false, err
}
for i := len(path) - 1; i > 0; i-- {
val, err := store.Read(ctx, txn, Path(path[:i]))
if err != nil && !IsNotFound(err) {
return false, err
} else if err == nil {
if _, ok := val.(map[string]interface{}); ok {
return false, nil
}
return true, nil
}
}
return false, nil
}
} | go | func NonEmpty(ctx context.Context, store Store, txn Transaction) func([]string) (bool, error) {
return func(path []string) (bool, error) {
if _, err := store.Read(ctx, txn, Path(path)); err == nil {
return true, nil
} else if !IsNotFound(err) {
return false, err
}
for i := len(path) - 1; i > 0; i-- {
val, err := store.Read(ctx, txn, Path(path[:i]))
if err != nil && !IsNotFound(err) {
return false, err
} else if err == nil {
if _, ok := val.(map[string]interface{}); ok {
return false, nil
}
return true, nil
}
}
return false, nil
}
} | [
"func",
"NonEmpty",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"Store",
",",
"txn",
"Transaction",
")",
"func",
"(",
"[",
"]",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"func",
"(",
"path",
"[",
"]",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"_",
",",
"err",
":=",
"store",
".",
"Read",
"(",
"ctx",
",",
"txn",
",",
"Path",
"(",
"path",
")",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"else",
"if",
"!",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"for",
"i",
":=",
"len",
"(",
"path",
")",
"-",
"1",
";",
"i",
">",
"0",
";",
"i",
"--",
"{",
"val",
",",
"err",
":=",
"store",
".",
"Read",
"(",
"ctx",
",",
"txn",
",",
"Path",
"(",
"path",
"[",
":",
"i",
"]",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"else",
"if",
"err",
"==",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"val",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // NonEmpty returns a function that tests if a path is non-empty. A
// path is non-empty if a Read on the path returns a value or a Read
// on any of the path prefixes returns a non-object value. | [
"NonEmpty",
"returns",
"a",
"function",
"that",
"tests",
"if",
"a",
"path",
"is",
"non",
"-",
"empty",
".",
"A",
"path",
"is",
"non",
"-",
"empty",
"if",
"a",
"Read",
"on",
"the",
"path",
"returns",
"a",
"value",
"or",
"a",
"Read",
"on",
"any",
"of",
"the",
"path",
"prefixes",
"returns",
"a",
"non",
"-",
"object",
"value",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/storage.go#L106-L126 | train |
open-policy-agent/opa | server/buffer.go | NewBoundedBuffer | func NewBoundedBuffer(n int) Buffer {
if n <= 0 {
panic("size must be greater than 0")
}
return &buffer{ring: make([]*Info, n, n)}
} | go | func NewBoundedBuffer(n int) Buffer {
if n <= 0 {
panic("size must be greater than 0")
}
return &buffer{ring: make([]*Info, n, n)}
} | [
"func",
"NewBoundedBuffer",
"(",
"n",
"int",
")",
"Buffer",
"{",
"if",
"n",
"<=",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"buffer",
"{",
"ring",
":",
"make",
"(",
"[",
"]",
"*",
"Info",
",",
"n",
",",
"n",
")",
"}",
"\n",
"}"
] | // NewBoundedBuffer creates a new Buffer with maximum size n. NewBoundedBuffer
// will panic if n is not positive. | [
"NewBoundedBuffer",
"creates",
"a",
"new",
"Buffer",
"with",
"maximum",
"size",
"n",
".",
"NewBoundedBuffer",
"will",
"panic",
"if",
"n",
"is",
"not",
"positive",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/buffer.go#L38-L44 | train |
open-policy-agent/opa | repl/repl.go | New | func New(store storage.Store, historyPath string, output io.Writer, outputFormat string, errLimit int, banner string) *REPL {
return &REPL{
output: output,
store: store,
modules: map[string]*ast.Module{},
outputFormat: outputFormat,
explain: explainOff,
historyPath: historyPath,
initPrompt: "> ",
bufferPrompt: "| ",
banner: banner,
errLimit: errLimit,
prettyLimit: defaultPrettyLimit,
}
} | go | func New(store storage.Store, historyPath string, output io.Writer, outputFormat string, errLimit int, banner string) *REPL {
return &REPL{
output: output,
store: store,
modules: map[string]*ast.Module{},
outputFormat: outputFormat,
explain: explainOff,
historyPath: historyPath,
initPrompt: "> ",
bufferPrompt: "| ",
banner: banner,
errLimit: errLimit,
prettyLimit: defaultPrettyLimit,
}
} | [
"func",
"New",
"(",
"store",
"storage",
".",
"Store",
",",
"historyPath",
"string",
",",
"output",
"io",
".",
"Writer",
",",
"outputFormat",
"string",
",",
"errLimit",
"int",
",",
"banner",
"string",
")",
"*",
"REPL",
"{",
"return",
"&",
"REPL",
"{",
"output",
":",
"output",
",",
"store",
":",
"store",
",",
"modules",
":",
"map",
"[",
"string",
"]",
"*",
"ast",
".",
"Module",
"{",
"}",
",",
"outputFormat",
":",
"outputFormat",
",",
"explain",
":",
"explainOff",
",",
"historyPath",
":",
"historyPath",
",",
"initPrompt",
":",
"\"",
"\"",
",",
"bufferPrompt",
":",
"\"",
"\"",
",",
"banner",
":",
"banner",
",",
"errLimit",
":",
"errLimit",
",",
"prettyLimit",
":",
"defaultPrettyLimit",
",",
"}",
"\n",
"}"
] | // New returns a new instance of the REPL. | [
"New",
"returns",
"a",
"new",
"instance",
"of",
"the",
"REPL",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/repl/repl.go#L73-L88 | train |
open-policy-agent/opa | repl/repl.go | Loop | func (r *REPL) Loop(ctx context.Context) {
// Initialize the liner library.
line := liner.NewLiner()
defer line.Close()
line.SetCtrlCAborts(true)
line.SetMultiLineMode(true)
r.loadHistory(line)
if len(r.banner) > 0 {
fmt.Fprintln(r.output, r.banner)
}
line.SetCompleter(r.complete)
loop:
for true {
input, err := line.Prompt(r.getPrompt())
// prompt on ctrl+d
if err == io.EOF {
goto exitPrompt
}
// reset on ctrl+c
if err == liner.ErrPromptAborted {
continue
}
// exit on unknown error
if err != nil {
fmt.Fprintln(r.output, "error (fatal):", err)
os.Exit(1)
}
if err := r.OneShot(ctx, input); err != nil {
switch err := err.(type) {
case stop:
goto exit
default:
fmt.Fprintln(r.output, err)
}
}
line.AppendHistory(input)
}
exitPrompt:
fmt.Fprintln(r.output)
for true {
input, err := line.Prompt(exitPromptMessage)
// exit on ctrl+d
if err == io.EOF {
break
}
// reset on ctrl+c
if err == liner.ErrPromptAborted {
goto loop
}
// exit on unknown error
if err != nil {
fmt.Fprintln(r.output, "error (fatal):", err)
os.Exit(1)
}
switch strings.ToLower(input) {
case "", "y", "yes":
goto exit
case "n", "no":
goto loop
}
}
exit:
r.saveHistory(line)
} | go | func (r *REPL) Loop(ctx context.Context) {
// Initialize the liner library.
line := liner.NewLiner()
defer line.Close()
line.SetCtrlCAborts(true)
line.SetMultiLineMode(true)
r.loadHistory(line)
if len(r.banner) > 0 {
fmt.Fprintln(r.output, r.banner)
}
line.SetCompleter(r.complete)
loop:
for true {
input, err := line.Prompt(r.getPrompt())
// prompt on ctrl+d
if err == io.EOF {
goto exitPrompt
}
// reset on ctrl+c
if err == liner.ErrPromptAborted {
continue
}
// exit on unknown error
if err != nil {
fmt.Fprintln(r.output, "error (fatal):", err)
os.Exit(1)
}
if err := r.OneShot(ctx, input); err != nil {
switch err := err.(type) {
case stop:
goto exit
default:
fmt.Fprintln(r.output, err)
}
}
line.AppendHistory(input)
}
exitPrompt:
fmt.Fprintln(r.output)
for true {
input, err := line.Prompt(exitPromptMessage)
// exit on ctrl+d
if err == io.EOF {
break
}
// reset on ctrl+c
if err == liner.ErrPromptAborted {
goto loop
}
// exit on unknown error
if err != nil {
fmt.Fprintln(r.output, "error (fatal):", err)
os.Exit(1)
}
switch strings.ToLower(input) {
case "", "y", "yes":
goto exit
case "n", "no":
goto loop
}
}
exit:
r.saveHistory(line)
} | [
"func",
"(",
"r",
"*",
"REPL",
")",
"Loop",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"// Initialize the liner library.",
"line",
":=",
"liner",
".",
"NewLiner",
"(",
")",
"\n",
"defer",
"line",
".",
"Close",
"(",
")",
"\n",
"line",
".",
"SetCtrlCAborts",
"(",
"true",
")",
"\n",
"line",
".",
"SetMultiLineMode",
"(",
"true",
")",
"\n",
"r",
".",
"loadHistory",
"(",
"line",
")",
"\n\n",
"if",
"len",
"(",
"r",
".",
"banner",
")",
">",
"0",
"{",
"fmt",
".",
"Fprintln",
"(",
"r",
".",
"output",
",",
"r",
".",
"banner",
")",
"\n",
"}",
"\n\n",
"line",
".",
"SetCompleter",
"(",
"r",
".",
"complete",
")",
"\n\n",
"loop",
":",
"for",
"true",
"{",
"input",
",",
"err",
":=",
"line",
".",
"Prompt",
"(",
"r",
".",
"getPrompt",
"(",
")",
")",
"\n\n",
"// prompt on ctrl+d",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"goto",
"exitPrompt",
"\n",
"}",
"\n\n",
"// reset on ctrl+c",
"if",
"err",
"==",
"liner",
".",
"ErrPromptAborted",
"{",
"continue",
"\n",
"}",
"\n\n",
"// exit on unknown error",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"r",
".",
"output",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"r",
".",
"OneShot",
"(",
"ctx",
",",
"input",
")",
";",
"err",
"!=",
"nil",
"{",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"stop",
":",
"goto",
"exit",
"\n",
"default",
":",
"fmt",
".",
"Fprintln",
"(",
"r",
".",
"output",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"line",
".",
"AppendHistory",
"(",
"input",
")",
"\n",
"}",
"\n\n",
"exitPrompt",
":",
"fmt",
".",
"Fprintln",
"(",
"r",
".",
"output",
")",
"\n\n",
"for",
"true",
"{",
"input",
",",
"err",
":=",
"line",
".",
"Prompt",
"(",
"exitPromptMessage",
")",
"\n\n",
"// exit on ctrl+d",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"break",
"\n",
"}",
"\n\n",
"// reset on ctrl+c",
"if",
"err",
"==",
"liner",
".",
"ErrPromptAborted",
"{",
"goto",
"loop",
"\n",
"}",
"\n\n",
"// exit on unknown error",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"r",
".",
"output",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}",
"\n\n",
"switch",
"strings",
".",
"ToLower",
"(",
"input",
")",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"goto",
"exit",
"\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"goto",
"loop",
"\n",
"}",
"\n",
"}",
"\n\n",
"exit",
":",
"r",
".",
"saveHistory",
"(",
"line",
")",
"\n",
"}"
] | // Loop will run until the user enters "exit", Ctrl+C, Ctrl+D, or an unexpected error occurs. | [
"Loop",
"will",
"run",
"until",
"the",
"user",
"enters",
"exit",
"Ctrl",
"+",
"C",
"Ctrl",
"+",
"D",
"or",
"an",
"unexpected",
"error",
"occurs",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/repl/repl.go#L113-L193 | train |
open-policy-agent/opa | repl/repl.go | OneShot | func (r *REPL) OneShot(ctx context.Context, line string) error {
var err error
r.txn, err = r.store.NewTransaction(ctx)
if err != nil {
return err
}
defer r.store.Abort(ctx, r.txn)
if r.metrics != nil {
defer r.metrics.Clear()
}
if len(r.buffer) == 0 {
if cmd := newCommand(line); cmd != nil {
switch cmd.op {
case "dump":
return r.cmdDump(ctx, cmd.args)
case "json":
return r.cmdFormat("json")
case "show":
return r.cmdShow(cmd.args)
case "unset":
return r.cmdUnset(ctx, cmd.args)
case "pretty":
return r.cmdFormat("pretty")
case "pretty-limit":
return r.cmdPrettyLimit(cmd.args)
case "trace":
return r.cmdTrace()
case "metrics":
return r.cmdMetrics()
case "instrument":
return r.cmdInstrument()
case "profile":
return r.cmdProfile()
case "types":
return r.cmdTypes()
case "unknown":
return r.cmdUnknown(cmd.args)
case "help":
return r.cmdHelp(cmd.args)
case "exit":
return r.cmdExit()
}
}
r.buffer = append(r.buffer, line)
return r.evalBufferOne(ctx)
}
r.buffer = append(r.buffer, line)
if len(line) == 0 {
return r.evalBufferMulti(ctx)
}
return nil
} | go | func (r *REPL) OneShot(ctx context.Context, line string) error {
var err error
r.txn, err = r.store.NewTransaction(ctx)
if err != nil {
return err
}
defer r.store.Abort(ctx, r.txn)
if r.metrics != nil {
defer r.metrics.Clear()
}
if len(r.buffer) == 0 {
if cmd := newCommand(line); cmd != nil {
switch cmd.op {
case "dump":
return r.cmdDump(ctx, cmd.args)
case "json":
return r.cmdFormat("json")
case "show":
return r.cmdShow(cmd.args)
case "unset":
return r.cmdUnset(ctx, cmd.args)
case "pretty":
return r.cmdFormat("pretty")
case "pretty-limit":
return r.cmdPrettyLimit(cmd.args)
case "trace":
return r.cmdTrace()
case "metrics":
return r.cmdMetrics()
case "instrument":
return r.cmdInstrument()
case "profile":
return r.cmdProfile()
case "types":
return r.cmdTypes()
case "unknown":
return r.cmdUnknown(cmd.args)
case "help":
return r.cmdHelp(cmd.args)
case "exit":
return r.cmdExit()
}
}
r.buffer = append(r.buffer, line)
return r.evalBufferOne(ctx)
}
r.buffer = append(r.buffer, line)
if len(line) == 0 {
return r.evalBufferMulti(ctx)
}
return nil
} | [
"func",
"(",
"r",
"*",
"REPL",
")",
"OneShot",
"(",
"ctx",
"context",
".",
"Context",
",",
"line",
"string",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"r",
".",
"txn",
",",
"err",
"=",
"r",
".",
"store",
".",
"NewTransaction",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"defer",
"r",
".",
"store",
".",
"Abort",
"(",
"ctx",
",",
"r",
".",
"txn",
")",
"\n\n",
"if",
"r",
".",
"metrics",
"!=",
"nil",
"{",
"defer",
"r",
".",
"metrics",
".",
"Clear",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"r",
".",
"buffer",
")",
"==",
"0",
"{",
"if",
"cmd",
":=",
"newCommand",
"(",
"line",
")",
";",
"cmd",
"!=",
"nil",
"{",
"switch",
"cmd",
".",
"op",
"{",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdDump",
"(",
"ctx",
",",
"cmd",
".",
"args",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdFormat",
"(",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdShow",
"(",
"cmd",
".",
"args",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdUnset",
"(",
"ctx",
",",
"cmd",
".",
"args",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdFormat",
"(",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdPrettyLimit",
"(",
"cmd",
".",
"args",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdTrace",
"(",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdMetrics",
"(",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdInstrument",
"(",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdProfile",
"(",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdTypes",
"(",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdUnknown",
"(",
"cmd",
".",
"args",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdHelp",
"(",
"cmd",
".",
"args",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"cmdExit",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"r",
".",
"buffer",
"=",
"append",
"(",
"r",
".",
"buffer",
",",
"line",
")",
"\n",
"return",
"r",
".",
"evalBufferOne",
"(",
"ctx",
")",
"\n",
"}",
"\n\n",
"r",
".",
"buffer",
"=",
"append",
"(",
"r",
".",
"buffer",
",",
"line",
")",
"\n",
"if",
"len",
"(",
"line",
")",
"==",
"0",
"{",
"return",
"r",
".",
"evalBufferMulti",
"(",
"ctx",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // OneShot evaluates the line and prints the result. If an error occurs it is
// returned for the caller to display. | [
"OneShot",
"evaluates",
"the",
"line",
"and",
"prints",
"the",
"result",
".",
"If",
"an",
"error",
"occurs",
"it",
"is",
"returned",
"for",
"the",
"caller",
"to",
"display",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/repl/repl.go#L197-L255 | train |
open-policy-agent/opa | repl/repl.go | DisableMultiLineBuffering | func (r *REPL) DisableMultiLineBuffering(yes bool) *REPL {
r.bufferDisabled = yes
return r
} | go | func (r *REPL) DisableMultiLineBuffering(yes bool) *REPL {
r.bufferDisabled = yes
return r
} | [
"func",
"(",
"r",
"*",
"REPL",
")",
"DisableMultiLineBuffering",
"(",
"yes",
"bool",
")",
"*",
"REPL",
"{",
"r",
".",
"bufferDisabled",
"=",
"yes",
"\n",
"return",
"r",
"\n",
"}"
] | // DisableMultiLineBuffering causes the REPL to not buffer lines when a parse
// error occurs. Instead, the error will be returned to the caller. | [
"DisableMultiLineBuffering",
"causes",
"the",
"REPL",
"to",
"not",
"buffer",
"lines",
"when",
"a",
"parse",
"error",
"occurs",
".",
"Instead",
"the",
"error",
"will",
"be",
"returned",
"to",
"the",
"caller",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/repl/repl.go#L259-L262 | train |
open-policy-agent/opa | repl/repl.go | DisableUndefinedOutput | func (r *REPL) DisableUndefinedOutput(yes bool) *REPL {
r.undefinedDisabled = yes
return r
} | go | func (r *REPL) DisableUndefinedOutput(yes bool) *REPL {
r.undefinedDisabled = yes
return r
} | [
"func",
"(",
"r",
"*",
"REPL",
")",
"DisableUndefinedOutput",
"(",
"yes",
"bool",
")",
"*",
"REPL",
"{",
"r",
".",
"undefinedDisabled",
"=",
"yes",
"\n",
"return",
"r",
"\n",
"}"
] | // DisableUndefinedOutput causes the REPL to not print any output when the query
// is undefined. | [
"DisableUndefinedOutput",
"causes",
"the",
"REPL",
"to",
"not",
"print",
"any",
"output",
"when",
"the",
"query",
"is",
"undefined",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/repl/repl.go#L266-L269 | train |
open-policy-agent/opa | repl/repl.go | loadInput | func (r *REPL) loadInput(ctx context.Context, compiler *ast.Compiler) (ast.Value, error) {
q := topdown.NewQuery(ast.MustParseBody("data.repl.input = x")).
WithCompiler(compiler).
WithStore(r.store).
WithTransaction(r.txn)
qrs, err := q.Run(ctx)
if err != nil {
return nil, err
}
if len(qrs) != 1 {
return nil, nil
}
return qrs[0][ast.Var("x")].Value, nil
} | go | func (r *REPL) loadInput(ctx context.Context, compiler *ast.Compiler) (ast.Value, error) {
q := topdown.NewQuery(ast.MustParseBody("data.repl.input = x")).
WithCompiler(compiler).
WithStore(r.store).
WithTransaction(r.txn)
qrs, err := q.Run(ctx)
if err != nil {
return nil, err
}
if len(qrs) != 1 {
return nil, nil
}
return qrs[0][ast.Var("x")].Value, nil
} | [
"func",
"(",
"r",
"*",
"REPL",
")",
"loadInput",
"(",
"ctx",
"context",
".",
"Context",
",",
"compiler",
"*",
"ast",
".",
"Compiler",
")",
"(",
"ast",
".",
"Value",
",",
"error",
")",
"{",
"q",
":=",
"topdown",
".",
"NewQuery",
"(",
"ast",
".",
"MustParseBody",
"(",
"\"",
"\"",
")",
")",
".",
"WithCompiler",
"(",
"compiler",
")",
".",
"WithStore",
"(",
"r",
".",
"store",
")",
".",
"WithTransaction",
"(",
"r",
".",
"txn",
")",
"\n\n",
"qrs",
",",
"err",
":=",
"q",
".",
"Run",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"qrs",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"qrs",
"[",
"0",
"]",
"[",
"ast",
".",
"Var",
"(",
"\"",
"\"",
")",
"]",
".",
"Value",
",",
"nil",
"\n",
"}"
] | // loadInput returns the input defined in the REPL. The REPL loads the
// input from the data.repl.input document. | [
"loadInput",
"returns",
"the",
"input",
"defined",
"in",
"the",
"REPL",
".",
"The",
"REPL",
"loads",
"the",
"input",
"from",
"the",
"data",
".",
"repl",
".",
"input",
"document",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/repl/repl.go#L741-L758 | train |
open-policy-agent/opa | util/hashmap.go | NewHashMap | func NewHashMap(eq func(T, T) bool, hash func(T) int) *HashMap {
return &HashMap{
eq: eq,
hash: hash,
table: make(map[int]*hashEntry),
size: 0,
}
} | go | func NewHashMap(eq func(T, T) bool, hash func(T) int) *HashMap {
return &HashMap{
eq: eq,
hash: hash,
table: make(map[int]*hashEntry),
size: 0,
}
} | [
"func",
"NewHashMap",
"(",
"eq",
"func",
"(",
"T",
",",
"T",
")",
"bool",
",",
"hash",
"func",
"(",
"T",
")",
"int",
")",
"*",
"HashMap",
"{",
"return",
"&",
"HashMap",
"{",
"eq",
":",
"eq",
",",
"hash",
":",
"hash",
",",
"table",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"*",
"hashEntry",
")",
",",
"size",
":",
"0",
",",
"}",
"\n",
"}"
] | // NewHashMap returns a new empty HashMap. | [
"NewHashMap",
"returns",
"a",
"new",
"empty",
"HashMap",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/hashmap.go#L28-L35 | train |
open-policy-agent/opa | util/hashmap.go | Copy | func (h *HashMap) Copy() *HashMap {
cpy := NewHashMap(h.eq, h.hash)
h.Iter(func(k, v T) bool {
cpy.Put(k, v)
return false
})
return cpy
} | go | func (h *HashMap) Copy() *HashMap {
cpy := NewHashMap(h.eq, h.hash)
h.Iter(func(k, v T) bool {
cpy.Put(k, v)
return false
})
return cpy
} | [
"func",
"(",
"h",
"*",
"HashMap",
")",
"Copy",
"(",
")",
"*",
"HashMap",
"{",
"cpy",
":=",
"NewHashMap",
"(",
"h",
".",
"eq",
",",
"h",
".",
"hash",
")",
"\n",
"h",
".",
"Iter",
"(",
"func",
"(",
"k",
",",
"v",
"T",
")",
"bool",
"{",
"cpy",
".",
"Put",
"(",
"k",
",",
"v",
")",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"return",
"cpy",
"\n",
"}"
] | // Copy returns a shallow copy of this HashMap. | [
"Copy",
"returns",
"a",
"shallow",
"copy",
"of",
"this",
"HashMap",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/hashmap.go#L38-L45 | train |
open-policy-agent/opa | util/hashmap.go | Get | func (h *HashMap) Get(k T) (T, bool) {
hash := h.hash(k)
for entry := h.table[hash]; entry != nil; entry = entry.next {
if h.eq(entry.k, k) {
return entry.v, true
}
}
return nil, false
} | go | func (h *HashMap) Get(k T) (T, bool) {
hash := h.hash(k)
for entry := h.table[hash]; entry != nil; entry = entry.next {
if h.eq(entry.k, k) {
return entry.v, true
}
}
return nil, false
} | [
"func",
"(",
"h",
"*",
"HashMap",
")",
"Get",
"(",
"k",
"T",
")",
"(",
"T",
",",
"bool",
")",
"{",
"hash",
":=",
"h",
".",
"hash",
"(",
"k",
")",
"\n",
"for",
"entry",
":=",
"h",
".",
"table",
"[",
"hash",
"]",
";",
"entry",
"!=",
"nil",
";",
"entry",
"=",
"entry",
".",
"next",
"{",
"if",
"h",
".",
"eq",
"(",
"entry",
".",
"k",
",",
"k",
")",
"{",
"return",
"entry",
".",
"v",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"false",
"\n",
"}"
] | // Get returns the value for k. | [
"Get",
"returns",
"the",
"value",
"for",
"k",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/hashmap.go#L63-L71 | train |
open-policy-agent/opa | util/hashmap.go | Delete | func (h *HashMap) Delete(k T) {
hash := h.hash(k)
var prev *hashEntry
for entry := h.table[hash]; entry != nil; entry = entry.next {
if h.eq(entry.k, k) {
if prev != nil {
prev.next = entry.next
} else {
h.table[hash] = entry.next
}
h.size--
return
}
prev = entry
}
} | go | func (h *HashMap) Delete(k T) {
hash := h.hash(k)
var prev *hashEntry
for entry := h.table[hash]; entry != nil; entry = entry.next {
if h.eq(entry.k, k) {
if prev != nil {
prev.next = entry.next
} else {
h.table[hash] = entry.next
}
h.size--
return
}
prev = entry
}
} | [
"func",
"(",
"h",
"*",
"HashMap",
")",
"Delete",
"(",
"k",
"T",
")",
"{",
"hash",
":=",
"h",
".",
"hash",
"(",
"k",
")",
"\n",
"var",
"prev",
"*",
"hashEntry",
"\n",
"for",
"entry",
":=",
"h",
".",
"table",
"[",
"hash",
"]",
";",
"entry",
"!=",
"nil",
";",
"entry",
"=",
"entry",
".",
"next",
"{",
"if",
"h",
".",
"eq",
"(",
"entry",
".",
"k",
",",
"k",
")",
"{",
"if",
"prev",
"!=",
"nil",
"{",
"prev",
".",
"next",
"=",
"entry",
".",
"next",
"\n",
"}",
"else",
"{",
"h",
".",
"table",
"[",
"hash",
"]",
"=",
"entry",
".",
"next",
"\n",
"}",
"\n",
"h",
".",
"size",
"--",
"\n",
"return",
"\n",
"}",
"\n",
"prev",
"=",
"entry",
"\n",
"}",
"\n",
"}"
] | // Delete removes the the key k. | [
"Delete",
"removes",
"the",
"the",
"key",
"k",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/hashmap.go#L74-L89 | train |
open-policy-agent/opa | util/hashmap.go | Hash | func (h *HashMap) Hash() int {
var hash int
h.Iter(func(k, v T) bool {
hash += h.hash(k) + h.hash(v)
return false
})
return hash
} | go | func (h *HashMap) Hash() int {
var hash int
h.Iter(func(k, v T) bool {
hash += h.hash(k) + h.hash(v)
return false
})
return hash
} | [
"func",
"(",
"h",
"*",
"HashMap",
")",
"Hash",
"(",
")",
"int",
"{",
"var",
"hash",
"int",
"\n",
"h",
".",
"Iter",
"(",
"func",
"(",
"k",
",",
"v",
"T",
")",
"bool",
"{",
"hash",
"+=",
"h",
".",
"hash",
"(",
"k",
")",
"+",
"h",
".",
"hash",
"(",
"v",
")",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"return",
"hash",
"\n",
"}"
] | // Hash returns the hash code for this hash map. | [
"Hash",
"returns",
"the",
"hash",
"code",
"for",
"this",
"hash",
"map",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/hashmap.go#L92-L99 | train |
open-policy-agent/opa | util/hashmap.go | Iter | func (h *HashMap) Iter(iter func(T, T) bool) bool {
for _, entry := range h.table {
for ; entry != nil; entry = entry.next {
if iter(entry.k, entry.v) {
return true
}
}
}
return false
} | go | func (h *HashMap) Iter(iter func(T, T) bool) bool {
for _, entry := range h.table {
for ; entry != nil; entry = entry.next {
if iter(entry.k, entry.v) {
return true
}
}
}
return false
} | [
"func",
"(",
"h",
"*",
"HashMap",
")",
"Iter",
"(",
"iter",
"func",
"(",
"T",
",",
"T",
")",
"bool",
")",
"bool",
"{",
"for",
"_",
",",
"entry",
":=",
"range",
"h",
".",
"table",
"{",
"for",
";",
"entry",
"!=",
"nil",
";",
"entry",
"=",
"entry",
".",
"next",
"{",
"if",
"iter",
"(",
"entry",
".",
"k",
",",
"entry",
".",
"v",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Iter invokes the iter function for each element in the HashMap.
// If the iter function returns true, iteration stops and the return value is true.
// If the iter function never returns true, iteration proceeds through all elements
// and the return value is false. | [
"Iter",
"invokes",
"the",
"iter",
"function",
"for",
"each",
"element",
"in",
"the",
"HashMap",
".",
"If",
"the",
"iter",
"function",
"returns",
"true",
"iteration",
"stops",
"and",
"the",
"return",
"value",
"is",
"true",
".",
"If",
"the",
"iter",
"function",
"never",
"returns",
"true",
"iteration",
"proceeds",
"through",
"all",
"elements",
"and",
"the",
"return",
"value",
"is",
"false",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/hashmap.go#L105-L114 | train |
open-policy-agent/opa | util/hashmap.go | Update | func (h *HashMap) Update(other *HashMap) *HashMap {
updated := h.Copy()
other.Iter(func(k, v T) bool {
updated.Put(k, v)
return false
})
return updated
} | go | func (h *HashMap) Update(other *HashMap) *HashMap {
updated := h.Copy()
other.Iter(func(k, v T) bool {
updated.Put(k, v)
return false
})
return updated
} | [
"func",
"(",
"h",
"*",
"HashMap",
")",
"Update",
"(",
"other",
"*",
"HashMap",
")",
"*",
"HashMap",
"{",
"updated",
":=",
"h",
".",
"Copy",
"(",
")",
"\n",
"other",
".",
"Iter",
"(",
"func",
"(",
"k",
",",
"v",
"T",
")",
"bool",
"{",
"updated",
".",
"Put",
"(",
"k",
",",
"v",
")",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"return",
"updated",
"\n",
"}"
] | // Update returns a new HashMap with elements from the other HashMap put into this HashMap.
// If the other HashMap contains elements with the same key as this HashMap, the value
// from the other HashMap overwrites the value from this HashMap. | [
"Update",
"returns",
"a",
"new",
"HashMap",
"with",
"elements",
"from",
"the",
"other",
"HashMap",
"put",
"into",
"this",
"HashMap",
".",
"If",
"the",
"other",
"HashMap",
"contains",
"elements",
"with",
"the",
"same",
"key",
"as",
"this",
"HashMap",
"the",
"value",
"from",
"the",
"other",
"HashMap",
"overwrites",
"the",
"value",
"from",
"this",
"HashMap",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/hashmap.go#L148-L155 | train |
open-policy-agent/opa | internal/ir/walk.go | Walk | func Walk(vis Visitor, x interface{}) error {
impl := walkerImpl{
vis: vis,
}
impl.walk(x)
return impl.err
} | go | func Walk(vis Visitor, x interface{}) error {
impl := walkerImpl{
vis: vis,
}
impl.walk(x)
return impl.err
} | [
"func",
"Walk",
"(",
"vis",
"Visitor",
",",
"x",
"interface",
"{",
"}",
")",
"error",
"{",
"impl",
":=",
"walkerImpl",
"{",
"vis",
":",
"vis",
",",
"}",
"\n",
"impl",
".",
"walk",
"(",
"x",
")",
"\n",
"return",
"impl",
".",
"err",
"\n",
"}"
] | // Walk invokes the visitor for nodes under x. | [
"Walk",
"invokes",
"the",
"visitor",
"for",
"nodes",
"under",
"x",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/ir/walk.go#L15-L21 | train |
open-policy-agent/opa | profiler/profiler.go | ReportByFile | func (p *Profiler) ReportByFile() (report Report) {
p.processLastExpr()
report.Files = map[string]*FileReport{}
for file, hits := range p.hits {
stats := []ExprStats{}
for _, stat := range hits {
stats = append(stats, stat)
}
sortStatsByRow(stats)
fr, ok := report.Files[file]
if !ok {
fr = &FileReport{}
report.Files[file] = fr
}
fr.Result = stats
}
return report
} | go | func (p *Profiler) ReportByFile() (report Report) {
p.processLastExpr()
report.Files = map[string]*FileReport{}
for file, hits := range p.hits {
stats := []ExprStats{}
for _, stat := range hits {
stats = append(stats, stat)
}
sortStatsByRow(stats)
fr, ok := report.Files[file]
if !ok {
fr = &FileReport{}
report.Files[file] = fr
}
fr.Result = stats
}
return report
} | [
"func",
"(",
"p",
"*",
"Profiler",
")",
"ReportByFile",
"(",
")",
"(",
"report",
"Report",
")",
"{",
"p",
".",
"processLastExpr",
"(",
")",
"\n",
"report",
".",
"Files",
"=",
"map",
"[",
"string",
"]",
"*",
"FileReport",
"{",
"}",
"\n",
"for",
"file",
",",
"hits",
":=",
"range",
"p",
".",
"hits",
"{",
"stats",
":=",
"[",
"]",
"ExprStats",
"{",
"}",
"\n",
"for",
"_",
",",
"stat",
":=",
"range",
"hits",
"{",
"stats",
"=",
"append",
"(",
"stats",
",",
"stat",
")",
"\n",
"}",
"\n\n",
"sortStatsByRow",
"(",
"stats",
")",
"\n",
"fr",
",",
"ok",
":=",
"report",
".",
"Files",
"[",
"file",
"]",
"\n",
"if",
"!",
"ok",
"{",
"fr",
"=",
"&",
"FileReport",
"{",
"}",
"\n",
"report",
".",
"Files",
"[",
"file",
"]",
"=",
"fr",
"\n",
"}",
"\n",
"fr",
".",
"Result",
"=",
"stats",
"\n",
"}",
"\n",
"return",
"report",
"\n",
"}"
] | // ReportByFile returns a profiler report for expressions grouped by the
// file name. For each file the results are sorted by increasing row number. | [
"ReportByFile",
"returns",
"a",
"profiler",
"report",
"for",
"expressions",
"grouped",
"by",
"the",
"file",
"name",
".",
"For",
"each",
"file",
"the",
"results",
"are",
"sorted",
"by",
"increasing",
"row",
"number",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/profiler/profiler.go#L43-L61 | train |
open-policy-agent/opa | profiler/profiler.go | ReportTopNResults | func (p *Profiler) ReportTopNResults(numResults int, criteria []string) []ExprStats {
p.processLastExpr()
stats := []ExprStats{}
for _, hits := range p.hits {
for _, stat := range hits {
stats = append(stats, stat)
}
}
// allowed criteria for sorting results
allowedCriteria := map[string]lessFunc{}
allowedCriteria["total_time_ns"] = func(stat1, stat2 *ExprStats) bool {
return stat1.ExprTimeNs > stat2.ExprTimeNs
}
allowedCriteria["num_eval"] = func(stat1, stat2 *ExprStats) bool {
return stat1.NumEval > stat2.NumEval
}
allowedCriteria["num_redo"] = func(stat1, stat2 *ExprStats) bool {
return stat1.NumRedo > stat2.NumRedo
}
allowedCriteria["file"] = func(stat1, stat2 *ExprStats) bool {
return stat1.Location.File > stat2.Location.File
}
allowedCriteria["line"] = func(stat1, stat2 *ExprStats) bool {
return stat1.Location.Row > stat2.Location.Row
}
sortFuncs := []lessFunc{}
for _, cr := range criteria {
if fn, ok := allowedCriteria[cr]; ok {
sortFuncs = append(sortFuncs, fn)
}
}
// if no criteria return all the stats
if len(sortFuncs) == 0 {
return stats
}
orderedBy(sortFuncs).Sort(stats)
// if desired number of results to be returned is less than or
// equal to 0 or exceed total available results,
// return all the stats
if numResults <= 0 || numResults > len(stats) {
return stats
}
return stats[:numResults]
} | go | func (p *Profiler) ReportTopNResults(numResults int, criteria []string) []ExprStats {
p.processLastExpr()
stats := []ExprStats{}
for _, hits := range p.hits {
for _, stat := range hits {
stats = append(stats, stat)
}
}
// allowed criteria for sorting results
allowedCriteria := map[string]lessFunc{}
allowedCriteria["total_time_ns"] = func(stat1, stat2 *ExprStats) bool {
return stat1.ExprTimeNs > stat2.ExprTimeNs
}
allowedCriteria["num_eval"] = func(stat1, stat2 *ExprStats) bool {
return stat1.NumEval > stat2.NumEval
}
allowedCriteria["num_redo"] = func(stat1, stat2 *ExprStats) bool {
return stat1.NumRedo > stat2.NumRedo
}
allowedCriteria["file"] = func(stat1, stat2 *ExprStats) bool {
return stat1.Location.File > stat2.Location.File
}
allowedCriteria["line"] = func(stat1, stat2 *ExprStats) bool {
return stat1.Location.Row > stat2.Location.Row
}
sortFuncs := []lessFunc{}
for _, cr := range criteria {
if fn, ok := allowedCriteria[cr]; ok {
sortFuncs = append(sortFuncs, fn)
}
}
// if no criteria return all the stats
if len(sortFuncs) == 0 {
return stats
}
orderedBy(sortFuncs).Sort(stats)
// if desired number of results to be returned is less than or
// equal to 0 or exceed total available results,
// return all the stats
if numResults <= 0 || numResults > len(stats) {
return stats
}
return stats[:numResults]
} | [
"func",
"(",
"p",
"*",
"Profiler",
")",
"ReportTopNResults",
"(",
"numResults",
"int",
",",
"criteria",
"[",
"]",
"string",
")",
"[",
"]",
"ExprStats",
"{",
"p",
".",
"processLastExpr",
"(",
")",
"\n",
"stats",
":=",
"[",
"]",
"ExprStats",
"{",
"}",
"\n\n",
"for",
"_",
",",
"hits",
":=",
"range",
"p",
".",
"hits",
"{",
"for",
"_",
",",
"stat",
":=",
"range",
"hits",
"{",
"stats",
"=",
"append",
"(",
"stats",
",",
"stat",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// allowed criteria for sorting results",
"allowedCriteria",
":=",
"map",
"[",
"string",
"]",
"lessFunc",
"{",
"}",
"\n",
"allowedCriteria",
"[",
"\"",
"\"",
"]",
"=",
"func",
"(",
"stat1",
",",
"stat2",
"*",
"ExprStats",
")",
"bool",
"{",
"return",
"stat1",
".",
"ExprTimeNs",
">",
"stat2",
".",
"ExprTimeNs",
"\n",
"}",
"\n",
"allowedCriteria",
"[",
"\"",
"\"",
"]",
"=",
"func",
"(",
"stat1",
",",
"stat2",
"*",
"ExprStats",
")",
"bool",
"{",
"return",
"stat1",
".",
"NumEval",
">",
"stat2",
".",
"NumEval",
"\n",
"}",
"\n",
"allowedCriteria",
"[",
"\"",
"\"",
"]",
"=",
"func",
"(",
"stat1",
",",
"stat2",
"*",
"ExprStats",
")",
"bool",
"{",
"return",
"stat1",
".",
"NumRedo",
">",
"stat2",
".",
"NumRedo",
"\n",
"}",
"\n",
"allowedCriteria",
"[",
"\"",
"\"",
"]",
"=",
"func",
"(",
"stat1",
",",
"stat2",
"*",
"ExprStats",
")",
"bool",
"{",
"return",
"stat1",
".",
"Location",
".",
"File",
">",
"stat2",
".",
"Location",
".",
"File",
"\n",
"}",
"\n",
"allowedCriteria",
"[",
"\"",
"\"",
"]",
"=",
"func",
"(",
"stat1",
",",
"stat2",
"*",
"ExprStats",
")",
"bool",
"{",
"return",
"stat1",
".",
"Location",
".",
"Row",
">",
"stat2",
".",
"Location",
".",
"Row",
"\n",
"}",
"\n\n",
"sortFuncs",
":=",
"[",
"]",
"lessFunc",
"{",
"}",
"\n\n",
"for",
"_",
",",
"cr",
":=",
"range",
"criteria",
"{",
"if",
"fn",
",",
"ok",
":=",
"allowedCriteria",
"[",
"cr",
"]",
";",
"ok",
"{",
"sortFuncs",
"=",
"append",
"(",
"sortFuncs",
",",
"fn",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// if no criteria return all the stats",
"if",
"len",
"(",
"sortFuncs",
")",
"==",
"0",
"{",
"return",
"stats",
"\n",
"}",
"\n\n",
"orderedBy",
"(",
"sortFuncs",
")",
".",
"Sort",
"(",
"stats",
")",
"\n\n",
"// if desired number of results to be returned is less than or",
"// equal to 0 or exceed total available results,",
"// return all the stats",
"if",
"numResults",
"<=",
"0",
"||",
"numResults",
">",
"len",
"(",
"stats",
")",
"{",
"return",
"stats",
"\n",
"}",
"\n",
"return",
"stats",
"[",
":",
"numResults",
"]",
"\n\n",
"}"
] | // ReportTopNResults returns the top N results based on the given
// criteria. If N <= 0, all the results based on the criteria are returned. | [
"ReportTopNResults",
"returns",
"the",
"top",
"N",
"results",
"based",
"on",
"the",
"given",
"criteria",
".",
"If",
"N",
"<",
"=",
"0",
"all",
"the",
"results",
"based",
"on",
"the",
"criteria",
"are",
"returned",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/profiler/profiler.go#L65-L116 | train |
open-policy-agent/opa | profiler/profiler.go | Trace | func (p *Profiler) Trace(event *topdown.Event) {
switch event.Op {
case topdown.EvalOp:
if expr, ok := event.Node.(*ast.Expr); ok && expr != nil {
p.processExpr(expr, event.Op)
}
case topdown.RedoOp:
if expr, ok := event.Node.(*ast.Expr); ok && expr != nil {
p.processExpr(expr, event.Op)
}
}
} | go | func (p *Profiler) Trace(event *topdown.Event) {
switch event.Op {
case topdown.EvalOp:
if expr, ok := event.Node.(*ast.Expr); ok && expr != nil {
p.processExpr(expr, event.Op)
}
case topdown.RedoOp:
if expr, ok := event.Node.(*ast.Expr); ok && expr != nil {
p.processExpr(expr, event.Op)
}
}
} | [
"func",
"(",
"p",
"*",
"Profiler",
")",
"Trace",
"(",
"event",
"*",
"topdown",
".",
"Event",
")",
"{",
"switch",
"event",
".",
"Op",
"{",
"case",
"topdown",
".",
"EvalOp",
":",
"if",
"expr",
",",
"ok",
":=",
"event",
".",
"Node",
".",
"(",
"*",
"ast",
".",
"Expr",
")",
";",
"ok",
"&&",
"expr",
"!=",
"nil",
"{",
"p",
".",
"processExpr",
"(",
"expr",
",",
"event",
".",
"Op",
")",
"\n",
"}",
"\n",
"case",
"topdown",
".",
"RedoOp",
":",
"if",
"expr",
",",
"ok",
":=",
"event",
".",
"Node",
".",
"(",
"*",
"ast",
".",
"Expr",
")",
";",
"ok",
"&&",
"expr",
"!=",
"nil",
"{",
"p",
".",
"processExpr",
"(",
"expr",
",",
"event",
".",
"Op",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Trace updates the profiler state. | [
"Trace",
"updates",
"the",
"profiler",
"state",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/profiler/profiler.go#L119-L130 | train |
open-policy-agent/opa | profiler/profiler.go | Less | func (ms *multiSorter) Less(i, j int) bool {
p, q := &ms.stats[i], &ms.stats[j]
// Try all but the last comparison.
var k int
for k = 0; k < len(ms.less)-1; k++ {
less := ms.less[k]
switch {
case less(p, q):
return true
case less(q, p):
return false
}
// p == q; try the next comparison.
}
return ms.less[k](p, q)
} | go | func (ms *multiSorter) Less(i, j int) bool {
p, q := &ms.stats[i], &ms.stats[j]
// Try all but the last comparison.
var k int
for k = 0; k < len(ms.less)-1; k++ {
less := ms.less[k]
switch {
case less(p, q):
return true
case less(q, p):
return false
}
// p == q; try the next comparison.
}
return ms.less[k](p, q)
} | [
"func",
"(",
"ms",
"*",
"multiSorter",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"p",
",",
"q",
":=",
"&",
"ms",
".",
"stats",
"[",
"i",
"]",
",",
"&",
"ms",
".",
"stats",
"[",
"j",
"]",
"\n",
"// Try all but the last comparison.",
"var",
"k",
"int",
"\n",
"for",
"k",
"=",
"0",
";",
"k",
"<",
"len",
"(",
"ms",
".",
"less",
")",
"-",
"1",
";",
"k",
"++",
"{",
"less",
":=",
"ms",
".",
"less",
"[",
"k",
"]",
"\n",
"switch",
"{",
"case",
"less",
"(",
"p",
",",
"q",
")",
":",
"return",
"true",
"\n",
"case",
"less",
"(",
"q",
",",
"p",
")",
":",
"return",
"false",
"\n",
"}",
"\n",
"// p == q; try the next comparison.",
"}",
"\n",
"return",
"ms",
".",
"less",
"[",
"k",
"]",
"(",
"p",
",",
"q",
")",
"\n",
"}"
] | // Less is part of sort.Interface. It is implemented by looping along the
// less functions until it finds a comparison that discriminates between
// the two items. | [
"Less",
"is",
"part",
"of",
"sort",
".",
"Interface",
".",
"It",
"is",
"implemented",
"by",
"looping",
"along",
"the",
"less",
"functions",
"until",
"it",
"finds",
"a",
"comparison",
"that",
"discriminates",
"between",
"the",
"two",
"items",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/profiler/profiler.go#L259-L274 | train |
open-policy-agent/opa | internal/presentation/presentation.go | JSON | func (o DepAnalysisOutput) JSON(w io.Writer) error {
o.sort()
return JSON(w, o)
} | go | func (o DepAnalysisOutput) JSON(w io.Writer) error {
o.sort()
return JSON(w, o)
} | [
"func",
"(",
"o",
"DepAnalysisOutput",
")",
"JSON",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"o",
".",
"sort",
"(",
")",
"\n",
"return",
"JSON",
"(",
"w",
",",
"o",
")",
"\n",
"}"
] | // JSON outputs o to w as JSON. | [
"JSON",
"outputs",
"o",
"to",
"w",
"as",
"JSON",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/presentation/presentation.go#L39-L42 | train |
open-policy-agent/opa | internal/presentation/presentation.go | Pretty | func (o DepAnalysisOutput) Pretty(w io.Writer) error {
var headers []string
var rows [][]string
// Fill two columns if results have base and virtual docs. Else fill one column.
if len(o.Base) > 0 && len(o.Virtual) > 0 {
maxLen := len(o.Base)
if len(o.Virtual) > maxLen {
maxLen = len(o.Virtual)
}
headers = []string{"Base Documents", "Virtual Documents"}
rows = make([][]string, maxLen)
for i := range rows {
rows[i] = make([]string, 2)
if i < len(o.Base) {
rows[i][0] = o.Base[i].String()
}
if i < len(o.Virtual) {
rows[i][1] = o.Virtual[i].String()
}
}
} else if len(o.Base) > 0 {
headers = []string{"Base Documents"}
rows = make([][]string, len(o.Base))
for i := range rows {
rows[i] = []string{o.Base[i].String()}
}
} else if len(o.Virtual) > 0 {
headers = []string{"Virtual Documents"}
rows = make([][]string, len(o.Base))
for i := range rows {
rows[i] = []string{o.Virtual[i].String()}
}
}
if len(rows) == 0 {
return nil
}
table := tablewriter.NewWriter(w)
table.SetHeader(headers)
table.SetAutoWrapText(false)
for i := range rows {
table.Append(rows[i])
}
table.Render()
return nil
} | go | func (o DepAnalysisOutput) Pretty(w io.Writer) error {
var headers []string
var rows [][]string
// Fill two columns if results have base and virtual docs. Else fill one column.
if len(o.Base) > 0 && len(o.Virtual) > 0 {
maxLen := len(o.Base)
if len(o.Virtual) > maxLen {
maxLen = len(o.Virtual)
}
headers = []string{"Base Documents", "Virtual Documents"}
rows = make([][]string, maxLen)
for i := range rows {
rows[i] = make([]string, 2)
if i < len(o.Base) {
rows[i][0] = o.Base[i].String()
}
if i < len(o.Virtual) {
rows[i][1] = o.Virtual[i].String()
}
}
} else if len(o.Base) > 0 {
headers = []string{"Base Documents"}
rows = make([][]string, len(o.Base))
for i := range rows {
rows[i] = []string{o.Base[i].String()}
}
} else if len(o.Virtual) > 0 {
headers = []string{"Virtual Documents"}
rows = make([][]string, len(o.Base))
for i := range rows {
rows[i] = []string{o.Virtual[i].String()}
}
}
if len(rows) == 0 {
return nil
}
table := tablewriter.NewWriter(w)
table.SetHeader(headers)
table.SetAutoWrapText(false)
for i := range rows {
table.Append(rows[i])
}
table.Render()
return nil
} | [
"func",
"(",
"o",
"DepAnalysisOutput",
")",
"Pretty",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"var",
"headers",
"[",
"]",
"string",
"\n",
"var",
"rows",
"[",
"]",
"[",
"]",
"string",
"\n\n",
"// Fill two columns if results have base and virtual docs. Else fill one column.",
"if",
"len",
"(",
"o",
".",
"Base",
")",
">",
"0",
"&&",
"len",
"(",
"o",
".",
"Virtual",
")",
">",
"0",
"{",
"maxLen",
":=",
"len",
"(",
"o",
".",
"Base",
")",
"\n",
"if",
"len",
"(",
"o",
".",
"Virtual",
")",
">",
"maxLen",
"{",
"maxLen",
"=",
"len",
"(",
"o",
".",
"Virtual",
")",
"\n",
"}",
"\n",
"headers",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"rows",
"=",
"make",
"(",
"[",
"]",
"[",
"]",
"string",
",",
"maxLen",
")",
"\n",
"for",
"i",
":=",
"range",
"rows",
"{",
"rows",
"[",
"i",
"]",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"2",
")",
"\n",
"if",
"i",
"<",
"len",
"(",
"o",
".",
"Base",
")",
"{",
"rows",
"[",
"i",
"]",
"[",
"0",
"]",
"=",
"o",
".",
"Base",
"[",
"i",
"]",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"i",
"<",
"len",
"(",
"o",
".",
"Virtual",
")",
"{",
"rows",
"[",
"i",
"]",
"[",
"1",
"]",
"=",
"o",
".",
"Virtual",
"[",
"i",
"]",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"if",
"len",
"(",
"o",
".",
"Base",
")",
">",
"0",
"{",
"headers",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"rows",
"=",
"make",
"(",
"[",
"]",
"[",
"]",
"string",
",",
"len",
"(",
"o",
".",
"Base",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"rows",
"{",
"rows",
"[",
"i",
"]",
"=",
"[",
"]",
"string",
"{",
"o",
".",
"Base",
"[",
"i",
"]",
".",
"String",
"(",
")",
"}",
"\n",
"}",
"\n",
"}",
"else",
"if",
"len",
"(",
"o",
".",
"Virtual",
")",
">",
"0",
"{",
"headers",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"rows",
"=",
"make",
"(",
"[",
"]",
"[",
"]",
"string",
",",
"len",
"(",
"o",
".",
"Base",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"rows",
"{",
"rows",
"[",
"i",
"]",
"=",
"[",
"]",
"string",
"{",
"o",
".",
"Virtual",
"[",
"i",
"]",
".",
"String",
"(",
")",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"rows",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"table",
":=",
"tablewriter",
".",
"NewWriter",
"(",
"w",
")",
"\n",
"table",
".",
"SetHeader",
"(",
"headers",
")",
"\n",
"table",
".",
"SetAutoWrapText",
"(",
"false",
")",
"\n",
"for",
"i",
":=",
"range",
"rows",
"{",
"table",
".",
"Append",
"(",
"rows",
"[",
"i",
"]",
")",
"\n",
"}",
"\n\n",
"table",
".",
"Render",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Pretty outputs o to w in a human-readable format. | [
"Pretty",
"outputs",
"o",
"to",
"w",
"in",
"a",
"human",
"-",
"readable",
"format",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/presentation/presentation.go#L45-L95 | train |
open-policy-agent/opa | internal/presentation/presentation.go | WithLimit | func (e Output) WithLimit(n int) Output {
e.limit = n
return e
} | go | func (e Output) WithLimit(n int) Output {
e.limit = n
return e
} | [
"func",
"(",
"e",
"Output",
")",
"WithLimit",
"(",
"n",
"int",
")",
"Output",
"{",
"e",
".",
"limit",
"=",
"n",
"\n",
"return",
"e",
"\n",
"}"
] | // WithLimit sets the output limit to set on stringified values. | [
"WithLimit",
"sets",
"the",
"output",
"limit",
"to",
"set",
"on",
"stringified",
"values",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/presentation/presentation.go#L120-L123 | train |
open-policy-agent/opa | internal/presentation/presentation.go | JSON | func JSON(w io.Writer, x interface{}) error {
encoder := json.NewEncoder(w)
encoder.SetIndent("", " ")
return encoder.Encode(x)
} | go | func JSON(w io.Writer, x interface{}) error {
encoder := json.NewEncoder(w)
encoder.SetIndent("", " ")
return encoder.Encode(x)
} | [
"func",
"JSON",
"(",
"w",
"io",
".",
"Writer",
",",
"x",
"interface",
"{",
"}",
")",
"error",
"{",
"encoder",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"encoder",
".",
"SetIndent",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"return",
"encoder",
".",
"Encode",
"(",
"x",
")",
"\n",
"}"
] | // JSON writes x to w with indentation. | [
"JSON",
"writes",
"x",
"to",
"w",
"with",
"indentation",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/presentation/presentation.go#L130-L134 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.