Ibis + Altair.ipynb
import omnisci_renderer
import ibis
import altair as alt
omnisci_cli = ibis.mapd.connect(
host='metis.mapd.com', user='mapd', password='HyperInteractive',
port=443, database='mapd', protocol= 'https'
)
t = omnisci_cli.table('tweets_nov_feb')
expr = t[t.goog_x.name('x'), t.goog_y.name('y'), t.tweet_id.name('rowid')]
print(expr.compile())
Browser rendering¶
Now, let's first try rendering this by getting a Pandas DataFrame and rendering this on the browser
df = expr.execute()
df.head()
This is a lot of data, so let's tell Altair to save it as a temporary JSON file.
This way it all won't be stored in the notebook
alt.data_transformers.enable('json')
alt.renderers.enable('default')
alt.Chart(df, width=384, height=564).mark_square(
color='green',
size=2,
clip=True
).encode(
alt.X(
'x:Q',
scale=alt.Scale(domain=[-3650484.1235206556, 7413325.514451755], range='width')
),
alt.Y(
'y:Q',
scale=alt.Scale(domain=[-5778161.9183506705, 10471808.487466192], range='height')
),
)
OmniSci Rendering¶
That looks OK, but we seem to be missing some data! Well omnisci's API has a default max row limit. Instead of increasing this, let's move all the computation to omnisci, so that we don't have to send all the data to the client, just the rendered graphic.
We enable the omnisci renderer with our connection info and then Altair will treat the string we pass in as a Mapd SQL query.
alt.renderers.enable('omnisci', conn=omnisci_cli)
alt.Chart(expr.compile(), width=384, height=564).mark_square(
color='green',
size=2,
clip=True
).encode(
alt.X(
'x:Q',
scale=alt.Scale(domain=[-3650484.1235206556, 7413325.514451755], range='width')
),
alt.Y(
'y:Q',
scale=alt.Scale(domain=[-5778161.9183506705, 10471808.487466192], range='height')
),
)
You see that we used the exact same Altair code, but we just changed the input. However, it does look a bit different because OmniScis vega backend doesn't behave the same as the standard javascript one.