Esempio n. 1
0
// Helper function. Given a client, key, columnFamily, value inserts into the table under column 'a'
func insertKeyValue(c *gohbase.Client, key, columnFamily string, value []byte) error {
	values := map[string]map[string][]byte{columnFamily: map[string][]byte{}}
	values[columnFamily]["a"] = value
	putRequest, err := hrpc.NewPutStr(context.Background(), table, key, values)
	_, err = c.Put(putRequest)
	return err
}
Esempio n. 2
0
func doTest(client gohbase.Client, action string) (err error) {

	switch action {
	case "get":
		var getReq *hrpc.Get
		getReq, err = hrpc.NewGetStr(context.Background(), "t1", "10001")
		if err != nil {
			fmt.Printf("hrpc.NewGetStr failed, err is %v", err)
			return
		}
		_, err = client.Get(getReq)
		if err != nil {
			fmt.Printf("client.Get failed, err is %v", err)
			return
		}
	case "put":
		var putReq *hrpc.Mutate
		rowID, _ := IntRange(0, 3000000)
		putReq, err = hrpc.NewPutStr(context.Background(), "t1", strconv.Itoa(rowID), map[string]map[string][]byte{
			"fam1": map[string][]byte{
				"col1": []byte("testvalue"),
			},
		})
		if err != nil {
			fmt.Printf("hrpc.NewPutStr failed, err is %v", err)
			return
		}
		_, err = client.Put(putReq)
		if err != nil {
			fmt.Printf("client.Put failed, err is %v", err)
			return
		}
	case "delete":
		var delReq *hrpc.Mutate
		rowID, _ := IntRange(0, 3000000)
		delReq, err = hrpc.NewDelStr(context.Background(), "t1", strconv.Itoa(rowID), map[string]map[string][]byte{
			"fam1": map[string][]byte{
				"col1": []byte("testvalue"),
			},
		})
		if err != nil {
			fmt.Printf("hrpc.NewDelStr failed, err is %v", err)
			return
		}
		_, err = client.Delete(delReq)
		if err != nil {
			fmt.Printf("client.Del failed, err is %v", err)
			return
		}
	}
	return
}