Basic usage#
This section shows how to perform basic iris operations in Jupyter Notebook.
The iris interface#
iris's interface consists of line and cell magic commands.
A line magic command begins with
%
and can be used with a set of switched arguments on a single line. For example,%ten_help
displays usage information.A cell magic command begins with
%%
, and the following lines contain the rest of the input. For example,%%ten_query
is followed by the 1010data query written in Macro Language.
Loading iris#
Load iris as follows:
%load_ext iris
The %ten_iris_version
command displays the version of iris you are using.
Starting a 1010data session#
The line magic command %ten_login
starts a 1010data session:
%ten_login -g URL -u USERNAME -p PASSWORD --possess --xmllog LOGNAME
--xmllog LOGNAME
enables logging for the session. It is optional, but very helpful for troubleshooting.
iris displays the number of seconds it took to log in.
Running a 1010data Macro Language query#
The %%ten_query
cell magic command, followed by a 1010data query, runs the query in 1010data Macro Language and displays a grid.
The following query displays all transactions from store 1:
%%ten_query
<base table="pub.demo.retail.item"/>
<sel value="store='1'"/>
<sort cols="date"/>
If you simply want to display an entire table, you can use the %ten_query
line magic command along with the --base
parameter, as follows:
%ten_query --base pub.demo.retail.item
Running a SQL query#
The %%ten_sql
cell magic command, followed by a SQL query, runs the query and displays a grid.
%%ten_sql
SELECT * FROM "pub.demo.retail.item" WHERE "Store" IN (1,3)
ORDER BY "Date";
Running TenFrames#
Note
TenFrame must be installed. See Installing TenFrame in the TenFrame User's Guide.
Creating a TenFrame requires a py1010.Session
object. You can use the line magic command %ten_get_ses
to access a session created through %ten_login
, or you can create your session using py1010 directly.
import tenFrame
session = %ten_get_ses
#import py1010
#session = py1010.Session("1010data URL", "USERNAME", "PASSWORD", py1010.POSSESS)
frame = tenFrame.TenFrame(session, "pub.demo.retail.item")
Running server-side Python#
Note
Your 1010data environment must be enabled with this feature.
The %ten_py_version
line magic command displays the version of Python running on the server:
The %%ten_py_stream
cell magic command, followed by Python code, instantiates an interpreter in your session's main server-side process, runs your Python code, and returns results from the pandas.DataFrame
passed into the ten.rebase
function.
%%ten_py_stream
# Some data
species = ['molurus','sebae','regius','bivittatus','curtus','breitensteini','anchietae']
name = ['Indian Python','African rock python','Ball python','Burmese python',
'Sumatran short-tailed python','Bornean short-tailed python','Angolan python']
year = [1758, 1788, 1802, 1820, 1872, 1881, 1887]
# Create a Pandas DataFrame, note that we didn't need to import pandas,
# it is automatically imported
df = pd.DataFrame({'python':species,'name':name,'discovery_year':year})
# Create an op
ops = ten.rebase(df)
Running server-side R#
Note
Your 1010data environment must be enabled with this feature.
The %ten_r_version
line magic command displays the version of R running on the server:
The %%ten_r_stream
cell magic command displays results from the data.frame
passed into the ReBase
function.
%%ten_r_stream
# create a table using a native R data.frame
ops <- ReBase(iris) # iris is a data.frame built into base R
Saving query results#
Note
You must have TenFrame or pandas installed.
To save query results as a TenFrame, use the --tenframe
switch with %%ten_query
.
%%ten_query --tenframe frame
<base table="pub.demo.retail.item"/>
To save query results as a pandas DataFrame, use the --pandas
switch with %%ten_query
. Use -nrows
to specify the number of rows to save. The default number of rows is 10.
%%ten_query --pandas frame --nrows 3
<base table="pub.demo.retail.item"/>
Saving query results as a 1010data Quick Query#
The %%ten_save_query
cell magic command saves a Macro Language query as a 1010data Quick Query in the path specified in the --path
switch. Optionally, you can add a title (--title
), short description (--sdesc
), long description (--ldesc
), and authorized users (--users
) to the Quick Query. --run
runs the query.
%%ten_save_query --path retail.data --title MyQuickQuery --users user1,user2
<base table="pub.demo.retail.item"/>
<sel value="store='1','3'"/>
Clearing the cache#
Use %ten_clearcache
to delete the server-side subprocesses and the cache of the main process associated with your session. If you have multiple active sessions, use --session-name NAME
to specify the session:
%ten_clearcache --session-name NAME
Listing objects#
Use %ten_dir
to list objects (directories, tables, queries), within a directory specified by --dir
:
%ten_dir --dir DIRNAME
If you do not specify a directory, iris uses the root directory.