in linkis-engineconn-plugins/hbase/hbase-shims-2.2.6/src/main/resources/hbase-ruby/hbase/table.rb [347:467]
def _get_internal(row, *args)
get = org.apache.hadoop.hbase.client.Get.new(row.to_s.to_java_bytes)
maxlength = -1
count = 0
@converters.clear
args = args.first if args.first.is_a?(Hash)
if args.is_a?(String) || args.is_a?(Array)
columns = [args].flatten.compact
args = { COLUMNS => columns }
end
unless args.is_a?(Hash)
raise ArgumentError, "Failed parse of #{args.inspect}, #{args.class}"
end
maxlength = args.delete(MAXLENGTH) if args[MAXLENGTH]
filter = args.delete(FILTER) if args[FILTER]
attributes = args[ATTRIBUTES]
authorizations = args[AUTHORIZATIONS]
consistency = args.delete(CONSISTENCY) if args[CONSISTENCY]
replicaId = args.delete(REGION_REPLICA_ID) if args[REGION_REPLICA_ID]
converter = args.delete(FORMATTER) || nil
converter_class = args.delete(FORMATTER_CLASS) || 'org.apache.hadoop.hbase.util.Bytes'
unless args.empty?
columns = args[COLUMN] || args[COLUMNS]
vers = if args[VERSIONS]
args[VERSIONS]
else
1
end
if columns
columns = [columns] if columns.is_a?(String)
unless columns.is_a?(Array)
raise ArgumentError, "Failed parse column argument type #{args.inspect}, #{args.class}"
end
columns.each do |column|
family, qualifier = parse_column_name(column.to_s)
if qualifier
get.addColumn(family, qualifier)
else
get.addFamily(family)
end
end
get.setMaxVersions(vers)
get.setTimeStamp(args[TIMESTAMP]) if args[TIMESTAMP]
get.setTimeRange(args[TIMERANGE][0], args[TIMERANGE][1]) if args[TIMERANGE]
else
if attributes
set_attributes(get, attributes)
elsif authorizations
set_authorizations(get, authorizations)
else
unless ts = args[TIMESTAMP] || tr = args[TIMERANGE]
raise ArgumentError, "Failed parse of #{args.inspect}, #{args.class}"
end
end
get.setMaxVersions(vers)
get.setTimeStamp(ts.to_i) if args[TIMESTAMP]
get.setTimeRange(args[TIMERANGE][0], args[TIMERANGE][1]) if args[TIMERANGE]
end
set_attributes(get, attributes) if attributes
set_authorizations(get, authorizations) if authorizations
end
if filter.class == String
get.setFilter(
org.apache.hadoop.hbase.filter.ParseFilter.new.parseFilterString(filter.to_java_bytes)
)
else
get.setFilter(filter)
end
get.setConsistency(org.apache.hadoop.hbase.client.Consistency.valueOf(consistency)) if consistency
get.setReplicaId(replicaId) if replicaId
result = @table.get(get)
return nil if result.isEmpty
is_stale = result.isStale
count += 1
res = {}
result.listCells.each do |c|
family = convert_bytes_with_position(c.getFamilyArray,
c.getFamilyOffset, c.getFamilyLength, converter_class, converter)
qualifier = convert_bytes_with_position(c.getQualifierArray,
c.getQualifierOffset, c.getQualifierLength, converter_class, converter)
column = "#{family}:#{qualifier}"
value = to_string(column, c, maxlength, converter_class, converter)
if block_given?
yield(column, value)
else
res[column] = value
end
end
(block_given? ? [count, is_stale] : res)
end