updates
rodzic
8b7ff765f7
commit
02fe76cf84
145
README.md
145
README.md
|
@ -11,59 +11,99 @@
|
|||
The following will walk you through the steps for setting up [Apache Zeppelin](https://zeppelin.apache.org/) to integrate with MariaDB and work with several samples of modern SQL functionality.
|
||||
|
||||
# Table of Contents
|
||||
1. [Environment and Compatibility](#compatibility)
|
||||
2. [Getting started with MariaDB](#overview)
|
||||
1. [The Basics](#intro-mariadb)
|
||||
2. [Downloading and installing MariaDB](#installation)
|
||||
3. [Requirements](#requirements)
|
||||
4. [Getting started with Apache Zeppelin](#getting-started)
|
||||
5. [Support and Contribution](#support-contribution)
|
||||
6. [License](#license)
|
||||
1. [Requirements](#requirements)
|
||||
2. [Introduction to MariaDB](#introduction)
|
||||
1. [MariaDB Platform](#platform)
|
||||
2. [MariaDB SkySQL](#skysql)
|
||||
3. [Preparing the database](#prepare)
|
||||
1. [Create the schema](#schema)
|
||||
2. [Load the data](#data)
|
||||
4. [Using Apache Zeppelin](#getting-started)
|
||||
1. [Adding a MariaDB Interpreter](#add-interpreter)
|
||||
2. [Importing Zeppelin notes](#import-note)
|
||||
5. [Raw Queries](#queries)
|
||||
6. [Support and Contribution](#support-contribution)
|
||||
7. [License](#license)
|
||||
|
||||
## Environment and Compatibility <a name="compatibility"></a>
|
||||
|
||||
This sample was created using the following techologies:
|
||||
|
||||
* [MariaDB](https://mariadb.com/products/mariadb-platform/)
|
||||
* [Apache Zeppelin](https://zeppelin.apache.org/)
|
||||
|
||||
This application was tested on [macOS Mojave v.10.14.6](https://developer.apple.com/documentation/macos_release_notes/macos_mojave_10_14_6_release_notes).
|
||||
|
||||
## Overview <a name="overview"></a>
|
||||
|
||||
### Introduction to MariaDB <a name="intro-mariadb"></a>
|
||||
|
||||
[MariaDB platform](https://mariadb.com/products/mariadb-platform/) unifies [MariaDB TX (transactions)](https://mariadb.com/products/mariadb-platform-transactional/) and [MariaDB AX (analytics)](https://mariadb.com/products/mariadb-platform-analytical/) so transactional applications can retain unlimited historical data and leverage powerful, real-time analytics in order to provide data-driven customers with more information, actionable insight and greater value – and businesses with endless ways to monetize data. It is the enterprise open source database for hybrid transactional/analytical processing at scale.
|
||||
|
||||
### Getting start with MariaDB <a name="installation"></a>
|
||||
|
||||
To download and deploy MariaDB check out the instructions [here](https://mariadb.com/docs/deploy/installation/). You can also make use of the [MariaDB Image available on Docker Hub](https://hub.docker.com/_/mariadb).
|
||||
|
||||
### Create the schema <a name="create-schema"></a>
|
||||
|
||||
Next execute the SQL within [create_schema_data.sql](create_schema_data.sql) within a new database. The script will create the following tables
|
||||
|
||||
* supers
|
||||
* teams
|
||||
* supersteams
|
||||
|
||||
and insert a small amount of sample data into them. From there you can add/remove your own data!
|
||||
|
||||
## Requirements <a name="requirements"></a>
|
||||
## Environment and Compatibility <a name="requirements"></a>
|
||||
|
||||
This project assumes you have familiarity with building web applications using ReactJS and NodeJS technologies.
|
||||
|
||||
* Download and install [MariaDB](#installation).
|
||||
* Download and install [MariaDB](#introduction).
|
||||
* Download and install [Apache Zeppelin](https://zeppelin.apache.org/download.html).
|
||||
* git (Optional) - this is required if you would prefer to pull the source code from GitHub repo.
|
||||
- Create a [free github account](https://github.com/) if you don’t already have one
|
||||
- git can be downloaded from git-scm.org
|
||||
|
||||
## Introduction to MariaDB <a name="introduction"></a>
|
||||
|
||||
### MariaDB Platform <a name="platform"></a>
|
||||
|
||||
[MariaDB Platform](https://mariadb.com/products/mariadb-platform/) integrates [transactional](https://mariadb.com/products/mariadb-platform-transactional/) and [analytical](https://mariadb.com/products/mariadb-platform-analytical/) products so developers can build modern applications by enriching transactions with real-time analytics and historical data, creating insightful experiences and compelling opportunities for customers – and for businesses, endless ways to monetize data.
|
||||
|
||||
<p align="center" spacing="10">
|
||||
<kbd>
|
||||
<img src="media/platform.png" />
|
||||
</kbd>
|
||||
</p>
|
||||
|
||||
To get started using MariaDB locally you can choose one of the following options:
|
||||
|
||||
* [Download and install MariaDB (Community or Enterprise) directly from mariadb.com](https://mariadb.com/docs/deploy/installation/)
|
||||
|
||||
* [Download and install MariaDB using the official MariaDB Community Server 10.5 Docker Image available at hub.docker.com](https://hub.docker.com/r/mariadb/columnstore)
|
||||
|
||||
### MariaDB SkySQL <a name="skysql">
|
||||
|
||||
[SkySQL](https://mariadb.com/products/skysql/) is the first and only database-as-a-service (DBaaS) to bring the full power of MariaDB Platform to the cloud, including its support for transactional, analytical and hybrid workloads. Built on Kubernetes, and optimized for cloud infrastructure and services, SkySQL combines ease of use and self-service with enterprise reliability and world-class support – everything needed to safely run mission-critical databases in the cloud, and with enterprise governance.
|
||||
|
||||
[Get started with SkySQL!](https://mariadb.com/products/skysql/#get-started)
|
||||
|
||||
<p align="center" spacing="10">
|
||||
<kbd>
|
||||
<img src="media/skysql.png" />
|
||||
</kbd>
|
||||
</p>
|
||||
|
||||
## Preparing the database <a name="prepare"></a>
|
||||
|
||||
### Create the schema <a name="schema"></a>
|
||||
|
||||
Next execute the SQL within [schema.sql](sql/schema.sql) either manually within a new database, or using the MariaDB client:
|
||||
|
||||
Locally (with root and empty password):
|
||||
```bash
|
||||
$ mariadb < sql/schema.sql
|
||||
```
|
||||
|
||||
MariaDB SkySQL:
|
||||
```bash
|
||||
mariadb --host tx-1.mdb0001390.db.skysql.net --port 5002 --user DB00003108 -pPassword123! --ssl-ca ~/Downloads/skysql_chain.pem < sql/schema.sql>
|
||||
```
|
||||
|
||||
**Note:** The previous commands assume you have the MariaDB client installed, the relative locations of [schema.sql](sql/schema.sql) and the skysql_chain.pem file residing in a directory called `Downloads`. But all things are configurable :)
|
||||
|
||||
The script will create the following tables within a database called `demo`:
|
||||
|
||||
* `supers`
|
||||
* `teams`
|
||||
* `supersteams`
|
||||
|
||||
### Load the data <a name="data"></a>
|
||||
|
||||
Once the database and tables have been created, execute the [data.sql](sql/data.sql) script to load data into the tables.
|
||||
|
||||
```bash
|
||||
$ mariadb < sql/data.sql
|
||||
```
|
||||
|
||||
## Getting started with Apache Zeppelin<a name="getting-started"></a>
|
||||
|
||||
### Adding a MariaDB interpreter
|
||||
### Adding a MariaDB interpreter <a name="add-interpreter></a>
|
||||
|
||||
Once you've downloaded and installed Apache Zeppelin you will need to add a new [interpreter](https://zeppelin.apache.org/docs/0.8.2/usage/interpreter/overview.html) for MariaDB using the following steps:
|
||||
For a more comprehensive step-by-step walk-through of how to setup and use Zeppelin with MariaDB check out [this blog post](https://mariadb.com/resources/blog/create-beautiful-data-with-mariadb-skysql-and-apache-zeppelin/)!
|
||||
|
||||
After you've downloaded and installed Apache Zeppelin you will need to add a new [interpreter](https://zeppelin.apache.org/docs/0.8.2/usage/interpreter/overview.html) for MariaDB using the following steps:
|
||||
|
||||
1. Navigate to "Interpreter".
|
||||
|
||||
|
@ -99,16 +139,24 @@ Once you've downloaded and installed Apache Zeppelin you will need to add a new
|
|||
</kbd>
|
||||
</p>
|
||||
|
||||
### Importing the notebooks
|
||||
### Importing notes <a name="import-notes"></a>
|
||||
|
||||
Import the notes:
|
||||
In Zeppelin, a notebook is simply a collection of notes, which is a collection of “paragraphs”. Each paragraph then uses an interpreter (via MariaDB Connector/J) to connect to and communicate with a datasource (MariaDB).
|
||||
|
||||
* [demo_1.json](demo_1.json): Set operators, table value constructors, aggregation functions, and rollups.
|
||||
* [demo_2.json](demo_2.json): Window functions and common table expressions (recursive).
|
||||
* [demo_3.json](demo_3.json): Temporal tables.
|
||||
<p align="center" spacing="10">
|
||||
<kbd>
|
||||
<img src="media/zeppelin.png" />
|
||||
</kbd>
|
||||
</p>
|
||||
|
||||
This repo contains several notes that demonstrate a variety of modern SQL capabilities within MariaDB.
|
||||
|
||||
* [demo_1](zeppelin/demo_1.json), [demo_4](zeppelin/demo_4.json): Set operators, table value constructors, aggregation functions, and rollups.
|
||||
* [demo_2](zeppelin/demo_2.json), [demo_5](zeppelin/demo_5.json): Window functions and common table expressions (recursive).
|
||||
* [demo_3](zeppelin/demo_3.json), [demo_6](zeppelin/demo_6.json): Temporal tables.
|
||||
* [bitemporal-table-demo](bitemporal-table-demo.json): A comprehensive look at a MariaDB Bitemporal table.
|
||||
|
||||
by selecting "Import note".
|
||||
Notes can be imported into Zeppelin by clicking the "Import Note" button, and providing a valid `json` note file.
|
||||
|
||||
<p align="center" spacing="10">
|
||||
<kbd>
|
||||
|
@ -116,6 +164,9 @@ by selecting "Import note".
|
|||
</kbd>
|
||||
</p>
|
||||
|
||||
## Raw Queires <a name="queries"></a>
|
||||
|
||||
If you'd prefer to execute the SQL queries contained within the Apache Zeppelin you can find them all within [demos.sql](sql/demos.sql).
|
||||
|
||||
## Support and Contribution <a name="support-contribution"></a>
|
||||
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
DROP TABLE IF EXISTS `supers`;
|
||||
|
||||
CREATE TABLE `supers` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) NOT NULL DEFAULT '',
|
||||
`alias` varchar(50) NOT NULL DEFAULT '',
|
||||
`type` char(1) NOT NULL DEFAULT '',
|
||||
`rescues` int(11) NOT NULL,
|
||||
`mentor` int(11) DEFAULT NULL,
|
||||
`startDate` datetime NOT NULL,
|
||||
`endDate` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
PERIOD FOR `date_period` (`startDate`, `endDate`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
LOCK TABLES `supers` WRITE;
|
||||
|
||||
INSERT INTO `supers` (`id`, `name`, `alias`, `type`, `rescues`, `mentor`, `startDate`, `endDate`)
|
||||
VALUES
|
||||
(1,'Bruce Wayne','Batman','H',192,6,'2016-01-01 00:00:00','2020-01-01 00:00:00'),
|
||||
(2,'Clark Kent','Superman','H',257,NULL,'2016-01-01 00:00:00','2020-01-01 00:00:00'),
|
||||
(3,'Diana Prince','Wonder Woman','H',212,NULL,'2016-01-01 00:00:00','2020-01-01 00:00:00'),
|
||||
(4,'Dick Grayson','Robin/Nightwing','H',127,1,'2016-01-01 00:00:00','2020-01-01 00:00:00'),
|
||||
(5,'Beast Boy','Gar Logan','H',59,NULL,'2016-01-01 00:00:00','2020-01-01 00:00:00'),
|
||||
(6,'Ra\'s Ah Ghul','The Demon\'s Head','V',3,NULL,'2016-06-01 00:00:00','2020-01-01 00:00:00'),
|
||||
(7,'Frank Castle','The Punisher','V',37,NULL,'2016-01-01 00:00:00','2020-01-01 00:00:00');
|
||||
|
||||
UNLOCK TABLES;
|
||||
|
||||
|
||||
# Dump of table supersteams
|
||||
# ------------------------------------------------------------
|
||||
|
||||
DROP TABLE IF EXISTS `supersteams`;
|
||||
|
||||
CREATE TABLE `supersteams` (
|
||||
`supersid` int(11) unsigned NOT NULL,
|
||||
`teamsid` int(11) unsigned NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
LOCK TABLES `supersteams` WRITE;
|
||||
|
||||
INSERT INTO `supersteams` (`supersid`, `teamsid`)
|
||||
VALUES
|
||||
(1,1),
|
||||
(2,1),
|
||||
(3,1),
|
||||
(4,1),
|
||||
(4,2),
|
||||
(5,2);
|
||||
|
||||
UNLOCK TABLES;
|
||||
|
||||
|
||||
# Dump of table teams
|
||||
# ------------------------------------------------------------
|
||||
|
||||
DROP TABLE IF EXISTS `teams`;
|
||||
|
||||
CREATE TABLE `teams` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(50) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
LOCK TABLES `teams` WRITE;
|
||||
|
||||
INSERT INTO `teams` (`id`, `name`)
|
||||
VALUES
|
||||
(1,'Justice League'),
|
||||
(2,'Teen Titans');
|
||||
|
||||
UNLOCK TABLES;
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1 +0,0 @@
|
|||
{"paragraphs":[{"text":"%mariadb\n\n/* Temporal Table - Application Time */\n\nSELECT \n id, name, alias, type, startDate, endDate\nFROM\n demo.supers\nWHERE \n name = 'Frank Castle' \nORDER BY \n startDate","user":"anonymous","dateUpdated":"2020-02-25T18:56:13+0000","config":{"colWidth":12,"fontSize":9,"enabled":true,"results":{"0":{"graph":{"mode":"table","height":300,"optionOpen":false,"setting":{"table":{"tableGridState":{},"tableColumnTypeState":{"names":{"id":"string","name":"string","alias":"string","type":"string","startDate":"string","endDate":"string"},"updated":false},"tableOptionSpecHash":"[{\"name\":\"useFilter\",\"valueType\":\"boolean\",\"defaultValue\":false,\"widget\":\"checkbox\",\"description\":\"Enable filter for columns\"},{\"name\":\"showPagination\",\"valueType\":\"boolean\",\"defaultValue\":false,\"widget\":\"checkbox\",\"description\":\"Enable pagination for better navigation\"},{\"name\":\"showAggregationFooter\",\"valueType\":\"boolean\",\"defaultValue\":false,\"widget\":\"checkbox\",\"description\":\"Enable a footer for displaying aggregated values\"}]","tableOptionValue":{"useFilter":false,"showPagination":false,"showAggregationFooter":false},"updated":false,"initialized":false},"lineChart":{"rotate":{"degree":"-45"},"xLabelStatus":"default"},"stackedAreaChart":{"rotate":{"degree":"-45"},"xLabelStatus":"default"},"scatterChart":{"yAxis":{"name":"startDate","index":1,"aggr":"sum"},"group":{"name":"type","index":0,"aggr":"sum"},"xAxis":{"name":"endDate","index":2,"aggr":"sum"}},"pieChart":{},"multiBarChart":{"rotate":{"degree":"-45"},"xLabelStatus":"default"}},"keys":[],"groups":[],"values":[],"commonSetting":{}},"helium":{}}},"editorSetting":{"language":"sql","editOnDblClick":false,"completionKey":"TAB","completionSupport":true},"editorMode":"ace/mode/sql"},"settings":{"params":{},"forms":{}},"results":{"code":"SUCCESS","msg":[{"type":"TABLE","data":"id\tname\talias\ttype\tstartDate\tendDate\n17\tFrank Castle\tThe Punisher\tH\t2016-01-01 00:00:00.0\t2016-06-01 00:00:00.0\n7\tFrank Castle\tThe Punisher\tV\t2016-06-01 00:00:00.0\t2017-06-01 00:00:00.0\n18\tFrank Castle\tThe Punisher\tH\t2017-06-01 00:00:00.0\t2020-01-01 00:00:00.0\n"}]},"apps":[],"jobName":"paragraph_1582302441669_1528409790","id":"20200221-162721_22859113","dateCreated":"2020-02-21T16:27:21+0000","dateStarted":"2020-02-25T18:56:13+0000","dateFinished":"2020-02-25T18:56:13+0000","status":"FINISHED","progressUpdateIntervalMs":500,"focus":true,"$$hashKey":"object:22025"},{"text":"%mariadb\n\nUPDATE demo.supers\n FOR PORTION OF date_period\nFROM '2016-06-01' to '2017-06-01'\n SET type = 'V'\nWHERE id = 7","user":"anonymous","dateUpdated":"2020-02-25T18:56:06+0000","config":{"colWidth":12,"fontSize":9,"enabled":true,"results":{},"editorSetting":{"language":"sql","editOnDblClick":false,"completionKey":"TAB","completionSupport":true},"editorMode":"ace/mode/sql"},"settings":{"params":{},"forms":{}},"results":{"code":"SUCCESS","msg":[{"type":"TEXT","data":"Query executed successfully. Affected rows : 1"}]},"apps":[],"jobName":"paragraph_1582320067715_487363913","id":"20200221-212107_406003971","dateCreated":"2020-02-21T21:21:07+0000","dateStarted":"2020-02-25T18:56:06+0000","dateFinished":"2020-02-25T18:56:06+0000","status":"FINISHED","progressUpdateIntervalMs":500,"$$hashKey":"object:22026"},{"text":"%mariadb\n","user":"anonymous","dateUpdated":"2020-02-25T00:54:25+0000","config":{"colWidth":12,"fontSize":9,"enabled":true,"results":{},"editorSetting":{"language":"sql","editOnDblClick":false,"completionKey":"TAB","completionSupport":true},"editorMode":"ace/mode/sql"},"settings":{"params":{},"forms":{}},"apps":[],"jobName":"paragraph_1582592065740_-1031376089","id":"20200225-005425_624048741","dateCreated":"2020-02-25T00:54:25+0000","status":"READY","errorMessage":"","progressUpdateIntervalMs":500,"$$hashKey":"object:22027"}],"name":"Super Demo 3","id":"2F13T1FEP","noteParams":{},"noteForms":{},"angularObjects":{"mariadb:shared_process":[],"spark:shared_process":[]},"config":{"isZeppelinNotebookCronEnable":false,"looknfeel":"default","personalizedMode":"false"},"info":{}}
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 279 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 54 KiB |
|
@ -0,0 +1,38 @@
|
|||
USE demo;
|
||||
|
||||
/* Add supers */
|
||||
INSERT INTO `supers` (`name`, `type`, `rescues`, `mentor`, `startDate`, `endDate`)
|
||||
VALUES
|
||||
('Batman','H',192,6,'1997-01-01 00:00:00','2021-02-17 00:00:00'),
|
||||
('Superman','H',257,NULL,'1998-01-01 00:00:00','2021-02-17 00:00:00'),
|
||||
('Wonder Woman','H',212,NULL,'1985-01-01 00:00:00','2021-02-17 00:00:00'),
|
||||
('Robin/Nightwing','H',127,1,'2008-01-01 00:00:00','2021-02-17 00:00:00'),
|
||||
('Gar Logan','H',59,NULL,'2017-01-01 00:00:00','2021-02-17 00:00:00'),
|
||||
("Ra's Ah Ghul",'V',3,NULL,'1990-06-01 00:00:00','2021-02-17 00:00:00'),
|
||||
('The Punisher','V',37,NULL,'2003-01-01 00:00:00','2021-02-17 00:00:00'),
|
||||
('The Flash','H',297,NULL,'2001-01-01 00:00:00','2021-02-17 00:00:00'),
|
||||
('Kid Flash','H',61,NULL,'2018-01-01 00:00:00','2021-02-17 00:00:00'),
|
||||
('Catwoman','V',43,NULL,'1998-01-01 00:00:00','2021-02-17 00:00:00');
|
||||
|
||||
/* Add teams */
|
||||
INSERT INTO `teams` (`name`)
|
||||
VALUES
|
||||
('Justice Society of America'),
|
||||
('Justice League of America'),
|
||||
('Teen Titans');
|
||||
|
||||
/* Add supers to teams */
|
||||
INSERT INTO `supersteams` (`superid`, `teamid`)
|
||||
VALUES
|
||||
(1,2),
|
||||
(2,2),
|
||||
(3,2),
|
||||
(4,2),
|
||||
(4,3),
|
||||
(5,3),
|
||||
(8,1),
|
||||
(8,2),
|
||||
(9,3);
|
||||
|
||||
|
||||
/* mariadb --host transactions-1.mdb0001390.db.skysql.net --port 5002 --user DB00003108 -p'E30W9,614oI6/8s1pn7Vl8' --ssl-ca ~/Downloads/skysql_chain.pem < schema.sql */
|
|
@ -0,0 +1,112 @@
|
|||
|
||||
/* Aggregate functions, Rollups/Super-Aggregates,
|
||||
Table Value Constructors, Set Operators, Precedence Operators
|
||||
*/
|
||||
|
||||
/* Aggregate functions */
|
||||
SELECT SUM(rescues) FROM demo.supers;
|
||||
|
||||
/* Rollup / Super-aggregates */
|
||||
SELECT
|
||||
t.name, AVG(rescues) as avg_rescues, SUM(rescues) as total_rescues
|
||||
FROM
|
||||
demo.supers AS s INNER JOIN
|
||||
demo.supersteams AS st ON s.id = st.superid LEFT JOIN
|
||||
demo.teams AS t ON st.teamid = t.id
|
||||
GROUP BY
|
||||
t.name
|
||||
WITH ROLLUP;
|
||||
|
||||
/* Set Operators */
|
||||
SELECT
|
||||
name
|
||||
FROM
|
||||
demo.supers AS s INNER JOIN
|
||||
demo.supersteams AS st ON s.id = st.superid
|
||||
WHERE
|
||||
st.teamid = 1
|
||||
UNION
|
||||
SELECT
|
||||
name
|
||||
FROM
|
||||
demo.supers AS s INNER JOIN
|
||||
demo.supersteams AS st ON s.id = st.superid
|
||||
WHERE
|
||||
st.teamid = 2
|
||||
|
||||
/* Table Value Constructor */
|
||||
SELECT
|
||||
name, rescues
|
||||
FROM
|
||||
demo.supers AS s INNER JOIN
|
||||
demo.supersteams AS st ON s.id = st.superid
|
||||
WHERE
|
||||
st.teamid = 1
|
||||
UNION
|
||||
values ('Super Developer', 0)
|
||||
|
||||
|
||||
/* Window functions, Common Table Expressions (CTEs) */
|
||||
|
||||
/* Window function */
|
||||
SELECT
|
||||
s.name as name, s.rescues,
|
||||
RANK() OVER (PARTITION BY t.name ORDER BY s.rescues DESC) AS rank,
|
||||
t.name as team,
|
||||
sum(rescues) OVER(PARTITION BY t.name) as team_total
|
||||
FROM
|
||||
demo.supers s INNER JOIN
|
||||
demo.supersteams st ON s.id = st.superid INNER JOIN
|
||||
demo.teams t ON t.id = st.teamid
|
||||
ORDER BY
|
||||
t.name, s.rescues DESC
|
||||
|
||||
/* Non-recursive CTE */
|
||||
WITH new_heroes AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
demo.supers
|
||||
WHERE
|
||||
rescues < 150 and
|
||||
type = 'H'
|
||||
)
|
||||
|
||||
SELECT * FROM new_heroes
|
||||
INTERSECT
|
||||
SELECT s.*
|
||||
FROM
|
||||
demo.supers s
|
||||
INNER JOIN demo.supersteams st ON s.id = st.superid
|
||||
INNER JOIN demo.teams t ON st.teamid = t.id
|
||||
WHERE
|
||||
t.id = 2;
|
||||
|
||||
/* Recursive CTE */
|
||||
WITH RECURSIVE mentors AS(
|
||||
SELECT id, name, mentor
|
||||
FROM demo.supers
|
||||
WHERE name = 'Robin/Nightwing'
|
||||
UNION
|
||||
SELECT s.id, s.name, s.mentor
|
||||
FROM demo.supers AS s, mentors AS h
|
||||
WHERE s.id = h.mentor
|
||||
)
|
||||
SELECT * FROM mentors;
|
||||
|
||||
/* Temporal Table - Application Time */
|
||||
|
||||
UPDATE demo.supers
|
||||
FOR PORTION OF date_period
|
||||
FROM '2009-01-01' to '2019-12-31'
|
||||
SET type = 'H'
|
||||
WHERE id = 10
|
||||
|
||||
SELECT
|
||||
id, name, type, startDate, endDate
|
||||
FROM
|
||||
demo.supers
|
||||
WHERE
|
||||
name = 'Catwoman'
|
||||
ORDER BY
|
||||
startDate
|
|
@ -0,0 +1,28 @@
|
|||
DROP DATABASE IF EXISTS demo;
|
||||
|
||||
CREATE DATABASE demo;
|
||||
|
||||
USE demo;
|
||||
|
||||
CREATE TABLE `supers` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) NOT NULL DEFAULT '',
|
||||
`type` char(1) NOT NULL DEFAULT '',
|
||||
`rescues` int(11) NOT NULL,
|
||||
`mentor` int(11) DEFAULT NULL,
|
||||
`startDate` datetime NOT NULL,
|
||||
`endDate` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
PERIOD FOR `date_period` (`startDate`, `endDate`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `supersteams` (
|
||||
`superid` int(11) unsigned NOT NULL,
|
||||
`teamid` int(11) unsigned NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `teams` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(50) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
|||
{"paragraphs":[{"text":"%mariadb\n\n/* Temporal Table - Application Time */\n\nSELECT \n id, name, type, startDate, endDate\nFROM\n demo.supers\nWHERE \n name = 'The Punisher' \nORDER BY \n startDate","user":"anonymous","dateUpdated":"2021-02-10T17:46:20+0000","config":{"editorSetting":{"language":"sql","editOnDblClick":false,"completionKey":"TAB","completionSupport":true},"colWidth":12,"editorMode":"ace/mode/sql","fontSize":9,"results":{"0":{"graph":{"mode":"table","height":300,"optionOpen":false,"setting":{"table":{"tableGridState":{},"tableColumnTypeState":{"names":{"id":"string","name":"string","type":"string","startDate":"string","endDate":"string"},"updated":false},"tableOptionSpecHash":"[{\"name\":\"useFilter\",\"valueType\":\"boolean\",\"defaultValue\":false,\"widget\":\"checkbox\",\"description\":\"Enable filter for columns\"},{\"name\":\"showPagination\",\"valueType\":\"boolean\",\"defaultValue\":false,\"widget\":\"checkbox\",\"description\":\"Enable pagination for better navigation\"},{\"name\":\"showAggregationFooter\",\"valueType\":\"boolean\",\"defaultValue\":false,\"widget\":\"checkbox\",\"description\":\"Enable a footer for displaying aggregated values\"}]","tableOptionValue":{"useFilter":false,"showPagination":false,"showAggregationFooter":false},"updated":false,"initialized":false},"lineChart":{"rotate":{"degree":"-45"},"xLabelStatus":"default"},"stackedAreaChart":{"rotate":{"degree":"-45"},"xLabelStatus":"default"},"scatterChart":{"yAxis":{"name":"startDate","index":1,"aggr":"sum"},"group":{"name":"type","index":0,"aggr":"sum"},"xAxis":{"name":"endDate","index":2,"aggr":"sum"}},"pieChart":{},"multiBarChart":{"rotate":{"degree":"-45"},"xLabelStatus":"default"}},"keys":[],"groups":[],"values":[],"commonSetting":{}},"helium":{}}},"enabled":true},"settings":{"params":{},"forms":{}},"results":{"code":"SUCCESS","msg":[{"type":"TABLE","data":"id\tname\ttype\tstartDate\tendDate\n7\tThe Punisher\tV\t2018-01-01 00:00:00.0\t2021-01-01 00:00:00.0\n"}]},"apps":[],"jobName":"paragraph_1612979152366_-1085081086","id":"20200221-162721_22859113","dateCreated":"2021-02-10T17:45:52+0000","status":"FINISHED","progressUpdateIntervalMs":500,"focus":true,"$$hashKey":"object:22415","dateFinished":"2021-02-10T17:46:20+0000","dateStarted":"2021-02-10T17:46:20+0000"},{"text":"%mariadb\n\nUPDATE demo.supers\n FOR PORTION OF date_period\nFROM '2016-06-01' to '2017-06-01'\n SET type = 'V'\nWHERE id = 7","user":"anonymous","dateUpdated":"2021-02-10T17:45:52+0000","config":{"editorSetting":{"language":"sql","editOnDblClick":false,"completionKey":"TAB","completionSupport":true},"colWidth":12,"editorMode":"ace/mode/sql","fontSize":9,"results":{},"enabled":true},"settings":{"params":{},"forms":{}},"results":{"code":"SUCCESS","msg":[{"type":"TEXT","data":"Query executed successfully. Affected rows : 1"}]},"apps":[],"jobName":"paragraph_1612979152366_381009384","id":"20200221-212107_406003971","dateCreated":"2021-02-10T17:45:52+0000","status":"READY","errorMessage":"","progressUpdateIntervalMs":500,"$$hashKey":"object:22416"},{"text":"%mariadb\n","user":"anonymous","dateUpdated":"2021-02-10T17:45:52+0000","config":{"editorSetting":{"language":"sql","editOnDblClick":false,"completionKey":"TAB","completionSupport":true},"colWidth":12,"editorMode":"ace/mode/sql","fontSize":9,"results":{},"enabled":true},"settings":{"params":{},"forms":{}},"apps":[],"jobName":"paragraph_1612979152366_-2022099143","id":"20200225-005425_624048741","dateCreated":"2021-02-10T17:45:52+0000","status":"READY","errorMessage":"","progressUpdateIntervalMs":500,"$$hashKey":"object:22417"}],"name":"Super Demo 3","id":"2FYDB43HF","noteParams":{},"noteForms":{},"angularObjects":{"jdbc:shared_process":[],"mariadb:shared_process":[],"spark:shared_process":[]},"config":{"isZeppelinNotebookCronEnable":false,"looknfeel":"default","personalizedMode":"false"},"info":{}}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
|||
{"paragraphs":[{"text":"%mariadb\n\n/* Temporal Table - Application Time */\n\nSELECT \n id, name, type, startDate, endDate\nFROM\n demo.supers\nWHERE \n name = 'Catwoman' \nORDER BY \n startDate","user":"anonymous","dateUpdated":"2021-02-11T16:43:05+0000","config":{"colWidth":12,"fontSize":9,"enabled":true,"results":{"0":{"graph":{"mode":"table","height":300,"optionOpen":false,"setting":{"table":{"tableGridState":{},"tableColumnTypeState":{"names":{"id":"string","name":"string","type":"string","startDate":"string","endDate":"string"},"updated":false},"tableOptionSpecHash":"[{\"name\":\"useFilter\",\"valueType\":\"boolean\",\"defaultValue\":false,\"widget\":\"checkbox\",\"description\":\"Enable filter for columns\"},{\"name\":\"showPagination\",\"valueType\":\"boolean\",\"defaultValue\":false,\"widget\":\"checkbox\",\"description\":\"Enable pagination for better navigation\"},{\"name\":\"showAggregationFooter\",\"valueType\":\"boolean\",\"defaultValue\":false,\"widget\":\"checkbox\",\"description\":\"Enable a footer for displaying aggregated values\"}]","tableOptionValue":{"useFilter":false,"showPagination":false,"showAggregationFooter":false},"updated":false,"initialized":false}},"commonSetting":{}}}},"editorSetting":{"language":"sql","editOnDblClick":false,"completionKey":"TAB","completionSupport":true},"editorMode":"ace/mode/sql"},"settings":{"params":{},"forms":{}},"results":{"code":"SUCCESS","msg":[{"type":"TABLE","data":"id\tname\ttype\tstartDate\tendDate\n11\tCatwoman\tV\t1998-01-01 00:00:00.0\t2009-01-01 00:00:00.0\n10\tCatwoman\tH\t2009-01-01 00:00:00.0\t2019-12-31 00:00:00.0\n12\tCatwoman\tV\t2019-12-31 00:00:00.0\t2021-02-17 00:00:00.0\n"}]},"apps":[],"jobName":"paragraph_1613061418475_-217930732","id":"20210211-163658_108226562","dateCreated":"2021-02-11T16:36:58+0000","dateStarted":"2021-02-11T16:43:05+0000","dateFinished":"2021-02-11T16:43:05+0000","status":"FINISHED","progressUpdateIntervalMs":500,"focus":true,"$$hashKey":"object:9853"},{"text":"%mariadb\n\nUPDATE demo.supers\n FOR PORTION OF date_period\nFROM '2009-01-01' to '2019-12-31'\n SET type = 'H'\nWHERE id = 10\n","user":"anonymous","dateUpdated":"2021-02-11T16:43:00+0000","config":{"colWidth":12,"fontSize":9,"enabled":true,"results":{},"editorSetting":{"language":"sql","editOnDblClick":false,"completionKey":"TAB","completionSupport":true},"editorMode":"ace/mode/sql"},"settings":{"params":{},"forms":{}},"results":{"code":"SUCCESS","msg":[{"type":"TEXT","data":"Query executed successfully. Affected rows : 1"}]},"apps":[],"jobName":"paragraph_1613061444335_-812742646","id":"20210211-163724_1830642047","dateCreated":"2021-02-11T16:37:24+0000","dateStarted":"2021-02-11T16:43:00+0000","dateFinished":"2021-02-11T16:43:00+0000","status":"FINISHED","progressUpdateIntervalMs":500,"$$hashKey":"object:9854"},{"text":"%mariadb\n","user":"anonymous","dateUpdated":"2021-02-11T16:39:06+0000","config":{"colWidth":12,"fontSize":9,"enabled":true,"results":{},"editorSetting":{"language":"sql","editOnDblClick":false,"completionKey":"TAB","completionSupport":true},"editorMode":"ace/mode/sql"},"settings":{"params":{},"forms":{}},"apps":[],"jobName":"paragraph_1613061546689_-155980516","id":"20210211-163906_362364857","dateCreated":"2021-02-11T16:39:06+0000","status":"READY","progressUpdateIntervalMs":500,"$$hashKey":"object:9855"}],"name":"Demo 3","id":"2FYFPQNE2","noteParams":{},"noteForms":{},"angularObjects":{"jdbc:shared_process":[],"mariadb:shared_process":[],"spark:shared_process":[]},"config":{"isZeppelinNotebookCronEnable":false,"looknfeel":"default","personalizedMode":"false"},"info":{}}
|
Ładowanie…
Reference in New Issue