mirror of
https://github.com/lancedb/lancedb.git
synced 2026-05-16 19:40:40 +00:00
fix: support dynamic projection on remote table (#3023)
The remote server expects an object (`{"alias": "col"}`) and the client
was previously sending a list of tuples `[["alias", "col"]]`
This commit is contained in:
@@ -423,12 +423,11 @@ impl<S: HttpSend> RemoteTable<S> {
|
||||
);
|
||||
}
|
||||
Select::Dynamic(pairs) => {
|
||||
body["columns"] = serde_json::Value::Array(
|
||||
pairs
|
||||
.iter()
|
||||
.map(|(name, expr)| serde_json::json!([name, expr]))
|
||||
.collect(),
|
||||
);
|
||||
let alias_map =
|
||||
serde_json::Map::from_iter(pairs.iter().map(|(name, expr)| {
|
||||
(name.clone(), serde_json::Value::String(expr.clone()))
|
||||
}));
|
||||
body["columns"] = alias_map.into();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3163,6 +3163,7 @@ mod tests {
|
||||
use arrow_array::{BinaryArray, LargeBinaryArray};
|
||||
use arrow_data::ArrayDataBuilder;
|
||||
use arrow_schema::{DataType, Field, Schema};
|
||||
use futures::TryStreamExt;
|
||||
use lance::dataset::WriteMode;
|
||||
use lance::io::{ObjectStoreParams, WrappingObjectStore};
|
||||
use lance::Dataset;
|
||||
@@ -3174,6 +3175,8 @@ mod tests {
|
||||
use crate::connection::ConnectBuilder;
|
||||
use crate::index::scalar::{BTreeIndexBuilder, BitmapIndexBuilder};
|
||||
use crate::index::vector::{IvfHnswPqIndexBuilder, IvfHnswSqIndexBuilder};
|
||||
use crate::query::{ExecutableQuery, QueryBase};
|
||||
use crate::test_utils::connection::new_test_connection;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_open() {
|
||||
@@ -3604,6 +3607,31 @@ mod tests {
|
||||
assert_eq!(table.list_indices().await.unwrap().len(), 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_dynamic_select() {
|
||||
let tc = new_test_connection().await.unwrap();
|
||||
let db = tc.connection;
|
||||
|
||||
let table = db
|
||||
.create_table("test", some_sample_data())
|
||||
.execute()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let query = table.query().select(Select::dynamic(&[("i_alias", "i")]));
|
||||
|
||||
let result = query.execute().await;
|
||||
let batches = result
|
||||
.expect("should have result")
|
||||
.try_collect::<Vec<_>>()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
for batch in batches {
|
||||
assert!(batch.column_by_name("i_alias").is_some());
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_ivf_pq_uses_default_partition_size_for_num_partitions() {
|
||||
use arrow_array::{Float32Array, RecordBatch};
|
||||
|
||||
Reference in New Issue
Block a user