Add binary option to bulkdata.append_string
This commit is contained in:
parent
d9afb48f45
commit
efa9aa9097
|
@ -413,12 +413,16 @@ class Table(object):
|
|||
return rocket.Rocket(self.layout,
|
||||
os.path.join(self.root, subdir, filename))
|
||||
|
||||
def append_string(self, data, start, end):
|
||||
def append_string(self, data, start, end, binary = False):
|
||||
"""Parse the formatted string in 'data', according to the
|
||||
current layout, and append it to the table. If any timestamps
|
||||
are non-monotonic, or don't fall between 'start' and 'end',
|
||||
a ValueError is raised.
|
||||
|
||||
If 'binary' is True, the data should be in raw binary format
|
||||
instead: little-endian, matching the current table's layout,
|
||||
including the int64 timestamp.
|
||||
|
||||
If this function succeeds, it returns normally. Otherwise,
|
||||
the table is reverted back to its original state by truncating
|
||||
or deleting files as necessary."""
|
||||
|
@ -437,17 +441,26 @@ class Table(object):
|
|||
# Ask the rocket object to parse and append up to "count"
|
||||
# rows of data, verifying things along the way.
|
||||
try:
|
||||
if binary:
|
||||
appender = f.append_binary
|
||||
else:
|
||||
appender = f.append_string
|
||||
(added_rows, data_offset, last_timestamp, linenum
|
||||
) = f.append_string(count, data, data_offset, linenum,
|
||||
start, end, last_timestamp)
|
||||
) = appender(count, data, data_offset, linenum,
|
||||
start, end, last_timestamp)
|
||||
except rocket.ParseError as e:
|
||||
(linenum, colnum, errtype, obj) = e.args
|
||||
where = "line %d, column %d: " % (linenum, colnum)
|
||||
if binary:
|
||||
where = "byte %d: " % (linenum)
|
||||
else:
|
||||
where = "line %d, column %d: " % (linenum, colnum)
|
||||
# Extract out the error line, add column marker
|
||||
try:
|
||||
if binary:
|
||||
raise IndexError
|
||||
bad = data.splitlines()[linenum-1]
|
||||
badptr = ' ' * (colnum - 1) + '^'
|
||||
except IndexError: # pragma: no cover
|
||||
bad += '\n' + ' ' * (colnum - 1) + '^'
|
||||
except IndexError:
|
||||
bad = ""
|
||||
if errtype == rocket.ERR_NON_MONOTONIC:
|
||||
err = "timestamp is not monotonically increasing"
|
||||
|
@ -463,7 +476,7 @@ class Table(object):
|
|||
else:
|
||||
err = str(obj)
|
||||
raise ValueError("error parsing input data: " +
|
||||
where + err + "\n" + bad + "\n" + badptr)
|
||||
where + err + "\n" + bad)
|
||||
tot_rows += added_rows
|
||||
except Exception:
|
||||
# Some failure, so try to roll things back by truncating or
|
||||
|
|
Loading…
Reference in New Issue
Block a user