Skip to content

Instantly share code, notes, and snippets.

@ndrluis
Last active July 27, 2024 15:39
Show Gist options
  • Save ndrluis/9113e5fecbe19021b3592bc0fb6ba815 to your computer and use it in GitHub Desktop.
Save ndrluis/9113e5fecbe19021b3592bc0fb6ba815 to your computer and use it in GitHub Desktop.
scan example
use std::collections::HashMap;
use futures::TryStreamExt;
use iceberg::{
io::{S3_ACCESS_KEY_ID, S3_ENDPOINT, S3_SECRET_ACCESS_KEY},
Catalog, TableIdent,
};
use iceberg_catalog_rest::{RestCatalog, RestCatalogConfig};
#[tokio::main]
async fn main() {
// Create catalog
let config = RestCatalogConfig::builder()
.uri("http://localhost:8181".to_string())
.warehouse("demo".to_string())
.props(HashMap::from([
(S3_ENDPOINT.to_string(), "http://localhost:9000".to_string()),
(S3_ACCESS_KEY_ID.to_string(), "admin".to_string()),
(S3_SECRET_ACCESS_KEY.to_string(), "password".to_string()),
]))
.build();
let catalog = RestCatalog::new(config);
let table = catalog
.load_table(&TableIdent::from_strs(["default", "cities"]).unwrap())
.await
.unwrap();
let scan = table.scan().select_all().build().unwrap();
let batch_stream = scan.to_arrow().await.unwrap();
dbg!(scan);
let batches: Vec<_> = batch_stream.try_collect().await.unwrap();
dbg!(batches.len());
}
from pyiceberg.catalog import load_catalog
from pyiceberg.table import Table
catalog = load_catalog(
"demo",
**{
"type": "rest",
"uri": "http://localhost:8181/",
"s3.endpoint": "http://localhost:9000",
"s3.access-key-id": "admin",
"s3.secret-access-key": "password",
"warehouse": "demo",
},
)
tbl: Table = catalog.load_table("default.cities")
res = tbl.scan().to_arrow()
print(len(res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment