Tabli - How to execute and shows the result of a SQL Query

Tabli - How to execute and shows the result of a SQL Query

About

Tpcds offers 100 queries. We will load the tpcds data and execute the query number 11.

Steps

Query file location

The file containing this query is located below the tpcds-query connection.

To get the absolute path and other information, you can use the data info. Example:

tabli data info sqlite/[email protected]_query
Information about the data resource (sqlite\[email protected]_query)
ATTRIBUTE      VALUE
------------   -----------------------------------------------------------------
AbsolutePath   D:\code\bytle-mono\db-jdbc\src\main\sql\tpcds\sqlite\query_11.sql
Characterset   ISO-8859-1
Connection     tpcds_query
Count          81
DataUri        sqlite\[email protected]_query
LogicalName    query_11
Name           query_11.sql
Path           sqlite\query_11.sql
Size           2900
Type           text/plain

This query shows customers that have generated growing sales from one year to another in the s and w sales type. Below is an excerpt.

tabli data head --limit 20 sqlite/[email protected]_query
The first 20 rows of the data resource (sqlite\[email protected]_query):

with year_total as (
 select c_customer_id customer_id
       ,c_first_name customer_first_name
       ,c_last_name customer_last_name
       ,c_preferred_cust_flag customer_preferred_cust_flag
       ,c_birth_country customer_birth_country
       ,c_login customer_login
       ,c_email_address customer_email_address
       ,d_year dyear
       ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total
       ,'s' sale_type
 from customer
     ,store_sales
     ,date_dim
 where c_customer_sk = ss_customer_sk
   and ss_sold_date_sk = d_date_sk
 group by c_customer_id
         ,c_first_name
         ,c_last_name

Loading the sales data

To prevent any conflict, you can execute the below command to drop all tables from the sqlite howto connection

tabli data drop *@sqlite

Loading the data with the transfer command. The query_11 is a sales query, we are then loading the sales data and their dependencies

tabli data transfer --with-dependencies *[email protected] @sqlite

where:

Source                         Target                          Latency (ms)   Row Count   Error   Message
----------------------------   -----------------------------   ------------   ---------   -----   -------
[email protected]              [email protected]              27             2
[email protected]             [email protected]             257            11718
[email protected]            [email protected]            6528           89807
[email protected]                 [email protected]                 93             1000
[email protected]         [email protected]         64             1000
[email protected]    [email protected]    17941          1920800
[email protected]                 [email protected]                 4154           73049
[email protected]   [email protected]   68             7200
[email protected]              [email protected]              24             20
[email protected]                     [email protected]                     382            2000
[email protected]                [email protected]                26             3
[email protected]                [email protected]                24             20
[email protected]                    [email protected]                    27             2
[email protected]              [email protected]              5914           120527
[email protected]                 [email protected]                 1076           86400
[email protected]                [email protected]                95             1
[email protected]                 [email protected]                 35             2
[email protected]                [email protected]                896            11876
[email protected]                 [email protected]                 73             2

Executing the query

A query is selected via a script selector where:

  • the first part is a data selector that locates one or more files that contains the query
  • and the second part is the connection where the query should run.

In the below script selector

(sqlite/[email protected]_query)@sqlite

A query data uri can be used with all command.

Example with the data print command.

tabli data print (sqlite/[email protected]_query)@sqlite
customer_id        customer_first_name   customer_last_name   customer_email_address
----------------   -------------------   ------------------   ----------------------------------
AAAAAAAABMDAAAAA   Jose                  Guzman               [email protected]
AAAAAAAAFLAAAAAA   Joseph                Riley                [email protected]
AAAAAAAAJGBAAAAA   Bonnie                Harrison             [email protected]
AAAAAAAAKMDAAAAA   Alexander             White                [email protected]
AAAAAAAAOFCAAAAA   Timothy               Grogan               [email protected]
Powered by ComboStrap