Example #1
0
func toHbaseTScan(scan *TScan) *Hbase.TScan {
	if scan == nil {
		return nil
	}

	if scan.FilterString == "" {
		return &Hbase.TScan{
			StartRow:     Hbase.Text(scan.StartRow),
			StopRow:      Hbase.Text(scan.StopRow),
			Timestamp:    scan.Timestamp,
			Columns:      toHbaseTextList(scan.Columns),
			Caching:      scan.Caching,
			FilterString: nil,
		}
	}

	return &Hbase.TScan{
		StartRow:     Hbase.Text(scan.StartRow),
		StopRow:      Hbase.Text(scan.StopRow),
		Timestamp:    scan.Timestamp,
		Columns:      toHbaseTextList(scan.Columns),
		Caching:      scan.Caching,
		FilterString: Hbase.Text(scan.FilterString),
	}

}
Example #2
0
func NewTIncrement(table string, row []byte, column string, ammount int64) *Hbase.TIncrement {
	return &Hbase.TIncrement{
		Table:   Hbase.Text(table),
		Row:     Hbase.Text(row),
		Column:  Hbase.Text(column),
		Ammount: ammount,
	}
}
Example #3
0
/**
 * Get the row just before the specified one.
 *
 * @return value for specified row/column
 *
 * Parameters:
 *  - TableName: name of table
 *  - Row: row key
 *  - Family: column name
 */
func (client *HClient) GetRowOrBefore(tableName string, row string, family string) (data []*Hbase.TCell, err error) {
	ret, io, e1 := client.hbase.GetRowOrBefore(Hbase.Text(tableName), Hbase.Text(row), Hbase.Text(family))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	data = ret
	return
}
Example #4
0
/**
 * Get a scanner on the current table starting and stopping at the
 * specified rows.  ending at the last row in the table.  Return the
 * specified columns.  Only values with the specified timestamp are
 * returned.
 *
 * @return scanner id to be used with other scanner procedures
 *
 * Parameters:
 *  - TableName: name of table
 *  - StartRow: Starting row in table to scan.
 * Send "" (empty string) to start at the first row.
 *  - StopRow: row to stop scanning on. This row is *not* included in the
 * scanner's results
 *  - Columns: columns to scan. If column name is a column family, all
 * columns of the specified column family are returned. It's also possible
 * to pass a regex in the column qualifier.
 *  - Timestamp: timestamp
 *  - Attributes: Scan attributes
 */
func (client *HClient) ScannerOpenWithStopTs(tableName string, startRow []byte, stopRow []byte, columns []string, timestamp int64, attributes map[string]string) (id int32, err error) {
	ret, io, e1 := client.hbase.ScannerOpenWithStopTs(Hbase.Text(tableName), Hbase.Text(startRow), Hbase.Text(stopRow), toHbaseTextList(columns), timestamp, toHbaseTextMap(attributes))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	id = int32(ret)
	return
}
Example #5
0
/**
 * Get the specified number of versions for the specified table,
 * row, and column.  Only versions less than or equal to the specified
 * timestamp will be returned.
 *
 * @return list of cells for specified row/column
 *
 * Parameters:
 *  - TableName: name of table
 *  - Row: row key
 *  - Column: column name
 *  - Timestamp: timestamp
 *  - NumVersions: number of versions to retrieve
 *  - Attributes: Get attributes
 */
func (client *HClient) GetVerTs(tableName string, row []byte, column string, timestamp int64, numVersions int32, attributes map[string]string) (data []*Hbase.TCell, err error) {
	ret, io, e1 := client.hbase.GetVerTs(Hbase.Text(tableName), Hbase.Text(row), Hbase.Text(column), timestamp, numVersions, toHbaseTextMap(attributes))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	data = ret
	return
}
Example #6
0
/**
 * Atomically increment the column value specified.  Returns the next value post increment.
 *
 * Parameters:
 *  - TableName: name of table
 *  - Row: row to increment
 *  - Column: name of column
 *  - Value: amount to increment by
 */
func (client *HClient) AtomicIncrement(tableName string, row []byte, column string, value int64) (v int64, err error) {
	ret, io, ia, e1 := client.hbase.AtomicIncrement(Hbase.Text(tableName), Hbase.Text(row), Hbase.Text(column), value)
	if err = checkHbaseArgError(io, ia, e1); err != nil {
		return
	}

	v = ret
	return
}
Example #7
0
/**
 * Get the specified columns for the specified table and row at the specified
 * timestamp. Returns an empty list if the row does not exist.
 *
 * @return TRowResult containing the row and map of columns to TCells
 *
 * Parameters:
 *  - TableName: name of table
 *  - Row: row key
 *  - Columns: List of columns to return, null for all columns
 *  - Timestamp
 *  - Attributes: Get attributes
 */
func (client *HClient) GetRowWithColumnsTs(tableName string, row []byte, columns []string, timestamp int64, attributes map[string]string) (data []*Hbase.TRowResult, err error) {
	ret, io, e1 := client.hbase.GetRowWithColumnsTs(Hbase.Text(tableName), Hbase.Text(row), toHbaseTextList(columns), timestamp, toHbaseTextMap(attributes))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	data = ret
	return
}
Example #8
0
func NewMutation(column string, value []byte) *Hbase.Mutation {
	return &Hbase.Mutation{
		IsDelete:   false,
		WriteToWAL: true,
		Column:     Hbase.Text(column),
		Value:      Hbase.Text(value),
	}

}
Example #9
0
/**
 * Open a scanner for a given prefix.  That is all rows will have the specified
 * prefix. No other rows will be returned.
 *
 * @return scanner id to use with other scanner calls
 *
 * Parameters:
 *  - TableName: name of table
 *  - StartAndPrefix: the prefix (and thus start row) of the keys you want
 *  - Columns: the columns you want returned
 *  - Attributes: Scan attributes
 */
func (client *HClient) ScannerOpenWithPrefix(tableName string, startAndPrefix []byte, columns []string, attributes map[string]string) (id int32, err error) {
	ret, io, e1 := client.hbase.ScannerOpenWithPrefix(Hbase.Text(tableName), Hbase.Text(startAndPrefix), toHbaseTextList(columns), toHbaseTextMap(attributes))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	id = int32(ret)
	return
}
Example #10
0
/**
 * Get all the data for the specified table and row at the latest
 * timestamp. Returns an empty list if the row does not exist.
 *
 * @return TRowResult containing the row and map of columns to TCells
 *
 * Parameters:
 *  - TableName: name of table
 *  - Row: row key
 *  - Attributes: Get attributes
 */
func (client *HClient) GetRow(tableName string, row []byte, attributes map[string]string) (data []*Hbase.TRowResult, err error) {
	ret, io, e1 := client.hbase.GetRow(Hbase.Text(tableName), Hbase.Text(row), toHbaseTextMap(attributes))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	data = ret
	return
}
Example #11
0
func fromMapStr(data map[string]string) thrift.TMap {

	var m thrift.TMap
	if data != nil {
		m = thrift.NewTMap(thrift.STRING, thrift.STRING, len(data))
		for k, v := range data {
			m.Set(Hbase.Text(k), Hbase.Text(v))
		}
	}

	return m
}
Example #12
0
/**
 * Get the row just before the specified one.
 *
 * @return value for specified row/column
 *
 * Parameters:
 *  - TableName: name of table
 *  - Row: row key
 *  - Family: column name
 */
func (client *HClient) GetRowOrBefore(tableName string, row string, family string) (data []*TCell, err error) {
	if err = client.Open(); err != nil {
		return
	}

	ret, io, e1 := client.thriftClient.GetRowOrBefore(Hbase.Text(tableName), Hbase.Text(row), Hbase.Text(family))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	data = toListCell(ret)
	return
}
Example #13
0
/**
 * Get the specified columns for the specified table and row at the specified
 * timestamp. Returns an empty list if the row does not exist.
 *
 * @return TRowResult containing the row and map of columns to TCells
 *
 * Parameters:
 *  - TableName: name of table
 *  - Row: row key
 *  - Columns: List of columns to return, null for all columns
 *  - Timestamp
 *  - Attributes: Get attributes
 */
func (client *HClient) GetRowWithColumnsTs(tableName string, row string, columns []string, timestamp int64, attributes map[string]string) (data []*TRowResult, err error) {
	if err = client.Open(); err != nil {
		return
	}

	ret, io, e1 := client.thriftClient.GetRowWithColumnsTs(Hbase.Text(tableName), Hbase.Text(row), fromListStr(columns), timestamp, fromMapStr(attributes))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	data = toListRowResult(ret)
	return
}
Example #14
0
/**
 * Get all the data for the specified table and row at the latest
 * timestamp. Returns an empty list if the row does not exist.
 *
 * @return TRowResult containing the row and map of columns to TCells
 *
 * Parameters:
 *  - TableName: name of table
 *  - Row: row key
 *  - Attributes: Get attributes
 */
func (client *HClient) GetRow(tableName string, row string, attributes map[string]string) (data []*TRowResult, err error) {
	if err = client.Open(); err != nil {
		return
	}

	ret, io, e1 := client.thriftClient.GetRow(Hbase.Text(tableName), Hbase.Text(row), fromMapStr(attributes))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	data = toListRowResult(ret)
	return
}
Example #15
0
/**
 * Get the specified number of versions for the specified table,
 * row, and column.  Only versions less than or equal to the specified
 * timestamp will be returned.
 *
 * @return list of cells for specified row/column
 *
 * Parameters:
 *  - TableName: name of table
 *  - Row: row key
 *  - Column: column name
 *  - Timestamp: timestamp
 *  - NumVersions: number of versions to retrieve
 *  - Attributes: Get attributes
 */
func (client *HClient) GetVerTs(tableName string, row string, column string, timestamp int64, numVersions int32, attributes map[string]string) (data []*TCell, err error) {
	if err = client.Open(); err != nil {
		return
	}

	ret, io, e1 := client.thriftClient.GetVerTs(Hbase.Text(tableName), Hbase.Text(row), Hbase.Text(column), timestamp, numVersions, fromMapStr(attributes))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	data = toListCell(ret)
	return
}
Example #16
0
/**
 * Deletes a table
 *
 * @throws IOError if table doesn't exist on server or there was some other
 * problem
 *
 * Parameters:
 *  - TableName: name of table to delete
 */
func (client *HClient) DeleteTable(tableName string) (err error) {
	if err = client.Open(); err != nil {
		return
	}

	return checkHbaseError(client.thriftClient.DeleteTable(Hbase.Text(tableName)))
}
Example #17
0
/**
 * List all the column families assoicated with a table.
 *
 * @return list of column family descriptors
 *
 * Parameters:
 *  - TableName: table name
 */
func (client *HClient) GetColumnDescriptors(tableName string) (columns map[string]*ColumnDescriptor, err error) {
	ret, io, e1 := client.hbase.GetColumnDescriptors(Hbase.Text(tableName))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}
	columns = toColMap(ret)
	return
}
Example #18
0
/**
 * Create a table with the specified column families.  The name
 * field for each ColumnDescriptor must be set and must end in a
 * colon (:). All other fields are optional and will get default
 * values if not explicitly specified.
 *
 * @throws IllegalArgument if an input parameter is invalid
 *
 * @throws AlreadyExists if the table name already exists
 *
 * Parameters:
 *  - TableName: name of table to create
 *  - ColumnFamilies: list of column family descriptors
 */
func (client *HClient) CreateTable(tableName string, columnFamilies []*ColumnDescriptor) (exists bool, err error) {
	columns := toHbaseColList(columnFamilies)
	io, ia, ex, e1 := client.hbase.CreateTable(Hbase.Text(tableName), columns)
	if err = checkHbaseArgError(io, ia, e1); err != nil {
		return
	}
	exists = (ex != nil)
	return
}
Example #19
0
/**
 * List the regions associated with a table.
 *
 * @return list of region descriptors
 *
 * Parameters:
 *  - TableName: table name
 */
func (client *HClient) GetTableRegions(tableName string) (regions []*TRegionInfo, err error) {
	ret, io, e1 := client.hbase.GetTableRegions(Hbase.Text(tableName))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	regions = toRegionList(ret)
	return
}
Example #20
0
/**
 * Get the regininfo for the specified row. It scans
 * the metatable to find region's start and end keys.
 *
 * @return value for specified row/column
 *
 * Parameters:
 *  - Row: row key
 */
func (client *HClient) GetRegionInfo(row string) (region *TRegionInfo, err error) {
	ret, io, e1 := client.hbase.GetRegionInfo(Hbase.Text(row))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	region = toRegion(ret)
	return
}
Example #21
0
/**
 * Get a scanner on the current table, using the Scan instance
 * for the scan parameters.
 *
 * Parameters:
 *  - TableName: name of table
 *  - Scan: Scan instance
 *  - Attributes: Scan attributes
 */
func (client *HClient) ScannerOpenWithScan(tableName string, scan *TScan, attributes map[string]string) (id int32, err error) {
	ret, io, e1 := client.hbase.ScannerOpenWithScan(Hbase.Text(tableName), toHbaseTScan(scan), toHbaseTextMap(attributes))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	id = int32(ret)
	return
}
Example #22
0
/**
 * Create a table with the specified column families.  The name
 * field for each ColumnDescriptor must be set and must end in a
 * colon (:). All other fields are optional and will get default
 * values if not explicitly specified.
 *
 * @throws IllegalArgument if an input parameter is invalid
 *
 * @throws AlreadyExists if the table name already exists
 *
 * Parameters:
 *  - TableName: name of table to create
 *  - ColumnFamilies: list of column family descriptors
 */
func (client *HClient) CreateTable(tableName string, columnFamilies []*ColumnDescriptor) (exist *AlreadyExists, err error) {
	if err = client.Open(); err != nil {
		return
	}

	columns := fromColumns(columnFamilies)
	io, ia, ex, e1 := client.thriftClient.CreateTable(Hbase.Text(tableName), columns)
	err = checkHbaseArgError(io, ia, e1)
	exist = toAlreadyExists(ex)
	return
}
Example #23
0
func toHbaseTextListFromByte(list [][]byte) []Hbase.Text {
	if list == nil {
		return nil
	}

	l := len(list)
	data := make([]Hbase.Text, l)
	for i := 0; i < l; i++ {
		data[i] = Hbase.Text(list[i])
	}
	return data
}
Example #24
0
func toHbaseTextMap(source map[string]string) map[string]Hbase.Text {
	if source == nil {
		return nil
	}

	data := make(map[string]Hbase.Text, len(source))
	for k, v := range source {
		data[k] = Hbase.Text(v)
	}

	return data
}
Example #25
0
/**
 * Get the specified columns for the specified table and rows at the latest
 * timestamp. Returns an empty list if no rows exist.
 *
 * @return TRowResult containing the rows and map of columns to TCells
 *
 * Parameters:
 *  - TableName: name of table
 *  - Rows: row keys
 *  - Columns: List of columns to return, null for all columns
 *  - Attributes: Get attributes
 */
func (client *HClient) GetRowsWithColumns(tableName string, rows [][]byte, columns []string, attributes map[string]string) (data []*Hbase.TRowResult, err error) {
	if err = client.Open(); err != nil {
		return
	}

	ret, io, e1 := client.hbase.GetRowsWithColumns(Hbase.Text(tableName), toHbaseTextListFromByte(rows), toHbaseTextList(columns), toHbaseTextMap(attributes))
	if err = checkHbaseError(io, e1); err != nil {
		return
	}

	data = ret
	return
}
Example #26
0
func fromListStr(list []string) thrift.TList {
	if list == nil {
		return nil
	}

	l := len(list)
	data := thrift.NewTList(thrift.STRING, l)
	for i := 0; i < l; i++ {
		//data.Set(i, Hbase.Text(list[i]))
		data.Push(Hbase.Text(list[i]))
	}

	return data
}
Example #27
0
func toHbaseColumn(col *ColumnDescriptor) *Hbase.ColumnDescriptor {
	return &Hbase.ColumnDescriptor{
		Name:                  Hbase.Text(col.Name),
		MaxVersions:           col.MaxVersions,
		Compression:           col.Compression,
		InMemory:              col.InMemory,
		BloomFilterType:       col.BloomFilterType,
		BloomFilterVectorSize: col.BloomFilterVectorSize,
		BloomFilterNbHashes:   col.BloomFilterNbHashes,
		BlockCacheEnabled:     col.BlockCacheEnabled,
		TimeToLive:            col.TimeToLive,
	}

}
Example #28
0
func fromColumns(columnFamilies []*ColumnDescriptor) thrift.TList {
	l := len(columnFamilies)
	columns := thrift.NewTListDefault()
	for i := 0; i < l; i++ {
		col := columnFamilies[i]
		hbaseColumn := &Hbase.ColumnDescriptor{
			Name:                  Hbase.Text(col.Name),
			MaxVersions:           col.MaxVersions,
			Compression:           col.Compression,
			InMemory:              col.InMemory,
			BloomFilterType:       col.BloomFilterType,
			BloomFilterVectorSize: col.BloomFilterVectorSize,
			BloomFilterNbHashes:   col.BloomFilterNbHashes,
			BlockCacheEnabled:     col.BlockCacheEnabled,
			TimeToLive:            col.TimeToLive,
		}
		columns.Push(hbaseColumn)
	}
	return columns
}
Example #29
0
/**
 * Completely delete the row's cells marked with a timestamp
 * equal-to or older than the passed timestamp.
 *
 * Parameters:
 *  - TableName: name of table
 *  - Row: key of the row to be completely deleted.
 *  - Timestamp: timestamp
 *  - Attributes: Delete attributes
 */
func (client *HClient) DeleteAllRowTs(tableName string, row []byte, timestamp int64, attributes map[string]string) error {
	return checkHbaseError(client.hbase.DeleteAllRowTs(Hbase.Text(tableName), Hbase.Text(row), timestamp, toHbaseTextMap(attributes)))
}
Example #30
0
/**
 * Delete all cells that match the passed row and column.
 *
 * Parameters:
 *  - TableName: name of table
 *  - Row: Row to update
 *  - Column: name of column whose value is to be deleted
 *  - Attributes: Delete attributes
 */
func (client *HClient) DeleteAll(tableName string, row []byte, column string, attributes map[string]string) error {
	return checkHbaseError(client.hbase.DeleteAll(Hbase.Text(tableName), Hbase.Text(row), Hbase.Text(column), toHbaseTextMap(attributes)))
}