Last active
November 17, 2021 17:18
-
-
Save mneedham/131041d61fd16ef8eb48e7ad8c465275 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//DEPS org.apache.pinot:pinot-jdbc-client:0.8.0 | |
//DEPS com.github.freva:ascii-table:1.2.0 | |
// jbang Query.java "select * from customers limit 5" | |
// export JDBC_URL="jdbc:pinot://localhost:9000" | |
import static java.lang.System.*; | |
import java.sql.*; | |
import java.util.*; | |
import com.github.freva.asciitable.*; | |
public class Query { | |
public static void main(String... args) throws Exception { | |
try (var con=DriverManager.getConnection("jdbc:pinot://localhost:9000"); | |
var stmt=con.createStatement(); | |
var rs=stmt.executeQuery(String.join(" ",args))) { | |
var meta=rs.getMetaData(); | |
var cols=new String[meta.getColumnCount()]; | |
for (int c=1;c<=cols.length;c++) | |
cols[c-1]=meta.getColumnName(c); | |
int row=0; | |
String[][] rows=new String[100][]; | |
while (rs.next() || row>=rows.length) { | |
rows[row]=new String[cols.length]; | |
for (int c=1;c<=cols.length;c++) | |
rows[row][c-1]=rs.getString(c); | |
row++; | |
} | |
out.println(AsciiTable.getTable(cols, Arrays.copyOf(rows,row))); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//DEPS org.apache.pinot:pinot-jdbc-client:0.8.0 | |
//DEPS com.github.freva:ascii-table:1.2.0 | |
//DEPS org.apache.commons:commons-lang3:3.0 | |
// jbang Query.java "select * from customers limit 5" | |
// export JDBC_URL="jdbc:pinot://localhost:9000" | |
import static java.lang.System.*; | |
import java.sql.*; | |
import java.util.*; | |
import com.github.freva.asciitable.*; | |
public class Query2 { | |
public static void main(String... args) throws Exception { | |
try (var con=DriverManager.getConnection("jdbc:pinot://localhost:9000"); | |
var stmt=con.createStatement(); | |
var rs=stmt.executeQuery(String.join(" ",args))) { | |
var meta=rs.getMetaData(); | |
var cols=new String[meta.getColumnCount()]; | |
for (int c=1;c<=cols.length;c++) | |
cols[c-1]=meta.getColumnName(c); | |
int row=0; | |
String[][] rows=new String[100][]; | |
while (rs.next() || row>=rows.length) { | |
rows[row]=new String[cols.length]; | |
for (int c=1;c<=cols.length;c++) | |
rows[row][c-1]=rs.getString(c); | |
row++; | |
} | |
out.println(AsciiTable.getTable(cols, Arrays.copyOf(rows,row))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment