Skip to content

Commit

Permalink
Fix cost type to Decimal64
Browse files Browse the repository at this point in the history
  • Loading branch information
Borys Tkachenko committed Nov 22, 2024
1 parent 8887d0d commit cac1e31
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ INSERT INTO spans(
:metadata<item.index>,
:model<item.index>,
:provider<item.index>,
toDecimal32(:total_estimated_cost<item.index>, 8),
toDecimal64(:total_estimated_cost<item.index>, 8),
:total_estimated_cost_version<item.index>,
:tags<item.index>,
mapFromArrays(:usage_keys<item.index>, :usage_values<item.index>),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -297,7 +297,7 @@ INSERT INTO spans (
<if(metadata)> :metadata <else> metadata <endif> as metadata,
<if(model)> :model <else> model <endif> as model,
<if(provider)> :provider <else> provider <endif> as provider,
<if(total_estimated_cost)> toDecimal32(:total_estimated_cost, 8) <else> total_estimated_cost <endif> as total_estimated_cost,
<if(total_estimated_cost)> toDecimal64(:total_estimated_cost, 8) <else> total_estimated_cost <endif> as total_estimated_cost,
<if(total_estimated_cost_version)> :total_estimated_cost_version <else> total_estimated_cost_version <endif> as total_estimated_cost_version,
<if(tags)> :tags <else> tags <endif> as tags,
<if(usage)> CAST((:usageKeys, :usageValues), 'Map(String, Int64)') <else> usage <endif> as usage,
Expand Down Expand Up @@ -437,7 +437,7 @@ INSERT INTO spans(
<if(metadata)> :metadata <else> '' <endif> as metadata,
<if(model)> :model <else> '' <endif> as model,
<if(provider)> :provider <else> '' <endif> as provider,
<if(total_estimated_cost)> toDecimal32(:total_estimated_cost, 8) <else> toDecimal32(0, 8) <endif> as total_estimated_cost,
<if(total_estimated_cost)> toDecimal64(:total_estimated_cost, 8) <else> toDecimal64(0, 8) <endif> as total_estimated_cost,
<if(total_estimated_cost_version)> :total_estimated_cost_version <else> '' <endif> as total_estimated_cost_version,
<if(tags)> :tags <else> [] <endif> as tags,
<if(usage)> CAST((:usageKeys, :usageValues), 'Map(String, Int64)') <else> mapFromArrays([], []) <endif> as usage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -3217,9 +3217,9 @@ static Stream<Arguments> 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));
}
Expand Down

0 comments on commit cac1e31

Please sign in to comment.