MCPcopy Create free account
hub / github.com/actiontech/dtle / NewWhereCtx

Function NewWhereCtx

driver/common/tabletypes.go:204–235  ·  view source on GitHub ↗
(where string, table *Table)

Source from the content-addressed store, hash-verified

202}
203
204func NewWhereCtx(where string, table *Table) (*WhereContext, error) {
205 ast, err := expr.ParseExpression(where)
206 if err != nil {
207 return nil, err
208 } else {
209 fields := expr.FindAllIdentityField(ast)
210 fieldsMap := make(map[string]int)
211 for _, field := range fields {
212 escapedFieldName := strings.ToLower(field) // TODO thorough escape
213 if escapedFieldName == "true" || escapedFieldName == "false" {
214 // qlbridge limitation
215 } else if _, ok := fieldsMap[field]; !ok {
216 if _, ok := table.OriginalTableColumns.Ordinals[field]; !ok {
217 return nil, fmt.Errorf("bad 'where' for table %v.%v: field %v does not exist. known fields: %v",
218 table.TableSchema, table.TableName, field, table.OriginalTableColumns.Ordinals)
219 } else {
220 fieldsMap[field] = table.OriginalTableColumns.Ordinals[field]
221 }
222 } else {
223 // already mapped
224 }
225 }
226
227 // We parse it even it is just 'true', but use the 'IsDefault' flag to optimize.
228 return &WhereContext{
229 Where: where,
230 Ast: ast,
231 FieldsMap: fieldsMap,
232 IsDefault: strings.ToLower(where) == "true",
233 }, nil
234 }
235}

Callers 2

ValidateOriginalTableMethod · 0.92
NewTableContextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected