|
| 1 | +// Copyright 2019-2020 Grabtaxi Holdings PTE LTE (GRAB), All rights reserved. |
| 2 | +// Use of this source code is governed by an MIT-style license that can be found in the LICENSE file |
| 3 | + |
| 4 | +package block |
| 5 | + |
| 6 | +import ( |
| 7 | + "github.com/kelindar/talaria/internal/column/computed" |
| 8 | + "github.com/kelindar/talaria/internal/encoding/typeof" |
| 9 | +) |
| 10 | + |
| 11 | +// Strip runs the computed Values and overwrites/appends them to the set. |
| 12 | +func Strip(filter *typeof.Schema, computed ...computed.Computed) applyFunc { |
| 13 | + return func(r Row) (Row, error) { |
| 14 | + for _, c := range computed { |
| 15 | + v, err := c.Value(r.Values) |
| 16 | + if err != nil || v == nil { |
| 17 | + continue |
| 18 | + } |
| 19 | + if v.(bool) == true { |
| 20 | + if r.Values["bch"] == "c4ae246b19eb45baab5eed083168e2a3" { |
| 21 | + out := NewRow(nil, 0) |
| 22 | + return out, nil |
| 23 | + } |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + return r, nil |
| 28 | + // // Create a new output row and copy the column values from the input |
| 29 | + // schema := make(typeof.Schema, len(r.Schema)) |
| 30 | + // out := NewRow(schema, len(r.Values)+len(computed)) |
| 31 | + // for k, v := range r.Values { |
| 32 | + // if filter == nil || filter.HasConvertible(k, r.Schema[k]) { |
| 33 | + // out.Values[k] = v |
| 34 | + // out.Schema[k] = r.Schema[k] |
| 35 | + // } |
| 36 | + // } |
| 37 | + |
| 38 | + // // Compute the Values |
| 39 | + // for _, c := range computed { |
| 40 | + // if filter != nil && !filter.Contains(c.Name(), c.Type()) { |
| 41 | + // continue // Skip computed Values which aren't part of the filter |
| 42 | + // } |
| 43 | + |
| 44 | + // // Compute the column |
| 45 | + // // v, err := c.Value(r.Values) |
| 46 | + // // if err != nil || v == nil { |
| 47 | + // // continue |
| 48 | + // // } |
| 49 | + |
| 50 | + // // If the column with the same name is already present in the input row, |
| 51 | + // // we need to overwrite this column and set a new type. |
| 52 | + // // out.Schema[c.Name()] = c.Type() |
| 53 | + // delete(out.Schema, "") |
| 54 | + // delete(out.Values, "") |
| 55 | + // } |
| 56 | + // return out, nil |
| 57 | + } |
| 58 | +} |
0 commit comments