Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instant type mapper now allows NULL values #38

Conversation

aboisvert
Copy link
Contributor

@aboisvert aboisvert commented Oct 9, 2024

When doing a .leftJoin() operation, it's often the case that the right hand side will consist of all null values if the join expression does not match a row.

In my case, I was using an java.time.Instant-typed field, and I was getting exceptions such as,

scala.MatchError: null
    at scalasql.dialects.Dialect$InstantType.get(Dialect.scala:156)
    at scalasql.dialects.Dialect$InstantType.get(Dialect.scala:144)
    at scalasql.core.Queryable$ResultSetIterator.get(Queryable.scala:73)
    at scalasql.core.Expr$ExprQueryable.construct(Expr.scala:50)
    at fanstake.model.Teams$.Teams$$superArg$1$$anonfun$3$$anonfun$2(Team.scala:23)
    at scalasql.query.Table$Internal$TableQueryable.construct(Table.scala:97)
    at scalasql.query.Table$Internal$TableQueryable.construct(Table.scala:97)
    at scalasql.core.Queryable$Row$$anon$1.construct(Queryable.scala:147)
    at scalasql.core.Queryable$Row$$anon$1.construct(Queryable.scala:145)
    at scalasql.core.generated.QueryableRow.Tuple2Queryable$$anonfun$2(Generated.scala:11)
    at scalasql.core.Queryable$Row$TupleNQueryable.construct(Queryable.scala:133)
    at scalasql.core.Queryable$Row$TupleNQueryable.construct(Queryable.scala:133)
    at scalasql.core.generated.QueryableRow.Tuple2Queryable$$anonfun$2(Generated.scala:11)
    at scalasql.core.Queryable$Row$TupleNQueryable.construct(Queryable.scala:133)
    at scalasql.core.Queryable$Row$TupleNQueryable.construct(Queryable.scala:133)
    at scalasql.query.SimpleSelect.queryConstruct(SimpleSelect.scala:225)
    at scalasql.query.SimpleSelect.queryConstruct(SimpleSelect.scala:224)
    at scalasql.query.Query$QueryQueryable.construct(Query.scala:76)
    at scalasql.query.Query$QueryQueryable.construct(Query.scala:76)
    at scalasql.core.DbApi$.scalasql$core$DbApi$Impl$$_$stream$$anonfun$1(DbApi.scala:231)
    at scalasql.core.DbApi$Impl$$anon$1.generate$$anonfun$2(DbApi.scala:417)
    at scalasql.core.DbApi$Impl.configureRunCloseStatement(DbApi.scala:504)
    at scalasql.core.DbApi$Impl$$anon$1.generate(DbApi.scala:420)
    at geny.Generator.foreach(Generator.scala:51)
    at geny.Generator.foreach$(Generator.scala:33)
    at scalasql.core.DbApi$Impl$$anon$1.foreach(DbApi.scala:401)
    at geny.Generator.toBuffer(Generator.scala:127)
    at geny.Generator.toBuffer$(Generator.scala:33)
    at scalasql.core.DbApi$Impl$$anon$1.toBuffer(DbApi.scala:401)
    at geny.Generator.toVector(Generator.scala:135)
    at geny.Generator.toVector$(Generator.scala:33)
    at scalasql.core.DbApi$Impl$$anon$1.toVector(DbApi.scala:401)
    at scalasql.core.DbApi$Impl.run(DbApi.scala:218)
    at fanstake.webapp.controllers.AtlasDTO$.unsafeFindAll(AtlasDTO.scala:88)

The short of it is that Dialect.InstantType, which is a TypeMapper[Instant] didn't allow NULL values to go through.

The fix is trivial - just adding a null pass-through for the match expression.

PS: Similar to InstantType, I noticed that some other TypeMappers do not pass NULL values through. If this PR looks like the right approach to solve this, I can submit a different PR that addresses these other issues.

@lihaoyi lihaoyi merged commit df51bd7 into com-lihaoyi:main Oct 9, 2024
6 checks passed
@lihaoyi
Copy link
Member

lihaoyi commented Oct 9, 2024

@aboisvert thanks, this looks great

@lihaoyi
Copy link
Member

lihaoyi commented Oct 9, 2024

Let me know if you want to submit further PRs, if so I'll wait for those to land before releasing. If not I can cut a release now for this one

@aboisvert
Copy link
Contributor Author

Great, thanks! I'd prefer releasing now since we need this fix. That will give me more time to address the others.

@lihaoyi
Copy link
Member

lihaoyi commented Oct 9, 2024

@aboisvert 0.1.10 should be out

lihaoyi pushed a commit that referenced this pull request Oct 21, 2024
Similarly to #38, adding support for passing nulls (both ways, via
get/set) through the remaining TypeMappers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants