func (l ListOfUint8) fromElemSlice(p []uint8) []types.Value {
	r := make([]types.Value, len(p))
	for i, v := range p {
		r[i] = types.Uint8(v)
	}
	return r
}
func (def ListOfUint8Def) New() ListOfUint8 {
	l := make([]types.Value, len(def))
	for i, d := range def {
		l[i] = types.Uint8(d)
	}
	return ListOfUint8{types.NewTypedList(__typeForListOfUint8, l...), &ref.Ref{}}
}
Example #3
0
func (s *testSuite) TestCSVImporterWithPipe() {
	oldDelimiter := delimiter
	newDelimiter := "|"
	delimiter = &newDelimiter
	defer func() { delimiter = oldDelimiter }()

	input, err := ioutil.TempFile(s.TempDir, "")
	d.Chk.NoError(err)
	defer input.Close()
	defer os.Remove(input.Name())

	_, err = input.WriteString("a|b\n1|2\n")
	d.Chk.NoError(err)

	storeName := "store"
	setName := "csv"
	out := s.Run(main, []string{"-store", storeName, "-column-types", "String,Uint8", "-ds", setName, input.Name()})
	s.Equal("", out)

	cs := chunks.NewLevelDBStore(s.LdbDir, storeName, 1, false)
	ds := dataset.NewDataset(datas.NewDataStore(cs), setName)
	defer ds.Store().Close()
	defer os.RemoveAll(s.LdbDir)

	l := ds.Head().Value().(types.List)
	s.Equal(uint64(1), l.Len())
	v := l.Get(0)
	st := v.(types.Struct)
	s.Equal(types.NewString("1"), st.Get("a"))
	s.Equal(types.Uint8(2), st.Get("b"))
}
func (def SetOfUint8Def) New() SetOfUint8 {
	l := make([]types.Value, len(def))
	i := 0
	for d, _ := range def {
		l[i] = types.Uint8(d)
		i++
	}
	return SetOfUint8{types.NewTypedSet(__typeForSetOfUint8, l...), &ref.Ref{}}
}
Example #5
0
// 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")
}
Example #6
0
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
}
Example #7
0
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
}
Example #8
0
func (s *testSuite) TestCSVImporter() {
	input, err := ioutil.TempFile(s.TempDir, "")
	d.Chk.NoError(err)
	defer input.Close()
	defer os.Remove(input.Name())

	_, err = input.WriteString("a,b\n")
	d.Chk.NoError(err)
	for i := 0; i < 100; i++ {
		_, err = input.WriteString(fmt.Sprintf("a%d,%d\n", i, i))
		d.Chk.NoError(err)
	}
	_, err = input.Seek(0, 0)
	d.Chk.NoError(err)

	storeName := "store"
	setName := "csv"
	out := s.Run(main, []string{"-store", storeName, "-column-types", "String,Uint8", "-ds", setName, input.Name()})
	s.Equal("", out)

	cs := chunks.NewLevelDBStore(s.LdbDir, storeName, 1, false)
	ds := dataset.NewDataset(datas.NewDataStore(cs), setName)
	defer ds.Store().Close()
	defer os.RemoveAll(s.LdbDir)

	l := ds.Head().Value().(types.List)
	s.Equal(uint64(100), l.Len())

	i := uint64(0)
	l.IterAll(func(v types.Value, j uint64) {
		s.Equal(i, j)
		st := v.(types.Struct)
		s.Equal(types.NewString(fmt.Sprintf("a%d", i)), st.Get("a"))
		s.Equal(types.Uint8(i), st.Get("b"))
		i++
	})
}
func (l ListOfUint8) Set(i uint64, val uint8) ListOfUint8 {
	return ListOfUint8{l.l.Set(i, types.Uint8(val)), &ref.Ref{}}
}
func (s SetOfUint8) Has(p uint8) bool {
	return s.s.Has(types.Uint8(p))
}