HPCC JDBC Driver. Boca Raton Documentation Team

Similar documents
The HPCC JAVA APIs Project. Boca Raton Documentation Team

HPCC Preflight and Certification. Boca Raton Documentation Team

HPCC Preflight and Certification. Boca Raton Documentation Team

Relational Database Management Systems for Epidemiologists: SQL Part II

Relational Database Management Systems for Epidemiologists: SQL Part I

Data Manipulation Language (DML)

CSC Web Programming. Introduction to SQL

SQL functions fit into two broad categories: Data definition language Data manipulation language

The ECL Scheduler. Boca Raton Documentation Team

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

Chapter 16: Databases

SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS. The foundation of good database design

SQL Aggregate Functions

INTERMEDIATE SQL GOING BEYOND THE SELECT. Created by Brian Duffey

Dynamic ESDL. Boca Raton Documentation Team

Roxie: The Rapid Data Delivery Engine. Boca Raton Documentation Team

HPCC Monitoring and Reporting (Technical Preview) Boca Raton Documentation Team

Chapter # 7 Introduction to Structured Query Language (SQL) Part II

The ECL Scheduler. Boca Raton Documentation Team

Dynamic ESDL. Boca Raton Documentation Team

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

SQL Server Administration Class 4 of 4. Activant Prophet 21. Basic Data Manipulation

Databases (MariaDB/MySQL) CS401, Fall 2015

Dynamic ESDL. Boca Raton Documentation Team

NCSS: Databases and SQL

Principles of Data Management

1) Introduction to SQL

SQL BASICS WITH THE SMALLBANKDB STEFANO GRAZIOLI & MIKE MORRIS

Six Degrees of Kevin Bacon. Boca Raton Documentation Team

SELECT WHERE JOIN. DBMS - Select. Robert Lowe. Division of Mathematics and Computer Science Maryville College. February 16, 2016

HPCC / Spark Integration. Boca Raton Documentation Team

CSE 344 Introduction to Data Management. Section 2: More SQL


Using ECL Watch. Boca Raton Documentation Team

COSC344 Database Theory and Applications. Lecture 6 SQL Data Manipulation Language (1)

Database Management Systems,

Activant Solutions Inc. SQL 2005: Basic Data Manipulation

CSCI/CMPE Object-Oriented Programming in Java JDBC. Dongchul Kim. Department of Computer Science University of Texas Rio Grande Valley

Databases and MySQL. COMP 342: Programming Methods. 16 September Databases and MySQL

SQL Data Manipulation Language. Lecture 5. Introduction to SQL language. Last updated: December 10, 2014

tablename ORDER BY column ASC tablename ORDER BY column DESC sortingorder, } The WHERE and ORDER BY clauses can be combined in one

STRUCTURED QUERY LANGUAGE (SQL)

SQL - Subqueries and. Schema. Chapter 3.4 V4.0. Napier University

MySQL Workshop. Scott D. Anderson

Exact Numeric Data Types

3/3/2008. Announcements. A Table with a View (continued) Fields (Attributes) and Primary Keys. Video. Keys Primary & Foreign Primary/Foreign Key

SQL. SQL Functions. SQL Aggregate Functions. SQL Scalar functions. SQL Aggregate Functions. The AVG() Function

Visualizing ECL Results. Boca Raton Documentation Team

Advanced SQL GROUP BY Clause and Aggregate Functions Pg 1

Unit Assessment Guide

Slides by: Ms. Shree Jaswal

Implementing Table Operations Using Structured Query Language (SQL) Using Multiple Operations. SQL: Structured Query Language

Running HPCC in a Virtual Machine. Boca Raton Documentation Team

Oracle Database 11g: SQL and PL/SQL Fundamentals

Insertions, Deletions, and Updates

Lecture 06. Fall 2018 Borough of Manhattan Community College

Structured Query Language: Introduction

Introduction to SQL. From Rob and Coronel (2004), Database Systems: Design, Implementation, and Management

CGS 3066: Spring 2017 SQL Reference

How to use SQL to work with a MySQL database

Java Persistence Query Language (JPQL)

HPCC Monitoring and Reporting (Technical Preview) Boca Raton Documentation Team

Appendix A. Using DML to Modify Data. Contents: Lesson 1: Adding Data to Tables A-3. Lesson 2: Modifying and Removing Data A-8

1Z Oracle Database 11g - SQL Fundamentals I Exam Summary Syllabus Questions

SQL Part 2. Kathleen Durant PhD Northeastern University CS3200 Lesson 6

Model Question Paper. Credits: 4 Marks: 140

Computing for Medicine (C4M) Seminar 3: Databases. Michelle Craig Associate Professor, Teaching Stream

G64DBS Database Systems. Lecture 7 SQL SELECT. The Data Dictionary. Data Dictionaries. Different Sections of SQL (DDL) Different Sections of SQL (DCL)

12. MS Access Tables, Relationships, and Queries

Java application using JDBC to connect to a database.

Review. Objec,ves. Example Students Table. Database Overview 3/8/17. PostgreSQL DB Elas,csearch. Databases

Database design process

Database Technology. Topic 3: SQL. Olaf Hartig.

13 Creation and Manipulation of Tables and Databases

Import & Export Utilities

In This Lecture. Yet More SQL SELECT ORDER BY. SQL SELECT Overview. ORDER BY Example. ORDER BY Example. Yet more SQL

Outline. Introduction to SQL. What happens when you run an SQL query? There are 6 possible clauses in a select statement. Tara Murphy and James Curran

Introduction to SQL. Tara Murphy and James Curran. 15th April, 2009

30. Structured Query Language (SQL)

Unit 1 - Chapter 4,5

Working with DB2 Data Using SQL and XQuery Answers

Chapter 6. SQL Data Manipulation

MySQL 8.0 What s New in the Optimizer

The SQL Guide to Pervasive PSQL. Rick F. van der Lans

Querying Data with Transact SQL

Database Management Systems. Chapter 5

RDBMS-Day3. SQL Basic DDL statements DML statements Aggregate functions

Web Security. Attacks on Servers 11/6/2017 1

Tables From Existing Tables

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

CMP-3440 Database Systems

Based on the following Table(s), Write down the queries as indicated: 1. Write an SQL query to insert a new row in table Dept with values: 4, Prog, MO

Pro JPA 2. Mastering the Java Persistence API. Apress* Mike Keith and Merrick Schnicariol

Follow these steps to get started: o Launch MS Access from your start menu. The MS Access startup panel is displayed:

Stat Wk 3. Stat 342 Notes. Week 3, Page 1 / 71

Sql Server Syllabus. Overview

MIS2502: Data Analytics SQL Getting Information Out of a Database. Jing Gong

Lesson 2. Data Manipulation Language

ASSIGNMENT NO Computer System with Open Source Operating System. 2. Mysql

COMP 244 DATABASE CONCEPTS & APPLICATIONS

Transcription:

Boca Raton Documentation Team

HPCC JDBC Driver Boca Raton Documentation Team We welcome your comments and feedback about this document via email to <docfeedback@hpccsystems.com> Please include Documentation Feedback in the subject line and reference the document name, page numbers, and current Version Number in the text of the message. LexisNexis and the Knowledge Burst logo are registered trademarks of Reed Elsevier Properties Inc., used under license. Other products, logos, and services may be trademarks or registered trademarks of their respective companies. All names and example data used in this manual are fictitious. Any similarity to actual persons, living or dead, is purely coincidental. 2

Introduction... 4 Installation... 5 Configuration... 6 Using HPCC as a JDBC data source... 7 Index Annotations... 7 Supported SQL... 9 CALL... 9 SELECT... 10 SELECT JOIN... 12 Supported Aggregate Functions... 14 Java Example... 15 3

Introduction Introduction Java Database Connectivity (JDBC) is a standard Java API that enables Java applications or client tools that support JDBC to access data from a presumably SQL-compliant data source via the SQL language. JDBC makes it possible to write a single database application that can run on different platforms and interact with different database management systems. Currently there are JDBC Drivers available for interaction with many popular data sources; now the HPCC platform is available as a data source. The HPCC JDBC Driver exposes HPCC logical files as RDB tables. HPCC Logical File <-> RDB Table HPCC Record Definition Fields <-> RDB Table Columns HPCC Published query <-> RDB Stored Procedure Provides HPCC system and data RDB metadata Supports subset of SQL syntax Read only operations supported Non transactional Provides means for utilizing HPCC index files for faster reads. Figure 1. An example SQL Client interface connected to an HPCC Platform with the JDBC driver 4

Installation Installation The HPCC JDBC driver is distributed in a self-contained JAVA jar file. Follow the instructions for your SQL client for installation. To utilize your HPCC platform, use the configuration settings in the next section. The manner in which you define these settings is dependent on your SQL client. The driver's full class path is: org.hpccsystems.jdbcdriver.hpccdriver 5

Configuration Configuration The HPCC JDBC driver supports the following configuration attributes: Property Description Default Value Req. ServerAddress Target HPCC address localhost Yes WsECLWatchAddress Target HPCC WsECLWatch address ServerAddress Value WsECLWatchPort Target HPCC WsECLWatch port 8010 No WsECLAddress Target HPCC WsECL Address ServerAddress Value WsECLPort Target HPCC WsECL port 8002 No WsECLDirectAddress Target HPCC WsECLDirectAddress ServerAddress Value WsECLDirectPort Target HPCC WsECLDirect port 8010 No Username User name on Target HPCC, if needed No Password Password on Target HPCC, if needed No PageSize ConnectTimeoutMilli Max Number of HPCC files or HPCC published queries reported as result of GetTables, or GetProcs Timeout value to establish connection to HPCC (in milliseconds) No No No 100 No 1000 No ReadTimeoutMilli HPCC Connection read timeout value (in milliseconds) 1500 No EclResultLimit LazyLoad Max result records returned (use ALL to return all records) Fetch HPCC file and query metadata on-demand (not at connect time) 100 No true TargetCluster ECLDirect target cluster hthor No QuerySet Target published query (stored procedure) QuerySet hthor No TraceToFile TraceLevel When true, tracing is directed to file./hpccjdbc.log, otherwise trace is sent to standard output (stdout) Trace Logging level, as defined in java.util.logging.level. Valid values: ALL, SEVERE, WARNING, INFO, FINEST, OFF These configuration settings are used when creating an HPCC JDBC connection. "false" They can be passed to the JDBC driver using the JDBC connection URL or as part of the connection properties object. When passed through the connection URL, the values must be URL-encoded. The connection URL syntax is as follows: jdbc:hpcc[;urlencodedkey=urlencodedvalue]* INFO No No No Note: The jdbc:hpcc prefix is required. 6

Using HPCC as a JDBC data source Using HPCC as a JDBC data source Once connected, the HPCC JDBC driver will process submitted SQL statements and generate dynamic ECL code. The code is submitted to and executed by your HPCC Platform. The resultset is returned to your application or SQL client. Note: The HPCC JDBC driver only supports files which contain the record definition in the logical file s metadata. Sprayed files do not contain this metadata. This metadata exists on any file or index which is written to the HPCC Distributed File System. Sprayed data files typically undergo some processing and an OUTPUT of the transformed data to disk before use, so this should not interfere with the driver's usefulness. In addition, you can utilize indexes on the HPCC in one of two ways: 1. Provide SQL hints to tell driver to use a specific index for your query. For example: USEINDEX(TutorialPersonByZipIndex) 2. Specify the related indexes in the HPCC logical file description. Index Annotations The JDBC driver attempts to perform index based reads whenever possible. However, in order to take advantage of index reads, the target HPCC files need to be annotated with the pertinent index file names. This is accomplished by adding the following key/value entry on the file s description using ECL Watch. From a logical file s details page, enter the information in the Description entry box, then press the Save Description button. This information is used by the driver to decide if an index fetch is possible for a query on the base file. On source file: XDBC:RelIndexes= [fulllogicalfilename1; fulllogicalfilename2] Example: XDBC:RelIndexes=[tutorial::yn::peoplebyzipindex; tutorial::yn::peoplebyzipindex2; tutorial::yn::peoplebyzipindex3] In this example, the source file has three indexes available. On the index file: XDBC:PosField=[indexPositionFieldName] Example: XDBC:PosField=[fpos] 7

Using HPCC as a JDBC data source The FilePosition field (fpos) can have any name, so it must be specified in the metadata so the driver knows which field is the fileposition. Simply enter the information in the description entry box, then press the Save Description button. Note: You should enter this information BEFORE publishing any query using the data file or indexes. Published queries lock the file and would prevent editing the metadata. 8

Supported SQL CALL Supported SQL Call queryname ([param list]) queryname paramlist The published query name or alias The parameters exposed by the published query (comma-separated) Call executes a published ECL query as if it were a stored procedure. Example: Call SearchPeopleByZipService ( 33024 ) 9

Supported SQL SELECT select [distinct] colummlist from tablelist [USE INDEX(indexFileName 0 )] [where logicalexpression] [group by columnlist 1 ] [having logicalexpression 2 ] [order by columnlist 1 [asc desc] ] [LIMIT limitnumber] NOTE: Identifiers can be unquoted or within double quotes, literal string values must be single quoted. columnlist columnreference1[,columnreference2,columnreference3,...,columnreferencen] The column(s) to return (comma-separated list). In addition, these aggregate functions are supported : COUNT, SUM, MIN, MAX, and AVG. These work in a similar manner as their ECL counterparts. columnreference [tablename.]columnname[ [AS] alias ] distinct [distinct] col1, col2,... coln The result set will only contain distinct (unique) values. tablelist tableref1[,tableref2,tableref3,...,tablerefn] One or more tables, separated by commas. NOTE: A table list with multiple tables creates an (one or more) implicit inner join using the where clause logical expression as the join condition which must contain an equality condition. tableref tablename[ [AS] alias ] The Name of the table as referenced, optionally defining its alias. alias The alias used to refer to the corresponding table or field reference. logicalexpression Logical expression based on standard SQL filtering syntax. Compound operators such as NOT IN or IS NULL must be in ALL CAPS or all lower case and can have one and only one space between the words. (NOT IN, not in, IS NULL, is null, etc.) BOOLEAN Only supports True or False, do not use Y, N, 0, or 1. Valid operators: = Equal (e.g., age=33) <> Not equal (e.g., age <>33) > Greater than (e.g., age >55) < Less than (e.g., age < 18) >= Greater than or equal (e.g., age >=21) <= Less than or equal (e.g., age <=21) IN(value1,value2,...,valuen) where values are comma separated homogeneous types. 10

Supported SQL NOT IN(value1,value2,...,valuen) where values are comma separated homogeneous types. IS NULL limitnumber The number of rows to return. This overrides the driver's configuration attribute (EclResultLimit ) but cannot be set to ALL. 1 Aliasing not supported 2 Can only contain references to aggregate functions if used with having clause. Aggregate functions can only be expressed in logicalexpressions by using Group by and having Examples: Select * from tablelist where Sum(F1 > 100) /* is NOT SUPPORTED */ Select * from tablelist Group byf1 Haveing Sum (F1 > 100) /* IS SUPPORTED */ Example: Select fname, lname, state from TutorialPerson where state= FL OR (lname='smith' and fname='joe') //returns data that looks like this: John Doe FL Jim Smith FL Jane Row FL Joe Smith CA Select fname, lname, state from TutorialPerson where state= FL AND lname <> Smith //returns data that looks like this: John Doe FL Jane Row FL The driver supports SQL index hints, which gives the SQL user the option to specify the most appropriate HPCC index for the current SQL query. This also allows you to disable the use of an index. select columnlist from tablename USE INDEX(hpcc::index::file::name) where logicalexprssions USE INDEX(0) forces the system to avoid seeking an index for the current query. Example: Select fname, lname, zip, state from TutorialPerson USEINDEX(TutorialPersonByZipIndex)where zip= 33024 //returns data that looks like this: John Doe FL 33024 Jim Smith FL 33024 Jane Row FL 33024 11

Supported SQL SELECT JOIN select colummlist from tablename [as alias] [<outer inner > JOIN join TableName [ as alias] on joincondition] [USE INDEX(indexFileName 0 )] [where logicalexpression] [group by fieldname] [order by columnnames [asc desc] ] [LIMIT limitnumber] columnlist columnreference1[,columnreference2,columnreference3,...,columnreferencen] The column(s) to return (comma-separated list). In addition, these aggregate functions are supported : COUNT, SUM, MIN, MAX, and AVG. These work in a similar manner as their ECL counterparts. columnreference [tablename.]columnname[ [AS] alias ] distinct [distinct] col1, col2,... coln The result set will only contain distinct (unique) values. alias The alias used to refer to the corresponding table or field reference. outer inner The type of JOIN to use. jointablename The JOIN file to use. joincondition Specifies the relationship between columns in the joined tables using logical expression. logicalexpression Logical expression based on standard SQL filtering syntax. Compound operators such as NOT IN or IS NULL must be in ALL CAPS or all lower case and can have one and only one space between the words. (NOT IN, not in, IS NULL, is null, etc.) BOOLEAN Only supports True or False, do not use Y, N, 0, or 1. Valid operators: = Equal (e.g., age=33) <> Not equal (e.g., age <>33) > Greater than (e.g., age >55) < Less than (e.g., age < 18) >= Greater than or equal (e.g., age >=21) <= Less than or equal (e.g., age <=21) IN(value1,value2,...,valuen) where values are comma separated homogeneous types. NOT IN(value1,value2,...,valuen) where values are comma separated homogeneous types. 12

Supported SQL IS NULL limitnumber Optional. The number of rows to return. This overrides the driver's configuration attribute (EclResultLimit ) but cannot be set to ALL. 1 Aliasing not supported 2 Can only contain references to aggregate functions if used with having clause. Aggregate functions can only be expressed in logicalexpressions by using Group by and having Examples: Select * from tablelist where Sum(F1 > 100) /* is NOT SUPPORTED */ Select * from tablelist Group byf1 Having Sum (F1 > 100) /* IS SUPPORTED */ Example: Select t1.personname, t2.address from persontable as t1 inner join addresstable as t2 on (t1.personid = t2.personid AND (t1.firstname = 'jim' AND t1.lastname = 'smith' )) The JDBC driver does not convert parameter list or column list values to string literals. String values should be single quote encapsulated. Field identifier can be left unquoted or double quoted. For example, the table persons has columns Firstname(String) and Zip (numeric) Select Firstname from persons where Firstname = Jim and zip > 33445 /* works */ Select Firstname from persons where Firstname = Jim and "zip" > 33445 /* also works */ Select Firstname from persons where Firstname = Jim and zip > 33445 /* doesn t work */ Select Firstname from persons where Firstname = Jim and zip > 33445 /* doesn t work */ 13

Supported SQL Supported Aggregate Functions COUNT([DISTINCT]columnName) DISTINCT(columnName) SUM(columnName) MIN(columnName) MAX(columnName) AVG(columnName) These aggregate functions are supported. They behave as their ECL counterparts. See the ECL Language Reference for details. COUNT DISTINCT SUM MIN MAX AVG columnname Counts the occurrences of columnname in the result, always an integer. Returns only distinct values of columnname in the result, output type is dependent on input type. Returns the sum of the values of columnname in the result, output type is dependent on input type. Returns the minimum value for of columnname in the result, output type is dependent on input type. Returns the minimum value for of columnname in the result, output type is dependent on input type. Returns the average of the values of columnname in the result, always a real number. The column to aggregate. Example: Select fname, lname, state, COUNT(zip) from TutorialPerson where zip= 33024 Supported String Modifiers UPPER(columnName) LOWER(columnName) UPPER LOWER columnname Returns with all lower case characters converted to upper case. Returns with all upper case characters converted to lower case. The column to aggregate 14

Java Example Java Example /* Obtain instance of JDBC Driver */ Driver jdbcdriver = DriverManager.getDriver("jdbc:hpcc"); /* Establish Connection */ HPCCConnection connection = null; try { /*populate JAVA properties object with pertinent connection options */ Properties connprops = new Properties(); connprops.put("serveraddress", "192.168.124.128"); /*or create JDBC connection url string with pertinent connection options*/ /* the connection values must be URL-encoded */ String jdbcurl = "jdbc:hpcc;serveraddress=http%3a%2f%2f192.168.124.128"; /*provide all necessary connection properties either by URL, or props object */ connection = (HPCCConnection) driver.connect(jdbcurl, connprops); } catch (Exception e) { System.out.println("Error");} /* create HPCCStatement object for single use SQL query execution */ HPCCStatement stmt = (HPCCStatement) connection.createstatement(); /* Create your SQL query */ String mysql = "select * from tablename as mytab limit 10"; /* Execute your SQL query */ HPCCResultSet res1 = (HPCCResultSet) stmt.executequery(mysql); /*Do something with your results */ printoutresultset(res1); /* Or create a prepared statement for multiple execution and parameterization */ String myprepsql = "select * from persons_table persons where zip=? limit 100"; HPCCPreparedStatement prepstmt = (HPCCPreparedStatement)createPrepStatement(connection, myprepsql); /* provide parameter values and execute */ for (int i = 33445; i < 33448; i++) { prepstmt.clearparameters(); prepstmt.setstring(1, "'" + Integer.toString(i, 10) + "'"); HPCCResultSet qrs = (HPCCResultSet) ((HPCCPreparedStatement) prepstmt).executequery(); /*Do something with your results */ printoutresultset(qrs); } More code samples are available from: https://github.com/hpcc-systems/hpcc-jdbc/tree/master/src/test/java/org/hpccsystems/jdbcdriver/tests 15