Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spatial analytics demo #37

Merged
merged 1 commit into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions spatial/README_spatial_samples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
README file for Db2 Spatial Analytics Samples

*
*
* (C) COPYRIGHT INTERNATIONAL BUSINESS MACHINES CORPORATION 2000, 2021.
*
ALL RIGHTS RESERVED.
*


File: samples/spatial/README_spatial_samples.txt

The Db2 Spatial Analytics samples consist of one demo program.
- One sample is based on banking (branches, customers, employees).
This banking demo is written in SQL scripts run by the command-line
processor (CLP).
This file briefly introduces the demo and indicates where to look for
further information.


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
The Banking Demo is implemented in SQL scripts that are run with the Db2
command line processor. You can use the demo and scripts as a tutorial.
The scripts and README file "saBankDemoREADME.txt" are located in the
"bank" subdirectory (sqllib/extenders/samples/spatial/bank).
The following excerpt from that file gives an introduction to the demo:
*****************************************************************************
Banking Customer Analysis Sample

This demo illustrates adding a spatial dimension to an existing
information system. The existing system did not contain any explicit
location (spatial) data. However, the existing system did contain implicit
location data in the form of addresses. By spatially enabling the existing
database, the user expands the business analysis capabilities of the system.

A bank that has customers with accounts at two branches needs to use the
spatial attribute of the existing data along with census demographic data
to perform various kinds of spatial analysis. The analysis consists of
comparing customer, branch, and demographic data, as well as profiling
customers and doing market analysis. The bank looks for prospective
customers by finding average balances for customers within three miles of
the branch, determining what areas the primary customers live in, and
searching for similar areas.

Note: Although this demo focuses on a banking application, it is equally
applicable to different businesses such as retail, insurance, and so on.
*****************************************************************************

For UNIX, the Banking Demo is driven by a Korn shell script called
"saBankDemoRunBankDemo". To display usage information, enter
saBankDemoRunBankDemo -h

For Windows, the Banking Demo is driven by a batch file which is TBD.

Before you run the demo, look at the "saBankDemoREADME.txt" file. This
README file describes the prerequisites and explains how to run the demo.

After the Banking Demo runs, the complete record of its actions can be found
in the file "sa_bank.log" which is in the "tmp", subdirectory under the home
directory of the user who ran the demo.

98 changes: 98 additions & 0 deletions spatial/bank/saBankDemoDDL.db2
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
----------------------------------------------------------------------------
-- Licensed Materials - Property of IBM
-- Governed under the terms of the IBM Public License
--
-- (C) COPYRIGHT International Business Machines Corp. 2000 - 2021
-- All Rights Reserved.
--
-- US Government Users Restricted Rights - Use, duplication or
-- disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
----------------------------------------------------------------------------
--
-- Component Name: Db2 Spatial Analytics
--
-- Source File Name: saBankDemoDDL.db2
--
-- Version: 11.5.6+
--
-- Description: Load non-spatial data into the sample database.
--
-- SQL STATEMENTS USED:
-- DROP TABLE
-- CREATE TABLE
--
-- The tables are created using the database default table organization.
-- Note: for column organized tables the primary keys are not enforced
-- by default.
--
-- For more information about the Db2 Spatial Analytics Bank Demo scripts,
-- see the saBankDemoREADME.txt file.
--
-- For more information about Db2 Spatial Analytics component, refer to the
-- documentation at
-- https://www.ibm.com/docs/en/db2/11.5?topic=data-db2-spatial-analytics.
--
-- For the latest information on Db2 refer to the Db2 website at
-- https://www.ibm.com/analytics/db2.
----------------------------------------------------------------------------
CREATE TABLE sa_demo.customers (
customer_id INTEGER NOT NULL
PRIMARY KEY ENFORCED,
sa_row_id INTEGER,
name VARCHAR (20),
street VARCHAR (25),
city VARCHAR (10),
state VARCHAR (2),
zip VARCHAR (5),
phone VARCHAR (20) ,
email VARCHAR (50) ,
customer_type VARCHAR (10) ,
date_billed DATE ,
notes VARCHAR (100),
date_entered DATE,
latitude DOUBLE,
longitude DOUBLE
) ;

CREATE TABLE sa_demo.branches (
branch_id INTEGER NOT NULL
PRIMARY KEY ENFORCED,
sa_row_id INTEGER,
name VARCHAR (12),
manager VARCHAR (20),
street VARCHAR (20),
city VARCHAR (10),
state VARCHAR (2),
zip VARCHAR (5),
phone VARCHAR (30),
fax VARCHAR (30),
latitude DOUBLE,
longitude DOUBLE
) ;

CREATE TABLE sa_demo.accounts (
customer_id INTEGER NOT NULL,
branch_id INTEGER NOT NULL,
account_id INTEGER NOT NULL
PRIMARY KEY ENFORCED,
type VARCHAR (10) NOT NULL,
balance DECIMAL (14, 2) NOT NULL,
routing_number integer NOT NULL,
CONSTRAINT fk_branches FOREIGN KEY(branch_id)
REFERENCES sa_demo.branches(branch_id) ON DELETE CASCADE,
CONSTRAINT fk_customers FOREIGN KEY(customer_id)
REFERENCES sa_demo.customers(customer_id) ON DELETE CASCADE
) ;

CREATE TABLE sa_demo.transactions (
transaction_id INTEGER NOT NULL
PRIMARY KEY,
transaction_date DATE NOT NULL,
description VARCHAR (100),
account_id INTEGER NOT NULL ,
amount DECIMAL (14, 2) NOT NULL,
notes VARCHAR (100),
classification VARCHAR (30),
CONSTRAINT fk_accounts FOREIGN KEY(account_id)
REFERENCES sa_demo.accounts(account_id) ON DELETE CASCADE
) ;
Loading