forked from tsuna/gohbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
64 lines (56 loc) · 1.56 KB
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (C) 2015 The GoHBase Authors. All rights reserved.
// This file is part of GoHBase.
// Use of this source code is governed by the Apache License 2.0
// that can be found in the COPYING file.
package hrpc
import (
"github.com/golang/protobuf/proto"
"github.com/tsuna/gohbase/pb"
"golang.org/x/net/context"
)
// CreateTable represents a CreateTable HBase call
type CreateTable struct {
tableOp
columns []string
}
// NewCreateTable creates a new CreateTable request that will create the given
// table in HBase. For use by the admin client.
func NewCreateTable(ctx context.Context, table []byte, columns []string) *CreateTable {
ct := &CreateTable{
tableOp: tableOp{base{
table: table,
ctx: ctx,
}},
columns: columns,
}
return ct
}
// GetName returns the name of this RPC call.
func (ct *CreateTable) GetName() string {
return "CreateTable"
}
// Serialize will convert this HBase call into a slice of bytes to be written to
// the network
func (ct *CreateTable) Serialize() ([]byte, error) {
pbcols := make([]*pb.ColumnFamilySchema, len(ct.columns))
for i, col := range ct.columns {
pbcols[i] = &pb.ColumnFamilySchema{
Name: []byte(col),
}
}
ctable := &pb.CreateTableRequest{
TableSchema: &pb.TableSchema{
TableName: &pb.TableName{
Namespace: []byte("default"),
Qualifier: ct.table,
},
ColumnFamilies: pbcols,
},
}
return proto.Marshal(ctable)
}
// NewResponse creates an empty protobuf message to read the response of this
// RPC.
func (ct *CreateTable) NewResponse() proto.Message {
return &pb.CreateTableResponse{}
}