Skip to content

Commit 7be968f

Browse files
committed
make small improvements
1 parent 2105e55 commit 7be968f

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

fluss-client/src/main/java/org/apache/fluss/client/table/scanner/Scan.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public interface Scan {
6565
*/
6666
LogScanner createLogScanner();
6767

68+
/**
69+
* Creates a {@link BatchScanner} to read current data in the given table.
70+
*
71+
* <p>Note: this API doesn't support pre-configured with {@link #project}.
72+
*/
73+
BatchScanner createBatchScanner();
74+
6875
/**
6976
* Creates a {@link BatchScanner} to read current data in the given table bucket for this scan.
7077
*

fluss-client/src/main/java/org/apache/fluss/client/table/scanner/TableScan.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.fluss.metadata.TableInfo;
3636
import org.apache.fluss.metadata.TablePath;
3737
import org.apache.fluss.types.RowType;
38+
import java.util.concurrent.ExecutionException;
3839

3940
import javax.annotation.Nullable;
4041

@@ -79,7 +80,7 @@ public Scan project(List<String> projectedColumnNames) {
7980
int index = rowType.getFieldIndex(projectedColumnNames.get(i));
8081
if (index < 0) {
8182
throw new IllegalArgumentException(
82-
"Field " + projectedColumnNames.get(i) + " not found in table schema.");
83+
String.format("Field %s not found in table schema.", projectedColumnNames.get(i)));
8384
}
8485
columnIndexes[i] = index;
8586
}
@@ -119,16 +120,42 @@ public BatchScanner createBatchScanner(TableBucket tableBucket) {
119120
public BatchScanner createBatchScanner(TableBucket tableBucket, long snapshotId) {
120121
if (limit != null) {
121122
throw new UnsupportedOperationException(
122-
"Currently, SnapshotBatchScanner doesn't support limit pushdown.");
123+
String.format(
124+
"SnapshotBatchScanner does not support limit pushdown. Received limit=%s. Remove limit() from the scan or use createBatchScanner(TableBucket) for limited reads.",
125+
limit));
126+
}
127+
if (!tableInfo.hasPrimaryKey()) {
128+
throw new UnsupportedOperationException(
129+
String.format(
130+
"Snapshot-based batch scanning is only supported for Primary Key tables. Table %s does not have a primary key.",
131+
tableInfo.getTablePath()));
123132
}
124133
String scannerTmpDir =
125134
conn.getConfiguration().getString(ConfigOptions.CLIENT_SCANNER_IO_TMP_DIR);
126135
Admin admin = conn.getAdmin();
127136
final KvSnapshotMetadata snapshotMeta;
128137
try {
129138
snapshotMeta = admin.getKvSnapshotMetadata(tableBucket, snapshotId).get();
139+
} catch (InterruptedException ie) {
140+
Thread.currentThread().interrupt();
141+
throw new FlussRuntimeException(
142+
String.format(
143+
"Interrupted while fetching snapshot metadata for table %s, %s, snapshotId=%d",
144+
tableInfo.getTablePath(), tableBucket, snapshotId),
145+
ie);
146+
} catch (ExecutionException ee) {
147+
Throwable cause = ee.getCause() == null ? ee : ee.getCause();
148+
throw new FlussRuntimeException(
149+
String.format(
150+
"Failed to get snapshot metadata for table %s, %s, snapshotId=%d: %s",
151+
tableInfo.getTablePath(), tableBucket, snapshotId, cause.getMessage()),
152+
cause);
130153
} catch (Exception e) {
131-
throw new FlussRuntimeException("Failed to get snapshot metadata", e);
154+
throw new FlussRuntimeException(
155+
String.format(
156+
"Unexpected error while getting snapshot metadata for table %s, %s, snapshotId=%d",
157+
tableInfo.getTablePath(), tableBucket, snapshotId),
158+
e);
132159
}
133160

134161
return new KvSnapshotBatchScanner(
@@ -170,7 +197,10 @@ public BatchScanner createBatchScanner(String partitionName) {
170197
}
171198
Long pid = conn.getMetadataUpdater().getPartitionId(physical).orElse(null);
172199
if (pid == null) {
173-
throw new IllegalStateException("Partition id not found for " + partitionName);
200+
throw new IllegalStateException(
201+
String.format(
202+
"Partition ID not found for partition '%s' in table %s. Metadata may be stale. Try refreshing metadata and ensure the partition exists.",
203+
partitionName, tableInfo.getTablePath()));
174204
}
175205
return new FullScanBatchScanner(tableInfo, conn.getMetadataUpdater(), pid);
176206
}
@@ -202,7 +232,7 @@ public BatchScanner createFullScanBatchScanner(String partitionName) {
202232
}
203233
Long pid = conn.getMetadataUpdater().getPartitionId(physical).orElse(null);
204234
if (pid == null) {
205-
throw new IllegalStateException("Partition id not found for " + partitionName);
235+
throw new IllegalStateException(String.format("Partition id not found for %s", partitionName));
206236
}
207237
return new FullScanBatchScanner(tableInfo, conn.getMetadataUpdater(), pid);
208238
}

0 commit comments

Comments
 (0)