This document discusses using SQL to access web APIs. It provides examples of popular APIs that support SQL functionality, like Google BigQuery, Salesforce, and Couchbase. The benefits of using SQL for API access are described, including ease of integration, leveraging existing tools, and handling related data. Integration challenges from inconsistent SQL support across APIs are also noted. The document introduces using standard database drivers to provide uniform SQL access to APIs. A case study describes how Bouqet.ai uses this approach to map natural language queries to SQL for accessing SaaS data.
Displacement, Velocity, Acceleration, and Second Derivatives
SQL for Web APIs - Simplifying Data Access for API Consumers
1. www.cdata.com
See the World as a Database
SQL for Web APIs
Simplifying Data Access for API Consumers
Jerod Johnson, Technology Evangelist
@jeRodimusPrime
@cdatasoftware
2. www.cdata.com
1. Popular APIs with SQL Endpoints
2. Why SQL?
3. Integration Challenges
4. Standard Drivers
5. Case Study: Bouqet.ai
Agenda
4. www.cdata.com
Google BigQuery – Standard SQL
Standard SQL
• Adheres to the SQL 2011 standard
• WITH clauses and SQL functions
• Subqueries (in SELECT and WHERE)
• ARRAY and STRUCT types
• Inserts, updates, and deletes
• JOINs
Popular APIs with SQL Functionality
Python Example:
# from google.cloud import bigquery
# client = bigquery.Client()
query = (
"SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` "
'WHERE state = "TX" '
"LIMIT 100"
)
query_job = client.query(
query,
# Location must match that of the dataset(s) referenced in the query.
location="US",
) # API request - starts the query
for row in query_job: # API request - fetches results
# Row values can be accessed by field name or index
assert row[0] == row.name == row["name"]
print(row)
5. www.cdata.com
Salesforce – SOQL & SOSL
Salesforce Object Query Language
• Provides SQL-like access to
Salesforce objects
• Format
SELECT one or more fields
FROM an object
WHERE filter statements/ordering
JavaScript query Example:
Popular APIs with SQL Functionality
Salesforce Object Search Language
• Provides text-based searching of
Salesforce objects
• Format
FIND SeachQuery
IN SearchGroup
JavaScript search Example:
var result = sforce.connection.query(
"Select Name, Id from User");
records = result.getArray("records");
for (var i=0; i < records.length; i++) {
var record = records[i];
log(record.Name + " -- " + record.Id);
}
var result = sforce.connection.search(
"FIND {jane} IN NAME FIELDS RETURNING Account(name, id)");
if (result) {
var records = result.getArray("searchRecords");
for (var i=0; i < records.length; i++) {
var record = records[i].record;
log(record.Id + " -- " + record.Name);
}
}
6. www.cdata.com
Couchbase – N1QL & SQL++
• Both provide SQL-like syntax for
JSON documents for different
Couchbase services
• Format
SELECT one or more fields
FROM a document
WHERE filter statements/ordering
• Dot notation to “drill down”
• Returns a JSON document
Popular APIs with SQL Functionality
Node.js N1qlQuery Example
var N1qlQuery = couchbase.N1qlQuery;
query =
N1qlQuery.fromString('SELECT name, contact.email FROM default');
bucket.query(query, function(err, rows, meta) {
for (row in rows) {
console.log('Name: %s. Email: %s', row.name, row.email);
}
});
Node.js AnalyticsQuery Example
var query = couchbase.AnalyticsQuery.fromString(
"SELECT airportname, address.country" +
"FROM airports WHERE address.country=?");
bucket.query(query, ['France’], function(err, rows) {
// ...
});
7. www.cdata.com
Why SQL?
• Self-describing API: objects, fields, functions are all defined & discoverable
• Ease of integration & application development
• Simplified interfacing with popular tooling
• Leverage server-side processing
• Examples:
• Retrieve data from multiple related objects
• Retrieve parts of fields (numbers, dates, or checkboxes/flags)
• Count the number of records that meet specified criteria
• Sort results as part of the query
8. www.cdata.com
Integration Challenges
• SQL access ≠ SQL response
• SQL access is not uniform
across APIs
• Not all APIs provide SQL
access
• Roughly 2,000 new public
APIs per year
9. www.cdata.com
LEGACY TECHNOLOGY SaaS APPLICATION
2017 State of the
SaaS-Powered Workplace
Can your API Integrations Keep Up?
58% of companies are running
almost completely on SaaS.
API Challenges
10. www.cdata.com
Standard Drivers – SQL Access to SaaS
Applications
• Ubiquitous technologies like JDBC, ODBC, &
ADO.NET
• Historically used to integrate with databases
• Vendors now create drivers for SaaS applications
ADO.NET ODATAJDBCODBC
11. www.cdata.com
Modeling APIs through SQL
• Tables and views correspond with
resource collections (Orders, Accounts,
Pages, Users, etc.)
• Individual elements correspond to a row
• Sub-collection relationships are
maintained (Orders and Order Line Items)
• CRUD operations are translated to SQL
statements
• Operations and functions are
implemented with stored procedures
Standard Drivers
12. www.cdata.com
SQL-92 Compliant Queries
The easiest way to build data-centric applications. Write
standard SQL queries with support for JOINs, updates,
aggregation, and more.
SELECT Account.Id, Account.Name, Account.Fax,
Opportunity.AccountId, Opportunity.CloseDate
FROM Salesforce.Account
INNER JOIN Salesforce.Opportunity
ON Account.Id = Opportunity.AccountId
SELECT WITH INNER JOIN
UPDATE Account SET Name='John' WHERE Id = @myId
UPDATE DATA
SELECT State, AVG(AnnualRevenue) FROM Account GROUP BY State
AGGREGATE FUNCTIONS
Properties prop = new Properties();
prop.setProperty("User","myUser");
prop.setProperty("Password","myPassword");
prop.setProperty("Security Token","myToken");
Connection conn = DriverManager.getConnection("jdbc:salesforce:",prop);
Statement stat = conn.createStatement();
boolean ret = stat.execute("SELECT BillingState, Name FROM Account");
if (ret) {
ResultSet rs=stat.getResultSet();
while(rs.next()) {
for(int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
System.out.println(rs.getMetaData().getColumnName(i) +
"=" + rs.getString(i));
}
}
}
One SDK / API to Learn & Implement
Just like connecting with a typical RDBMS like SQL. Use
standard classes like Properties, Connection,
DriverManager, Statement, ResultSet, etc.
Simplify Developer Integration
Standard Drivers
13. www.cdata.com
Natural language AI platform, Aris extends data connectivity with CData and the power of SQL abstraction.
Mapping natural language queries to SQL highlights the transformative power of a SQL data
abstraction, as it would be nearly impossible to map these dynamic queries to SaaS data any
other way.
More Online: https://www.cdata.com/case-study/bouquet/
Case Study: Bouqet.ai
14. www.cdata.com
The Takeaway – SQL Benefits for ALL APIs
• SQL continues to be the “lingua franca” for data access
• API growth continues unabated
• Standard drivers offer simplified integration
• Rapid application development
• Ease of use for citizen analysts
• Insulation from API changes
Want to know more?
email: jerodj@cdata.com
Notas do Editor
As the data world evolves, businesses are moving more of their data out of databases and into SaaS applications. Despite the migration, SQL remains a ubiquitous language for data access, so much so that many SaaS applications and non-relational cloud data stores support SQL endpoints in their APIs. While these endpoints allow users to leverage SQL queries to easily request data, there are still costly challenges to overcome when it comes to processing and managing the returned data.In this session, we'll showcase popular APIs that offer SQL endpoints, explore the benefits of providing customers SQL access, and cover how standards-based drivers enable SaaS integration and self-service data access through SQL.