Skip to content

Commit 3f53057

Browse files
committed
high quality example
1 parent 3f2cfed commit 3f53057

29 files changed

Lines changed: 102 additions & 125 deletions

examples/src/main/java/com/example/ConnectionErrorExample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public void onEnd(long totalRows) {
5959

6060
@Override
6161
public void onError(byte status, String message) {
62-
System.err.printf("error: 0x%02X %s%n", status & 0xFF, message);
6362
}
6463
}).await();
6564
} catch (QueryException e) {

examples/src/main/java/com/example/QuestDBExample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public void onEnd(long totalRows) {
8989

9090
@Override
9191
public void onError(byte status, String message) {
92-
System.err.printf("error: 0x%02X %s%n", status & 0xFF, message);
9392
}
9493
}
9594
}

examples/src/main/java/com/example/QuestDBSeparateConfigExample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public void onEnd(long totalRows) {
4747

4848
@Override
4949
public void onError(byte status, String message) {
50-
System.err.printf("error: 0x%02X %s%n", status & 0xFF, message);
5150
}
5251
}).await();
5352
} catch (QueryException e) {

examples/src/main/java/com/example/query/ArrayResultExample.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
* Assumes a table with a {@code DOUBLE[]} column, e.g. the one
2222
* {@code WsArrayExample} writes:
2323
* <pre>
24-
* CREATE TABLE book (levels DOUBLE[], ts TIMESTAMP)
25-
* TIMESTAMP(ts) PARTITION BY DAY WAL;
24+
* CREATE TABLE book (levels DOUBLE[], timestamp TIMESTAMP)
25+
* TIMESTAMP(timestamp) PARTITION BY DAY WAL;
2626
* </pre>
2727
*/
2828
public class ArrayResultExample {
@@ -54,7 +54,6 @@ public void onEnd(long totalRows) {
5454

5555
@Override
5656
public void onError(byte status, String message) {
57-
System.err.printf("error: 0x%02X %s%n", status & 0xFF, message);
5857
}
5958
}
6059
).await();

examples/src/main/java/com/example/query/BasicQueryExample.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void onBatch(QwpColumnBatch batch) {
4848
double amount = row.getDoubleValue(4); // DOUBLE
4949

5050
System.out.printf(
51-
"ts=%d symbol=%s side=%s price=%.4f amount=%.5f%n",
51+
"timestamp=%d symbol=%s side=%s price=%.4f amount=%.5f%n",
5252
timestamp, symbol, side, price, amount
5353
);
5454
});
@@ -61,7 +61,6 @@ public void onEnd(long totalRows) {
6161

6262
@Override
6363
public void onError(byte status, String message) {
64-
System.err.println("query failed: status=" + status + " msg=" + message);
6564
}
6665
}
6766
).await();

examples/src/main/java/com/example/query/BinaryResultExample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public void onEnd(long totalRows) {
5151

5252
@Override
5353
public void onError(byte status, String message) {
54-
System.err.printf("error: 0x%02X %s%n", status & 0xFF, message);
5554
}
5655
}
5756
).await();

examples/src/main/java/com/example/query/BindAllTypesExample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ public void onEnd(long totalRows) {
120120

121121
@Override
122122
public void onError(byte status, String message) {
123-
System.err.println("query failed: status=" + status + " msg=" + message);
124123
}
125124
})
126125
.submit()

examples/src/main/java/com/example/query/BindDecimalExample.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public void onEnd(long totalRows) {
103103

104104
@Override
105105
public void onError(byte status, String message) {
106-
System.err.println("query failed: " + message);
107106
}
108107
})
109108
.submit()
@@ -131,7 +130,6 @@ public void onEnd(long totalRows) {
131130

132131
@Override
133132
public void onError(byte status, String message) {
134-
System.err.println("query failed: " + message);
135133
}
136134
})
137135
.submit()
@@ -156,7 +154,6 @@ public void onEnd(long totalRows) {
156154

157155
@Override
158156
public void onError(byte status, String message) {
159-
System.err.println(" query failed: " + message);
160157
}
161158
};
162159
}

examples/src/main/java/com/example/query/BindNullExample.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public void onEnd(long totalRows) {
7272

7373
@Override
7474
public void onError(byte status, String message) {
75-
System.err.println(" query failed: " + message);
7675
}
7776
})
7877
.submit()
@@ -100,7 +99,6 @@ public void onEnd(long totalRows) {
10099

101100
@Override
102101
public void onError(byte status, String message) {
103-
System.err.println(" query failed: " + message);
104102
}
105103
})
106104
.submit()
@@ -126,7 +124,6 @@ public void onEnd(long totalRows) {
126124

127125
@Override
128126
public void onError(byte status, String message) {
129-
System.err.println(" query failed: " + message);
130127
}
131128
};
132129
}

examples/src/main/java/com/example/query/BindParametersExample.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@
1515
* keyed factory cache hits on every repeated call because the SQL text is
1616
* identical.
1717
* <p>
18-
* Assumes a table exists:
18+
* Assumes the {@code trades} table the ingest examples write:
1919
* <pre>
20-
* CREATE TABLE trades (ts TIMESTAMP, sym SYMBOL, price DOUBLE, qty LONG)
21-
* TIMESTAMP(ts) PARTITION BY DAY WAL;
20+
* CREATE TABLE trades (
21+
* symbol SYMBOL, side SYMBOL, price DOUBLE, amount DOUBLE, timestamp TIMESTAMP
22+
* ) TIMESTAMP(timestamp) PARTITION BY DAY WAL;
2223
* </pre>
2324
*/
2425
public class BindParametersExample {
2526

2627
public static void main(String[] args) throws InterruptedException {
2728
try (QuestDB db = QuestDB.connect("ws::addr=localhost:9000;")) {
2829

29-
String sql = "SELECT ts, sym, price, qty FROM trades "
30-
+ "WHERE sym = $1 AND price >= $2 AND ts >= $3 LIMIT 1000";
30+
String sql = "SELECT timestamp, symbol, price, amount FROM trades "
31+
+ "WHERE symbol = $1 AND price >= $2 AND timestamp >= $3 LIMIT 1000";
3132

3233
// Same SQL, three different parameter sets. Each call reuses the
3334
// compiled factory on the server side because the text is identical.
34-
String[] symbols = {"AAPL", "MSFT", "GOOG"};
35+
String[] symbols = {"ETH-USD", "BTC-USD", "SOL-USD"};
3536
for (String symbol : symbols) {
3637
System.out.println("fetching trades for " + symbol);
3738
try {
@@ -55,11 +56,11 @@ private static final class PrintingHandler implements QwpColumnBatchHandler {
5556
@Override
5657
public void onBatch(QwpColumnBatch batch) {
5758
batch.forEachRow(row -> System.out.printf(
58-
"ts=%d sym=%s price=%.4f qty=%d%n",
59+
"timestamp=%d symbol=%s price=%.4f amount=%.5f%n",
5960
row.getLongValue(0),
6061
row.getSymbol(1),
6162
row.getDoubleValue(2),
62-
row.getLongValue(3)
63+
row.getDoubleValue(3)
6364
));
6465
}
6566

@@ -70,7 +71,6 @@ public void onEnd(long totalRows) {
7071

7172
@Override
7273
public void onError(byte status, String message) {
73-
System.err.println("query failed: status=" + status + " msg=" + message);
7474
}
7575
}
7676
}

0 commit comments

Comments
 (0)