Skip to content

Commit

Permalink
[inferno-ml] Fix precision for entity ID columns (#134)
Browse files Browse the repository at this point in the history
Currently some entity IDs (group/user IDs) may overflow. So this changes
the column type to a `numeric` to fix that
  • Loading branch information
ngua authored Sep 27, 2024
1 parent feb8381 commit 599f3c5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions inferno-ml-server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Revision History for `inferno-ml-server`

## 2023.9.27
* Change entity DB representation to `numeric`

## 2023.7.2
* Use new `loadModel` primitive and pass model names to script evaluator

Expand Down
2 changes: 1 addition & 1 deletion inferno-ml-server/inferno-ml-server.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.4
name: inferno-ml-server
version: 2023.6.19
version: 2023.9.27
synopsis: Server for Inferno ML
description: Server for Inferno ML
homepage: https://github.com/plow-technologies/inferno.git#readme
Expand Down
11 changes: 8 additions & 3 deletions inferno-ml-server/src/Inferno/ML/Server/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import Data.Generics.Labels ()
import Data.Generics.Wrapped (wrappedTo)
import Data.Int (Int64)
import Data.Map.Strict (Map)
import Data.Scientific (Scientific)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Read as Text.Read
Expand Down Expand Up @@ -160,6 +161,7 @@ instance FromJSON (EntityId a) where
fmap entityIdFromInteger
. either fail (pure . fst)
. Text.Read.hexadecimal
-- Drop leading 'o'
. Text.drop 1

instance ToJSON (EntityId a) where
Expand All @@ -168,13 +170,16 @@ instance ToJSON (EntityId a) where
instance Typeable a => FromField (EntityId a) where
fromField f =
maybe (returnError UnexpectedNull f mempty) $
maybe (returnError ConversionFailed f mempty) (pure . entityIdFromInteger)
. readMaybe @Integer
maybe
(returnError ConversionFailed f mempty)
(pure . entityIdFromInteger . round)
-- `numeric` column
. readMaybe @Scientific
. ByteString.Char8.unpack

instance ToField (EntityId a) where
toField o = toField $ case readHex @Integer (entityIdToHex o) of
(n, _) : _ -> n
(n, _) : _ -> fromInteger @Scientific n
_ -> error "EntityId contained invalid fields"

entityIdFromInteger :: Integer -> EntityId a
Expand Down
4 changes: 2 additions & 2 deletions nix/inferno-ml/migrations/v1-create-tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ create extension lo;
create table if not exists models
( id serial primary key
, name text not null
, gid bigint not null
, gid numeric not null
, visibility jsonb
-- May be missing, if there is no model version yet
, updated timestamptz
Expand Down Expand Up @@ -77,7 +77,7 @@ create table if not exists params
, resolution integer not null
-- See note above
, terminated timestamptz
, uid bigint not null
, uid numeric not null
);

-- Execution info for inference evaluation
Expand Down

0 comments on commit 599f3c5

Please sign in to comment.