Skip to content

Instantly share code, notes, and snippets.

@t3rmin4t0r
Last active March 13, 2019 21:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t3rmin4t0r/c206799f8d33eeaf2b4c9bca38f253a2 to your computer and use it in GitHub Desktop.
Save t3rmin4t0r/c206799f8d33eeaf2b4c9bca38f253a2 to your computer and use it in GitHub Desktop.
Remove beeline pagination from a query result
import sys
sample="""
+------------------------------------------------------------------+--+
| createtab_stmt |
+------------------------------------------------------------------+--+
| CREATE TABLE `finance.xx_po_headers`( |
| `po_header_id` bigint, |
| `requester_name` string, |
+------------------------------------------------------------------+--+
| createtab_stmt |
+------------------------------------------------------------------+--+
| `enabled_flag` string, |
+------------------------------------------------------------------+--+
""".split("\n")
def main(args):
lines = [x.strip() for x in open(args[0])]
NONE='NONE'
SEPARATOR1='SEPARATOR1'
HEADER='HEADER'
SEPARATOR2='SEPARATOR2'
ROW='ROW'
SEPARATOR3='SEPARATOR3'
state=NONE
for l in lines:
if not(l.strip()):
continue
sep = (l.startswith("+-"))
row = (l.startswith("|"))
nstate = None
if (state == NONE and sep):
nstate = SEPARATOR1
elif (state == SEPARATOR3 and sep):
nstate = SEPARATOR1
elif (state == SEPARATOR3 and row):
nstate = HEADER
elif (state == SEPARATOR1 and row):
nstate = HEADER
elif (state == HEADER and sep):
nstate = SEPARATOR2
elif (state == SEPARATOR2 and row):
nstate = ROW
elif (state == ROW and sep):
nstate = SEPARATOR3
elif (state == ROW and row):
nstate = ROW
if not(nstate):
print l
assert nstate != None
if (nstate == ROW):
print l[2:-2].rstrip()
pass
#print "%s -> %s" % (state, nstate)
state = nstate
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment