zy-kkk commented on code in PR #71125:
URL: https://github.com/apache/doris/pull/71125#discussion_r4735715152


##########
fe/fe-connector/fe-connector-lance/src/main/java/org/apache/doris/connector/lance/LanceNamespaceClient.java:
##########
@@ -242,10 +244,124 @@ private CachedTableAccess 
describeTableAccess(List<String> tableId, String dbNam
         // BE through lance-c, so neither can end up with credentials the 
other lacks. The dataset URL picks
         // the option vocabulary, the same way Lance picks a provider from it.
         Map<String, String> vendedOptions = table.getStorageOptions();
-        LanceTableAccess access = new LanceTableAccess(datasetUri,
-                
LanceStorageOptions.fromDorisAndVendedStorageOptions(datasetUri, 
storageProperties, vendedOptions),
-                vendedOptions != null && !vendedOptions.isEmpty());
-        return new CachedTableAccess(access, cacheTtlNanos(access));
+        Map<String, String> storageOptions =
+                
LanceStorageOptions.fromDorisAndVendedStorageOptions(datasetUri, 
storageProperties, vendedOptions);
+        boolean vended = vendedOptions != null && !vendedOptions.isEmpty();
+        if (!Boolean.TRUE.equals(table.getManagedVersioning())) {
+            LanceTableAccess access = new LanceTableAccess(datasetUri, 
storageOptions, vended);
+            return new CachedTableAccess(access, cacheTtlNanos(access));
+        }
+        // The namespace decides which versions exist; the FE and the BE both 
read one of them by URI, which is
+        // all lance-c supports. The manifest paths the namespace records are 
object-store paths under
+        // `location`, so `table_uri` must name the same place; it may add a 
query, such as presigned
+        // credentials, which Doris then opens it with.
+        if (StringUtils.isBlank(table.getLocation())) {
+            throw new DorisConnectorException("Lance namespace returned no 
location for managed table " + tableId);
+        }
+        // An s3+ddb URI commits through DynamoDB, whose handler records and 
finalizes versions itself, even on
+        // read; the namespace already decides the versions of a managed table.
+        if (StringUtils.startsWithIgnoreCase(datasetUri, "s3+ddb:")) {
+            throw new DorisConnectorException("Lance namespace returned an 
s3+ddb URI for managed table " + tableId
+                    + ", whose versions the namespace manages");
+        }
+        if (StringUtils.isNotBlank(table.getTableUri())
+                && 
!withoutQuery(table.getTableUri()).equals(withoutQuery(table.getLocation()))) {

Review Comment:
   If `table_uri` and `location` both end in `#meta`, this comparison passes. A 
read of `@branch(dev)` then appends `/tree/dev` after `#meta`, leaving the 
dataset path at the table root. I reproduced this with Lance JNI 12.0.0: dev v3 
has 7 rows and main v3 has 9. With the fragment, the connector still reports 
`dev` but reads all 9 rows from main.
   
   Could we reject fragments on the resolved managed table URI, as branch-4.2 
does in #69384, and add a test where both fields contain the same fragment?



##########
fe/fe-connector/fe-connector-lance/src/main/java/org/apache/doris/connector/lance/LanceScanPlanProvider.java:
##########
@@ -402,17 +413,17 @@ public LanceTableMetadata metadata(ConnectorSession 
session, ConnectorTableHandl
                 LanceMetadataMetrics metrics) {
             LanceTableHandle table = lanceHandle(handle);
             return LanceStatementScope.sharedMetadata(session, table,
-                    () -> client.loadTableMetadata(table.getDbName(), 
table.getTableName(), table.getVersion(),
-                            metrics));
+                    () -> client.loadTableMetadata(table.getDbName(), 
table.getTableName(),
+                            LanceRefSelector.of(table), metrics));
         }
 
         @Override
         public LanceIndexMetadata indexMetadata(ConnectorSession session, 
ConnectorTableHandle handle,
                 LanceTableMetadata metadata, LanceMetadataMetrics metrics) {
             LanceTableHandle table = lanceHandle(handle);
             return LanceStatementScope.sharedIndexMetadata(session, table, 
metadata,
-                    () -> client.loadIndexMetadata(table.getDbName(), 
table.getTableName(), metadata.getVersion(),
-                            metrics));
+                    () -> client.loadIndexMetadata(table.getDbName(), 
table.getTableName(), metadata.getBranch(),

Review Comment:
   `loadIndexMetadata` looks the table up by name again after the scan has 
pinned its dataset. I reproduced this with two datasets, A and B, both at v3 
with different BTREE index UUIDs. After the scan pinned A, I switched the 
namespace location to B. With `row_id = 5` pushed down, `planScan` produced a 
range with A’s dataset URI and B’s index UUID. On branch-4.2 the same test 
loads A’s index with a single `DescribeTable` call.
   
   Could we pass the `LanceTableAccess` already held by `LanceTableMetadata` 
into the index loader and open that URI at the pinned version? That keeps index 
loading lazy and ensures the index and fragments come from the same dataset.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to