From cac1e31152946603790df6a670031e2c0d1e72fc Mon Sep 17 00:00:00 2001 From: Borys Tkachenko Date: Fri, 22 Nov 2024 11:31:47 +0100 Subject: [PATCH] Fix cost type to Decimal64 --- .../src/main/java/com/comet/opik/domain/SpanDAO.java | 8 ++++---- .../migrations/000007_add_model_to_spans.sql | 2 +- .../opik/api/resources/v1/priv/SpansResourceTest.java | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/opik-backend/src/main/java/com/comet/opik/domain/SpanDAO.java b/apps/opik-backend/src/main/java/com/comet/opik/domain/SpanDAO.java index 3912aba370..c94012e224 100644 --- a/apps/opik-backend/src/main/java/com/comet/opik/domain/SpanDAO.java +++ b/apps/opik-backend/src/main/java/com/comet/opik/domain/SpanDAO.java @@ -94,7 +94,7 @@ INSERT INTO spans( :metadata, :model, :provider, - toDecimal32(:total_estimated_cost, 8), + toDecimal64(:total_estimated_cost, 8), :total_estimated_cost_version, :tags, mapFromArrays(:usage_keys, :usage_values), @@ -235,7 +235,7 @@ INSERT INTO spans( :metadata as metadata, :model as model, :provider as provider, - toDecimal32(:total_estimated_cost, 8) as total_estimated_cost, + toDecimal64(:total_estimated_cost, 8) as total_estimated_cost, :total_estimated_cost_version as total_estimated_cost_version, :tags as tags, mapFromArrays(:usage_keys, :usage_values) as usage, @@ -297,7 +297,7 @@ INSERT INTO spans ( :metadata metadata as metadata, :model model as model, :provider provider as provider, - toDecimal32(:total_estimated_cost, 8) total_estimated_cost as total_estimated_cost, + toDecimal64(:total_estimated_cost, 8) total_estimated_cost as total_estimated_cost, :total_estimated_cost_version total_estimated_cost_version as total_estimated_cost_version, :tags tags as tags, CAST((:usageKeys, :usageValues), 'Map(String, Int64)') usage as usage, @@ -437,7 +437,7 @@ INSERT INTO spans( :metadata '' as metadata, :model '' as model, :provider '' as provider, - toDecimal32(:total_estimated_cost, 8) toDecimal32(0, 8) as total_estimated_cost, + toDecimal64(:total_estimated_cost, 8) toDecimal64(0, 8) as total_estimated_cost, :total_estimated_cost_version '' as total_estimated_cost_version, :tags [] as tags, CAST((:usageKeys, :usageValues), 'Map(String, Int64)') mapFromArrays([], []) as usage, diff --git a/apps/opik-backend/src/main/resources/liquibase/db-app-analytics/migrations/000007_add_model_to_spans.sql b/apps/opik-backend/src/main/resources/liquibase/db-app-analytics/migrations/000007_add_model_to_spans.sql index cc5d3e96dd..d5fa2f5ad5 100644 --- a/apps/opik-backend/src/main/resources/liquibase/db-app-analytics/migrations/000007_add_model_to_spans.sql +++ b/apps/opik-backend/src/main/resources/liquibase/db-app-analytics/migrations/000007_add_model_to_spans.sql @@ -4,7 +4,7 @@ ALTER TABLE ${ANALYTICS_DB_DATABASE_NAME}.spans ADD COLUMN IF NOT EXISTS model String DEFAULT '', ADD COLUMN IF NOT EXISTS provider String DEFAULT '', - ADD COLUMN IF NOT EXISTS total_estimated_cost Decimal32(8), + ADD COLUMN IF NOT EXISTS total_estimated_cost Decimal64(8), ADD COLUMN IF NOT EXISTS total_estimated_cost_version String DEFAULT ''; --rollback ALTER TABLE ${ANALYTICS_DB_DATABASE_NAME}.spans DROP COLUMN IF EXISTS model, DROP COLUMN IF EXISTS provider, DROP COLUMN IF EXISTS total_estimated_cost, DROP COLUMN IF EXISTS total_estimated_cost_version; diff --git a/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/SpansResourceTest.java b/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/SpansResourceTest.java index 5072dc9588..32c875389c 100644 --- a/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/SpansResourceTest.java +++ b/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/SpansResourceTest.java @@ -3217,9 +3217,9 @@ static Stream createAndGetCost() { .getJsonNodeFromString( "{\"created_from\":\"openai\",\"type\":\"openai_chat\",\"model\":\"gpt-3.5-turbo\"}"); return Stream.of( - Arguments.of(new BigDecimal("10.0000000"), "gpt-3.5-turbo-1106", null), - Arguments.of(new BigDecimal("10.0000000"), "gpt-3.5-turbo-1106", metadata), - Arguments.of(new BigDecimal("12.0000000"), "", metadata), + Arguments.of(new BigDecimal("10.00000000"), "gpt-3.5-turbo-1106", null), + Arguments.of(new BigDecimal("10.00000000"), "gpt-3.5-turbo-1106", metadata), + Arguments.of(new BigDecimal("12.00000000"), "", metadata), Arguments.of(null, "unknown-model", null), Arguments.of(null, "", null)); }