Skip to content

Commit

Permalink
Merge pull request #4242 from szarnyasg/landing-page-queries
Browse files Browse the repository at this point in the history
Rework queries on the landing page
  • Loading branch information
szarnyasg authored Dec 4, 2024
2 parents 28f10bd + fa9353c commit d953e3e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 27 deletions.
26 changes: 13 additions & 13 deletions _includes/landing-page/java/appender.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Using the appender for bulk inserts
DuckDBConnection conn = (DuckDBConnection) DriverManager.getConnection("jdbc:duckdb:");
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE person (first_name VARCHAR, last_name VARCHAR, age INT)");
// Perform bulk inserts using the Appender API
DuckDBConnection conn = (DuckDBConnection)
DriverManager.getConnection("jdbc:duckdb:");
Statement st = conn.createStatement();
st.execute("CREATE TABLE person (name VARCHAR, age INT)");

try (var appender = conn.createAppender(
DuckDBConnection.DEFAULT_SCHEMA, "tbl"
)) {
appender.beginRow();
appender.append("John");
appender.append("Smith");
appender.append(42);
appender.endRow();
}
var appender = conn.createAppender(
DuckDBConnection.DEFAULT_SCHEMA, "person");

appender.beginRow();
appender.append("MC Ducky");
appender.append(49);
appender.endRow();
appender.close();
17 changes: 7 additions & 10 deletions _includes/landing-page/java/sql-query.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// Get a list of train stations by traffic
Connection conn =
DriverManager.getConnection("jdbc:duckdb:");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(
"SELECT station_name, count(*) AS num_services\n" +
"FROM train_services\n" +
"GROUP BY ALL\n" +
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(
"SELECT station_name, count(*) AS num_services\n" +
"FROM train_services\n" +
"GROUP BY ALL\n" +
"ORDER BY num_services DESC;");

while (rs.next()) {
System.out.println(rs.getString(1));
System.out.println(rs.getInt(2));
}

System.out.println(rs.next());
4 changes: 3 additions & 1 deletion _includes/landing-page/sql/aggregation-full.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ CREATE TABLE train_services AS
FROM 's3://duckdb-blobs/train_services.parquet';

-- Get the top-3 busiest train stations
SELECT station_name, count(*) AS num_services
SELECT
station_name,
count(*) AS num_services
FROM train_services
GROUP BY ALL
ORDER BY num_services DESC
Expand Down
4 changes: 3 additions & 1 deletion _includes/landing-page/sql/aggregation.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- Get the top-3 busiest train stations
SELECT station_name, count(*) AS num_services
SELECT
station_name,
count(*) AS num_services
FROM train_services
GROUP BY ALL
ORDER BY num_services DESC
Expand Down
3 changes: 2 additions & 1 deletion _includes/landing-page/sql/csv-loader.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- Load CSV file, auto-detecting column name and types
-- Load CSV file to a table. DuckDB auto-detects
-- the CSV's format, column name and types
CREATE TABLE stations AS
FROM 's3://duckdb-blobs/stations.csv';
4 changes: 3 additions & 1 deletion _includes/landing-page/sql/s3-parquet.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- Directly query Parquet file in S3
SELECT station_name, count(*) AS num_services
SELECT
station,
count(*) AS num_services
FROM 's3://duckdb-blobs/train_services.parquet'
GROUP BY ALL
ORDER BY num_services DESC
Expand Down

0 comments on commit d953e3e

Please sign in to comment.