From b5adc465ac9fbba99d239813c32f866221b10c20 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Wed, 25 Nov 2020 18:34:00 -0500 Subject: [PATCH] array/map project iterate --- go/src/miller/types/mlrmap_accessors.go | 17 ++---------- go/todo.txt | 37 ++++++++++++------------- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/go/src/miller/types/mlrmap_accessors.go b/go/src/miller/types/mlrmap_accessors.go index cf119b1cd..aa827ecd3 100644 --- a/go/src/miller/types/mlrmap_accessors.go +++ b/go/src/miller/types/mlrmap_accessors.go @@ -3,7 +3,6 @@ package types import ( "bytes" "errors" - "strconv" "miller/lib" ) @@ -69,20 +68,8 @@ func (this *Mlrmap) PutCopyWithMlrvalIndex(key *Mlrval, value *Mlrval) error { this.PutCopy(&key.printrep, value) return nil } else if key.mvtype == MT_INT { - - if key.intval == 0 { - return errors.New("Miller: zero indices are not supported. Indices are 1-up.") - } - mapEntry := this.findEntryByPositionalIndex(key.intval) - if mapEntry == nil { - // There is no auto-deepen for positional indices - return errors.New( - "Positional index " + - strconv.Itoa(int(key.intval)) + - " not found.", - ) - } - mapEntry.Value = value.Copy() + s := key.String() + this.PutCopy(&s, value) return nil } else { return errors.New( diff --git a/go/todo.txt b/go/todo.txt index 8ca5aab16..5e1465a9b 100644 --- a/go/todo.txt +++ b/go/todo.txt @@ -23,16 +23,22 @@ big: k positional indexing for maps -- use [[]] [[[]]] k '{1:2}' treat as '{"1":2}' - o new logic on read: - - tbd - o new logic on write: - - if exists: tbd - - auto-lengthen: tbd - - auto-deepen: tbd + o cases to update: + - case-go-dsl-array-index-alias.sh + + o read paths: + - BuildArrayOrMapIndexAccessNode::Evaluate + > Mlrval:: ArrayGet + ! looks OK ... + > Mlrval:: MapGet + * Mlrval::GetWithMlrvalIndex + - explicit [[...]] / [[[.]]] paths: + > Mlrmap::GetNameAtPositionalIndex + > Mlrmap::GetWithPositionalIndex o write paths: - maps: - > Mlrmap::PutCopyWithMlrvalIndex + k Mlrmap::PutCopyWithMlrvalIndex * here is string/int logic > Mlrmap::PutIndexed * putIndexedOnMap @@ -46,19 +52,6 @@ big: - arrays: > ArrayPut ! Needs abend on invalids - o read paths: - - BuildArrayOrMapIndexAccessNode::Evaluate - > Mlrval:: ArrayGet - ! looks OK ... - > Mlrval:: MapGet - - explicit [[...]] / [[[.]]] paths: - > Mlrmap::GetNameAtPositionalIndex - > Mlrmap::GetWithPositionalIndex - - o old logic on read: 'm[1]' treat as 'm["1"]' if already exists as map - -> Mlrmap::GetWithMlrvalIndex - o old logic on write: 'm[1]' treat as 'm["1"]' on read if already exists as map - o auto-deepen logic -- foo[NR] -- should create a map not an array - idea is arrays are created with explicit array literals, then extended as such @@ -76,8 +69,12 @@ big: - ./types/mlrval_collections.go - ./types/mlrval_new.go - ./types/mlrval_new.go + o remove the [positional] semantics and all unneeded supporting code, except as used by [[position]] and [[[position]]]. + + o check deadness of Mlrmap::findEntryByPositionalIndex + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -