func (s *testSuite) TestShove() { s.LdbFlagName = "-source-ldb" sn := "storeName" source1 := dataset.NewDataset(datas.NewDataStore(chunks.NewLevelDBStore(s.LdbDir, sn, 1, false)), "foo") source1, err := source1.Commit(types.Int32(42)) s.NoError(err) source2, err := source1.Commit(types.Int32(43)) s.NoError(err) source1HeadRef := source1.Head().Ref() source2.Store().Close() // Close DataStore backing both Datasets ldb2dir := path.Join(s.TempDir, "ldb2") out := s.Run(main, []string{"-source-store", sn, "-source", source1HeadRef.String(), "-sink-ldb", ldb2dir, "-sink-store", sn, "-sink-ds", "bar"}) s.Equal("", out) dest := dataset.NewDataset(datas.NewDataStore(chunks.NewLevelDBStore(ldb2dir, sn, 1, false)), "bar") s.True(types.Int32(42).Equals(dest.Head().Value())) dest.Store().Close() out = s.Run(main, []string{"-source-store", sn, "-source", "foo", "-sink-ldb", ldb2dir, "-sink-ds", "bar"}) s.Equal("", out) dest = dataset.NewDataset(datas.NewDataStore(chunks.NewLevelDBStore(ldb2dir, sn, 1, false)), "bar") s.True(types.Int32(43).Equals(dest.Head().Value())) dest.Store().Close() }
func (suite *WalkAllTestSuite) TestWalkComposites() { suite.walkWorker(suite.storeAndRef(types.NewList()), 2) suite.walkWorker(suite.storeAndRef(types.NewList(types.Bool(false), types.Int32(8))), 4) suite.walkWorker(suite.storeAndRef(types.NewSet()), 2) suite.walkWorker(suite.storeAndRef(types.NewSet(types.Bool(false), types.Int32(8))), 4) suite.walkWorker(suite.storeAndRef(types.NewMap()), 2) suite.walkWorker(suite.storeAndRef(types.NewMap(types.Int32(8), types.Bool(true), types.Int32(0), types.Bool(false))), 6) }
func readerForQuarter(v types.Value) []types.Value { values := []types.Value{} s := v.(Quarter) values = append(values, types.Int32(s._Year)) values = append(values, s._Quarter) return values }
func TestValueMapDef(t *testing.T) { assert := assert.New(t) def := gen.MapOfStringToValueDef{"s": types.NewString("s"), "i": types.Int32(42)} m := def.New() assert.Equal(uint64(2), m.Len()) assert.True(types.NewString("s").Equals(m.Get("s"))) assert.True(types.Int32(42).Equals(m.Get("i"))) def2 := m.Def() assert.Equal(def, def2) m2 := gen.NewMapOfStringToValue().Set("s", types.NewString("s")).Set("i", types.Int32(42)) assert.True(m.Equals(m2)) }
func TestValueMapValue(t *testing.T) { assert := assert.New(t) def := gen.MapOfStringToValueDef{"s": types.NewString("s"), "i": types.Int32(42)} var m types.Value m = def.New() m2 := m.(gen.MapOfStringToValue) assert.True(m.Equals(m2)) }
func pullFirstCommit(t *testing.T, topdown bool) { assert := assert.New(t) sink := createTestDataset("sink") source := createTestDataset("source") sourceInitialValue := types.NewMap( types.NewString("first"), NewList(source), types.NewString("second"), NewList(source, types.Int32(2))) NewList(sink) NewList(sink, types.Int32(2)) source, err := source.Commit(sourceInitialValue) assert.NoError(err) sink, err = sink.pull(source.Store(), source.Head().Ref(), 1, topdown) assert.NoError(err) assert.True(source.Head().Equals(sink.Head())) }
func (suite *WalkAllTestSuite) TestWalkNestedComposites() { cs := chunks.NewMemoryStore() suite.walkWorker(suite.storeAndRef(types.NewList(suite.NewSet(cs), types.Int32(8))), 5) suite.walkWorker(suite.storeAndRef(types.NewSet(suite.NewList(cs), suite.NewSet(cs))), 6) // {"string": "string", // "list": [false true], // "map": {"nested": "string"} // "mtlist": [] // "set": [5 7 8] // []: "wow" // } nested := types.NewMap( types.NewString("string"), types.NewString("string"), types.NewString("list"), suite.NewList(cs, types.Bool(false), types.Bool(true)), types.NewString("map"), suite.NewMap(cs, types.NewString("nested"), types.NewString("string")), types.NewString("mtlist"), suite.NewList(cs), types.NewString("set"), suite.NewSet(cs, types.Int32(5), types.Int32(7), types.Int32(8)), suite.NewList(cs), types.NewString("wow"), // note that the dupe list chunk is skipped ) suite.walkWorker(suite.storeAndRef(nested), 25) }
// StringToType takes a piece of data as a string and attempts to convert it to a types.Value of the appropriate types.NomsKind. func StringToType(s string, k types.NomsKind) types.Value { switch k { case types.Uint8Kind: ival, err := strconv.ParseUint(s, 10, 8) d.Chk.NoError(err) return types.Uint8(ival) case types.Uint16Kind: ival, err := strconv.ParseUint(s, 10, 16) d.Chk.NoError(err) return types.Uint16(ival) case types.Uint32Kind: ival, err := strconv.ParseUint(s, 10, 32) d.Chk.NoError(err) return types.Uint32(ival) case types.Uint64Kind: ival, err := strconv.ParseUint(s, 10, 64) d.Chk.NoError(err) return types.Uint64(ival) case types.Int8Kind: ival, err := strconv.ParseInt(s, 10, 8) d.Chk.NoError(err) return types.Int8(ival) case types.Int16Kind: ival, err := strconv.ParseInt(s, 10, 16) d.Chk.NoError(err) return types.Int16(ival) case types.Int32Kind: ival, err := strconv.ParseInt(s, 10, 32) d.Chk.NoError(err) return types.Int32(ival) case types.Int64Kind: ival, err := strconv.ParseInt(s, 10, 64) d.Chk.NoError(err) return types.Int64(ival) case types.Float32Kind: fval, err := strconv.ParseFloat(s, 32) d.Chk.NoError(err) return types.Float32(fval) case types.Float64Kind: fval, err := strconv.ParseFloat(s, 64) d.Chk.NoError(err) return types.Float64(fval) case types.BoolKind: bval, err := strconv.ParseBool(s) d.Chk.NoError(err) return types.Bool(bval) case types.StringKind: return types.NewString(s) default: d.Exp.Fail("Invalid column type kind:", k) } panic("not reached") }
func pullTest(t *testing.T, topdown bool) { assert := assert.New(t) sink := createTestDataset("sink") source := createTestDataset("source") // Give sink and source some initial shared context. sourceInitialValue := types.NewMap( types.NewString("first"), NewList(source), types.NewString("second"), NewList(source, types.Int32(2))) sinkInitialValue := types.NewMap( types.NewString("first"), NewList(sink), types.NewString("second"), NewList(sink, types.Int32(2))) var err error source, err = source.Commit(sourceInitialValue) assert.NoError(err) sink, err = sink.Commit(sinkInitialValue) assert.NoError(err) // Add some new stuff to source. updatedValue := sourceInitialValue.Set( types.NewString("third"), NewList(source, types.Int32(3))) source, err = source.Commit(updatedValue) assert.NoError(err) // Add some more stuff, so that source isn't directly ahead of sink. updatedValue = updatedValue.Set( types.NewString("fourth"), NewList(source, types.Int32(4))) source, err = source.Commit(updatedValue) assert.NoError(err) sink, err = sink.pull(source.Store(), source.Head().Ref(), 1, topdown) assert.NoError(err) assert.True(source.Head().Equals(sink.Head())) }
func (s StructPrimitives) ChildValues() (ret []types.Value) { ret = append(ret, types.Uint64(s._uint64)) ret = append(ret, types.Uint32(s._uint32)) ret = append(ret, types.Uint16(s._uint16)) ret = append(ret, types.Uint8(s._uint8)) ret = append(ret, types.Int64(s._int64)) ret = append(ret, types.Int32(s._int32)) ret = append(ret, types.Int16(s._int16)) ret = append(ret, types.Int8(s._int8)) ret = append(ret, types.Float64(s._float64)) ret = append(ret, types.Float32(s._float32)) ret = append(ret, types.Bool(s._bool)) ret = append(ret, types.NewString(s._string)) ret = append(ret, s._blob) ret = append(ret, s._value) return }
func readerForStructPrimitives(v types.Value) []types.Value { values := []types.Value{} s := v.(StructPrimitives) values = append(values, types.Uint64(s._uint64)) values = append(values, types.Uint32(s._uint32)) values = append(values, types.Uint16(s._uint16)) values = append(values, types.Uint8(s._uint8)) values = append(values, types.Int64(s._int64)) values = append(values, types.Int32(s._int32)) values = append(values, types.Int16(s._int16)) values = append(values, types.Int8(s._int8)) values = append(values, types.Float64(s._float64)) values = append(values, types.Float32(s._float32)) values = append(values, types.Bool(s._bool)) values = append(values, types.NewString(s._string)) values = append(values, s._blob) values = append(values, s._value) return values }
func (def KeyDef) SetYear(val int32) KeyDef { def.__unionIndex = 4 def.__unionValue = types.Int32(val) return def }
func (s Key) SetYear(val int32) Key { s.__unionIndex = 4 s.__unionValue = types.Int32(val) s.ref = &ref.Ref{} return s }
func (s Quarter) ChildValues() (ret []types.Value) { ret = append(ret, types.Int32(s._Year)) ret = append(ret, s._Quarter) return }