-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpandas.html
More file actions
250 lines (219 loc) · 12.7 KB
/
pandas.html
File metadata and controls
250 lines (219 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="./">
<head>
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pandas Compatibility — Feldera Python SDK 0.272.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=19f00094" />
<!--[if lt IE 9]>
<script src="_static/js/html5shiv.min.js"></script>
<![endif]-->
<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=8b23721a"></script>
<script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Examples" href="examples.html" />
<link rel="prev" title="Introduction" href="introduction.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home">
Feldera Python SDK
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Pandas Compatibility</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#using-pandas-dataframes-as-input-output">Using Pandas DataFrames as Input / Output</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">API Reference:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="modules.html">feldera</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Feldera Python SDK</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active">Pandas Compatibility</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/pandas.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="pandas-compatibility">
<h1>Pandas Compatibility<a class="headerlink" href="#pandas-compatibility" title="Link to this heading"></a></h1>
<p>Feldera tries to be compatible with the Pandas as much as possible.
However, some types in SQL have limited support in Pandas.</p>
<p>Columns with the following SQL types will be converted to the corresponding Pandas types:</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>SQL Type</p></th>
<th class="head"><p>Pandas Type</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>BOOLEAN</p></td>
<td><p>bool</p></td>
</tr>
<tr class="row-odd"><td><p>TINYINT</p></td>
<td><p>Int8</p></td>
</tr>
<tr class="row-even"><td><p>SMALLINT</p></td>
<td><p>Int16</p></td>
</tr>
<tr class="row-odd"><td><p>INTEGER</p></td>
<td><p>Int32</p></td>
</tr>
<tr class="row-even"><td><p>BIGINT</p></td>
<td><p>Int64</p></td>
</tr>
<tr class="row-odd"><td><p>REAL</p></td>
<td><p>Float32</p></td>
</tr>
<tr class="row-even"><td><p>DOUBLE</p></td>
<td><p>Float64</p></td>
</tr>
<tr class="row-odd"><td><p>DECIMAL</p></td>
<td><p>decimal.Decimal</p></td>
</tr>
<tr class="row-even"><td><p>CHAR</p></td>
<td><p>str</p></td>
</tr>
<tr class="row-odd"><td><p>VARCHAR</p></td>
<td><p>str</p></td>
</tr>
<tr class="row-even"><td><p>DATE</p></td>
<td><p>datetime64[ns]</p></td>
</tr>
<tr class="row-odd"><td><p>TIMESTAMP</p></td>
<td><p>datetime64[ns]</p></td>
</tr>
<tr class="row-even"><td><p>TIME</p></td>
<td><p>timedelta64[ns]</p></td>
</tr>
<tr class="row-odd"><td><p>INTERVAL</p></td>
<td><p>timedelta64[ns]</p></td>
</tr>
<tr class="row-even"><td><p>ARRAY</p></td>
<td><p>object</p></td>
</tr>
<tr class="row-odd"><td><p>BINARY</p></td>
<td><p>object</p></td>
</tr>
<tr class="row-even"><td><p>VARBINARY</p></td>
<td><p>object</p></td>
</tr>
<tr class="row-odd"><td><p>STRUCT</p></td>
<td><p>object</p></td>
</tr>
<tr class="row-even"><td><p>MAP</p></td>
<td><p>object</p></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Please note that the “object” type in Pandas is dynamic and can hold any type of data.
Therefore, the representation of primitive types in arrays, binary, struct, and map types may be different to their
representation as a standalone column.</p>
</div>
<section id="using-pandas-dataframes-as-input-output">
<h2>Using Pandas DataFrames as Input / Output<a class="headerlink" href="#using-pandas-dataframes-as-input-output" title="Link to this heading"></a></h2>
<p>You can use <a class="reference internal" href="feldera.html#feldera.pipeline.Pipeline.input_pandas" title="feldera.pipeline.Pipeline.input_pandas"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Pipeline.input_pandas()</span></code></a> to insert records from a
DataFrame to a Feldera table.</p>
<p>Use <a class="reference internal" href="feldera.html#feldera.pipeline.Pipeline.listen" title="feldera.pipeline.Pipeline.listen"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Pipeline.listen()</span></code></a> to subscribe to updates to a view in the form of a stream of DataFrames.
To ensure all data is received start listening before calling
<a class="reference internal" href="feldera.html#feldera.pipeline.Pipeline.start" title="feldera.pipeline.Pipeline.start"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Pipeline.start()</span></code></a>.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">feldera</span><span class="w"> </span><span class="kn">import</span> <span class="n">FelderaClient</span><span class="p">,</span> <span class="n">PipelineBuilder</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">pandas</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">pd</span>
<span class="n">sql</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"""</span>
<span class="s2">CREATE TABLE students (</span>
<span class="s2"> name STRING,</span>
<span class="s2"> id INT</span>
<span class="s2">);</span>
<span class="s2">CREATE TABLE grades (</span>
<span class="s2"> student_id INT,</span>
<span class="s2"> science INT,</span>
<span class="s2"> maths INT,</span>
<span class="s2"> art INT</span>
<span class="s2">);</span>
<span class="s2">CREATE VIEW average_scores AS SELECT name, ((science + maths + art) / 3) as average FROM </span><span class="si">{</span><span class="n">TBL_NAMES</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="si">}</span><span class="s2"> JOIN </span><span class="si">{</span><span class="n">TBL_NAMES</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="si">}</span><span class="s2"> on id = student_id ORDER BY average DESC;</span>
<span class="s2">"""</span>
<span class="c1"># Create a client</span>
<span class="n">client</span> <span class="o">=</span> <span class="n">FelderaClient</span><span class="p">(</span><span class="s2">"https://try.feldera.com"</span><span class="p">,</span> <span class="n">api_key</span><span class="o">=</span><span class="s2">"YOUR_API_KEY"</span><span class="p">)</span>
<span class="n">pipeline</span> <span class="o">=</span> <span class="n">PipelineBuilder</span><span class="p">(</span><span class="n">client</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">"notebook"</span><span class="p">,</span> <span class="n">sql</span><span class="o">=</span><span class="n">sql</span><span class="p">)</span><span class="o">.</span><span class="n">create_or_replace</span><span class="p">()</span>
<span class="n">df_students</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_csv</span><span class="p">(</span><span class="s1">'students.csv'</span><span class="p">)</span>
<span class="n">df_grades</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_csv</span><span class="p">(</span><span class="s1">'grades.csv'</span><span class="p">)</span>
<span class="n">pipeline</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="c1"># listen for the output of the view here in the notebook</span>
<span class="c1"># you do not need to call this if you are forwarding the data to a sink</span>
<span class="n">out</span> <span class="o">=</span> <span class="n">pipeline</span><span class="o">.</span><span class="n">listen</span><span class="p">(</span><span class="s2">"average_scores"</span><span class="p">)</span>
<span class="n">pipeline</span><span class="o">.</span><span class="n">input_pandas</span><span class="p">(</span><span class="s2">"students"</span><span class="p">,</span> <span class="n">df_students</span><span class="p">)</span>
<span class="n">pipeline</span><span class="o">.</span><span class="n">input_pandas</span><span class="p">(</span><span class="s2">"grades"</span><span class="p">,</span> <span class="n">df_grades</span><span class="p">)</span>
<span class="c1"># wait for the pipeline to complete</span>
<span class="c1"># note that if the source is a stream, this will run indefinitely</span>
<span class="n">pipeline</span><span class="o">.</span><span class="n">wait_for_completion</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">out</span><span class="o">.</span><span class="n">to_pandas</span><span class="p">()</span>
<span class="c1"># see the result</span>
<span class="nb">print</span><span class="p">(</span><span class="n">df</span><span class="p">)</span>
<span class="c1"># clear the storage and delete the pipeline</span>
<span class="n">pipeline</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="introduction.html" class="btn btn-neutral float-left" title="Introduction" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="examples.html" class="btn btn-neutral float-right" title="Examples" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>© Copyright 2024, Feldera.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>