Esempio n. 1
1
func formData(t *testing.T, str string) string {
	p, err := loadPolygon(str)
	require.NoError(t, err)

	d, err := wkb.Marshal(p, binary.LittleEndian)
	require.NoError(t, err)
	var g types.Geo
	require.NoError(t, g.UnmarshalBinary(d))
	gb, err := g.MarshalText()
	require.NoError(t, err)
	return string(gb)
}
Esempio n. 2
1
func TestKeyGeneratorPolygon(t *testing.T) {
	p, err := loadPolygon("zip.json")
	require.NoError(t, err)
	data, err := wkb.Marshal(p, binary.LittleEndian)
	require.NoError(t, err)

	var g types.Geo
	err = g.UnmarshalBinary(data)
	require.NoError(t, err)
	keys, err := IndexTokens(&g)
	require.NoError(t, err)
	require.Len(t, keys, 65)
}
Esempio n. 3
0
// FilterUids filters the uids based on the corresponding values and QueryData.
func FilterUids(uids *task.List, values []*task.Value, q *QueryData) *task.List {
	x.AssertTruef(len(values) == len(uids.Uids), "lengths not matching")
	rv := &task.List{}
	for i := 0; i < len(values); i++ {
		valBytes := values[i].Val
		if bytes.Equal(valBytes, nil) {
			continue
		}
		vType := values[i].ValType
		if types.TypeID(vType) != types.GeoID {
			continue
		}
		var g types.Geo
		if err := g.UnmarshalBinary(valBytes); err != nil {
			continue
		}

		if !q.MatchesFilter(g) {
			continue
		}

		// we matched the geo filter, add the uid to the list
		rv.Uids = append(rv.Uids, uids.Uids[i])
	}
	return rv
}
Esempio n. 4
0
func formDataPolygon(t *testing.T, p *geom.Polygon) string {
	d, err := wkb.Marshal(p, binary.LittleEndian)
	require.NoError(t, err)
	var g types.Geo
	require.NoError(t, g.UnmarshalBinary(d))
	gb, err := g.MarshalText()
	require.NoError(t, err)
	return string(gb)
}
Esempio n. 5
0
func BenchmarkKeyGeneratorPoint(b *testing.B) {
	p := geom.NewPoint(geom.XY).MustSetCoords(geom.Coord{-122.082506, 37.4249518})
	data, err := wkb.Marshal(p, binary.LittleEndian)
	if err != nil {
		b.Error(err)
	}
	var g types.Geo
	g.UnmarshalBinary(data)
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		IndexTokens(&g)
	}
}
Esempio n. 6
0
func TestKeyGeneratorPoint(t *testing.T) {
	p := geom.NewPoint(geom.XY).MustSetCoords(geom.Coord{-122.082506, 37.4249518})
	data, err := wkb.Marshal(p, binary.LittleEndian)
	require.NoError(t, err)

	var g types.Geo
	err = g.UnmarshalBinary(data)
	require.NoError(t, err)

	keys, err := IndexTokens(&g)
	require.NoError(t, err)
	require.Len(t, keys, MaxCellLevel-MinCellLevel+1+1) // +1 for the cover
}
Esempio n. 7
0
func BenchmarkKeyGeneratorPolygon(b *testing.B) {
	p, err := loadPolygon("zip.json")
	if err != nil {
		b.Error(err)
	}
	data, err := wkb.Marshal(p, binary.LittleEndian)
	if err != nil {
		b.Error(err)
	}
	var g types.Geo
	g.UnmarshalBinary(data)
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		IndexTokens(&g)
	}
}
Esempio n. 8
0
func typeValueFromNQuad(nq *graph.NQuad) (types.Value, error) {
	if nq.Value == nil || nq.Value.Val == nil {
		return nil, nil
	}
	switch v := nq.Value.Val.(type) {
	case *graph.Value_BytesVal:
		b := types.Bytes(v.BytesVal)
		return &b, nil
	case *graph.Value_IntVal:
		i := types.Int32(v.IntVal)
		return &i, nil
	case *graph.Value_StrVal:
		s := types.String(v.StrVal)
		return &s, nil
	case *graph.Value_BoolVal:
		b := types.Bool(v.BoolVal)
		return &b, nil
	case *graph.Value_DoubleVal:
		f := types.Float(v.DoubleVal)
		return &f, nil
	case *graph.Value_GeoVal:
		var geom types.Geo
		err := geom.UnmarshalBinary(v.GeoVal)
		if err != nil {
			return nil, err
		}
		return &geom, nil

	case nil:
		log.Fatalf("Val being nil is already handled")
		return nil, nil
	default:
		// Unknown type
		return nil, x.Errorf("Unknown value type %T", v)
	}
}
Esempio n. 9
0
func TestSchema(t *testing.T) {
	dir, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir)
	defer os.RemoveAll(dir2)

	query := `
		{
			debug(_uid_:0x1) {
				_xid_
				name
				gender
				alive
				loc
				friend {
					name
				}
				friend {
				}
			}
		}
  `

	gq, _, err := gql.Parse(query)
	require.NoError(t, err)

	ctx := context.Background()
	sg, err := ToSubGraph(ctx, gq)
	require.NoError(t, err)

	ch := make(chan error)
	go ProcessGraph(ctx, sg, nil, ch)
	err = <-ch
	require.NoError(t, err)

	var l Latency
	gr, err := sg.ToProtocolBuffer(&l)
	require.NoError(t, err)

	require.EqualValues(t, "debug", gr.Children[0].Attribute)
	require.EqualValues(t, 1, gr.Children[0].Uid)
	require.EqualValues(t, "mich", gr.Children[0].Xid)
	require.Len(t, gr.Children[0].Properties, 4)

	require.EqualValues(t, "Michonne",
		getProperty(gr.Children[0].Properties, "name").GetStrVal())
	var g types.Geo
	x.Check(g.UnmarshalBinary(getProperty(gr.Children[0].Properties, "loc").GetGeoVal()))
	received, err := g.MarshalText()
	require.EqualValues(t, "{'type':'Point','coordinates':[1.1,2]}", string(received))

	require.Len(t, gr.Children[0].Children, 5)

	child := gr.Children[0].Children[0]
	require.EqualValues(t, 23, child.Uid)
	require.EqualValues(t, "friend", child.Attribute)

	require.Len(t, child.Properties, 1)
	require.EqualValues(t, "Rick Grimes",
		getProperty(child.Properties, "name").GetStrVal())
	require.Empty(t, child.Children)

	child = gr.Children[0].Children[1]
	require.EqualValues(t, 24, child.Uid)
	require.EqualValues(t, "friend", child.Attribute)

	require.Len(t, child.Properties, 1)
	require.EqualValues(t, "Glenn Rhee",
		getProperty(child.Properties, "name").GetStrVal())
	require.Empty(t, child.Children)

	child = gr.Children[0].Children[4]
	require.EqualValues(t, 101, child.Uid)
	require.EqualValues(t, "friend", child.Attribute)

	require.Len(t, child.Properties, 0)
}