Skip to content

Commit af5c342

Browse files
committed
fix: correctly support types like integer
1 parent 40e04cf commit af5c342

File tree

5 files changed

+223
-149
lines changed

5 files changed

+223
-149
lines changed

examples/postgres_embedding/main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ def postgres_message_embedding_flow(
1414
data_scope["messages"] = flow_builder.add_source(
1515
cocoindex.sources.Postgres(
1616
table_name="source_messages",
17+
# Optional. Use the default CocoIndex database if not specified.
1718
database=cocoindex.add_transient_auth_entry(
1819
cocoindex.sources.DatabaseConnectionSpec(
1920
url=os.getenv("SOURCE_DATABASE_URL"),
2021
)
2122
),
23+
# Optional.
2224
ordinal_column="created_at",
2325
)
2426
)
@@ -80,11 +82,14 @@ def postgres_product_embedding_flow(
8082
data_scope["products"] = flow_builder.add_source(
8183
cocoindex.sources.Postgres(
8284
table_name="source_products",
85+
# Optional. Use the default CocoIndex database if not specified.
8386
database=cocoindex.add_transient_auth_entry(
8487
cocoindex.sources.DatabaseConnectionSpec(
8588
url=os.getenv("SOURCE_DATABASE_URL"),
8689
)
8790
),
91+
# Optional.
92+
ordinal_column="modified_time",
8893
)
8994
)
9095

@@ -96,6 +101,11 @@ def postgres_product_embedding_flow(
96101
product["_key"]["product_name"],
97102
product["description"],
98103
)
104+
product["total_value"] = flow_builder.transform(
105+
calculate_total_value,
106+
product["price"],
107+
product["amount"],
108+
)
99109
product["embedding"] = product["full_description"].transform(
100110
cocoindex.functions.SentenceTransformerEmbed(
101111
model="sentence-transformers/all-MiniLM-L6-v2"
@@ -107,6 +117,7 @@ def postgres_product_embedding_flow(
107117
description=product["description"],
108118
price=product["price"],
109119
amount=product["amount"],
120+
total_value=product["total_value"],
110121
embedding=product["embedding"],
111122
)
112123

examples/postgres_embedding/prepare_source_data.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ VALUES (
8888
'Sports',
8989
'Running Shoes',
9090
'Lightweight running shoes for daily training',
91-
129.99,
91+
129.5,
9292
60,
9393
NOW() - INTERVAL '1 day'
9494
) ON CONFLICT (product_category, product_name) DO NOTHING;

src/ops/shared/postgres.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ pub async fn get_db_pool(
2323
}
2424

2525
pub fn key_value_fields_iter<'a>(
26-
key_fields_schema: &[FieldSchema],
26+
key_fields_schema: impl ExactSizeIterator<Item = &'a FieldSchema>,
2727
key_value: &'a KeyValue,
2828
) -> Result<&'a [KeyValue]> {
29-
let slice = if key_fields_schema.len() == 1 {
29+
let slice = if key_fields_schema.into_iter().count() == 1 {
3030
std::slice::from_ref(key_value)
3131
} else {
3232
match key_value {

0 commit comments

Comments
 (0)