Guest User

Untitled

a guest
Feb 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": null,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "# iquery --afl\n",
  10. "AFL% stream(\n",
  11. " build(<x:int64 not null>[i=1:10:0:5], i),\n",
  12. " 'python -uc \"\n",
  13. "import scidbstrm\n",
  14. "import pyarrow\n",
  15. "import sys\n",
  16. "import tempfile\n",
  17. "\n",
  18. "def save(df):\n",
  19. " rb = pyarrow.RecordBatch.from_pandas(df, preserve_index=False)\n",
  20. "\n",
  21. " fn = tempfile.mkstemp()[1]\n",
  22. " sys.stderr.write(\\\"{}\\\".format(fn))\n",
  23. "\n",
  24. " with pyarrow.OSFile(fn, \\\"wb\\\") as sink:\n",
  25. " writer = pyarrow.RecordBatchStreamWriter(sink, rb.schema)\n",
  26. " writer.write_batch(rb)\n",
  27. " writer.close()\n",
  28. "\n",
  29. " return None\n",
  30. "\n",
  31. "scidbstrm.map(save)\"',\n",
  32. " 'format=feather',\n",
  33. " 'types=int64',\n",
  34. " 'names=unused');"
  35. ]
  36. },
  37. {
  38. "cell_type": "code",
  39. "execution_count": 1,
  40. "metadata": {},
  41. "outputs": [
  42. {
  43. "name": "stdout",
  44. "output_type": "stream",
  45. "text": [
  46. "total 12\r\n",
  47. "-rw-------. 1 rares rares 3787 Feb 13 20:24 read-batches.ipynb\r\n",
  48. "-rw-------. 1 rares rares 556 Feb 13 19:37 tmpGqyn5p\r\n",
  49. "-rw-------. 1 rares rares 556 Feb 13 19:37 tmpzDxek1\r\n"
  50. ]
  51. }
  52. ],
  53. "source": [
  54. "!ls -l"
  55. ]
  56. },
  57. {
  58. "cell_type": "code",
  59. "execution_count": 2,
  60. "metadata": {},
  61. "outputs": [],
  62. "source": [
  63. "import pyarrow"
  64. ]
  65. },
  66. {
  67. "cell_type": "code",
  68. "execution_count": 3,
  69. "metadata": {},
  70. "outputs": [
  71. {
  72. "data": {
  73. "text/plain": [
  74. "(5, 1)"
  75. ]
  76. },
  77. "execution_count": 3,
  78. "metadata": {},
  79. "output_type": "execute_result"
  80. }
  81. ],
  82. "source": [
  83. "reader = pyarrow.open_stream('tmpGqyn5p')\n",
  84. "table = reader.read_all()\n",
  85. "table.shape"
  86. ]
  87. },
  88. {
  89. "cell_type": "code",
  90. "execution_count": 4,
  91. "metadata": {},
  92. "outputs": [
  93. {
  94. "data": {
  95. "text/plain": [
  96. "<pyarrow.lib.Column object at 0x7fe5281ce360>\n",
  97. "chunk 0: <pyarrow.lib.Int64Array object at 0x7fe5281c2c28>\n",
  98. "[\n",
  99. " 6,\n",
  100. " 7,\n",
  101. " 8,\n",
  102. " 9,\n",
  103. " 10\n",
  104. "]"
  105. ]
  106. },
  107. "execution_count": 4,
  108. "metadata": {},
  109. "output_type": "execute_result"
  110. }
  111. ],
  112. "source": [
  113. "table[0]"
  114. ]
  115. },
  116. {
  117. "cell_type": "code",
  118. "execution_count": 5,
  119. "metadata": {},
  120. "outputs": [
  121. {
  122. "data": {
  123. "text/plain": [
  124. "(5, 1)"
  125. ]
  126. },
  127. "execution_count": 5,
  128. "metadata": {},
  129. "output_type": "execute_result"
  130. }
  131. ],
  132. "source": [
  133. "reader = pyarrow.open_stream('tmpzDxek1')\n",
  134. "table = reader.read_all()\n",
  135. "table.shape"
  136. ]
  137. },
  138. {
  139. "cell_type": "code",
  140. "execution_count": 6,
  141. "metadata": {},
  142. "outputs": [
  143. {
  144. "data": {
  145. "text/plain": [
  146. "<pyarrow.lib.Column object at 0x7fe5281ce450>\n",
  147. "chunk 0: <pyarrow.lib.Int64Array object at 0x7fe5281dc598>\n",
  148. "[\n",
  149. " 1,\n",
  150. " 2,\n",
  151. " 3,\n",
  152. " 4,\n",
  153. " 5\n",
  154. "]"
  155. ]
  156. },
  157. "execution_count": 6,
  158. "metadata": {},
  159. "output_type": "execute_result"
  160. }
  161. ],
  162. "source": [
  163. "table[0]"
  164. ]
  165. }
  166. ],
  167. "metadata": {
  168. "kernelspec": {
  169. "display_name": "Python 3",
  170. "language": "python",
  171. "name": "python3"
  172. },
  173. "language_info": {
  174. "codemirror_mode": {
  175. "name": "ipython",
  176. "version": 3
  177. },
  178. "file_extension": ".py",
  179. "mimetype": "text/x-python",
  180. "name": "python",
  181. "nbconvert_exporter": "python",
  182. "pygments_lexer": "ipython3",
  183. "version": "3.6.4"
  184. }
  185. },
  186. "nbformat": 4,
  187. "nbformat_minor": 2
  188. }
Add Comment
Please, Sign In to add comment