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

Using exists in subquery #1708

Closed
Sherzodbek-Muhammadiev opened this issue Mar 20, 2023 · 1 comment · Fixed by #2094
Closed

Using exists in subquery #1708

Sherzodbek-Muhammadiev opened this issue Mar 20, 2023 · 1 comment · Fixed by #2094
Assignees

Comments

@Sherzodbek-Muhammadiev
Copy link

java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Boolean (java.lang.Integer and java.lang.Boolean are in module java.base of loader 'bootstrap')

val isOpenSubQuery = StudentLessonEntity
                .slice(StudentLessonEntity.id)
                .select {
                (StudentLessonEntity.studentId eq studentId and
                        (StudentLessonEntity.courseId eq courseId) and
                        (StudentLessonEntity.lessonId eq LessonEntity.id))
            }


            val isOpen = exists(isOpenSubQuery).alias("is_open")

and I run query:

(CourseEntity innerJoin LessonPackageEntity innerJoin LessonEntity)
                .slice(LessonEntity.id, LessonEntity.name, isOpen, solvedCount, taskCount)
                .select { CourseEntity.id eq courseId }
                .map { Mapper.run { it.toStudentLessonData(solvedCount, taskCount, isOpen) } }

Mapper:

 fun ResultRow.toStudentLessonData(
        solvedCount: Expression<Int>,
        taskCount: Expression<Int>,
        isOpen: Expression<Boolean>,
    ) = StudentLessonData(
        id = this[LessonEntity.id].value,
        name = this[LessonEntity.name],
        solvedCount = this[solvedCount],
        taskCount = this[taskCount],
        isLocked = this[isOpen]
    )

And this line isLocked = this[isOpen] happened crash

@Sherzodbek-Muhammadiev
Copy link
Author

Now, I am using my custom function exits2 as temporary solution:

class exists2(
    val query: AbstractQuery<*>
) : Op<Int>() {
    override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit = queryBuilder {
        append("EXISTS (")
        query.prepareSQL(this)
        append(")")
    }
}

@joc-a joc-a linked a pull request Jul 19, 2023 that will close this issue
@joc-a joc-a self-assigned this Jul 19, 2023
@joc-a joc-a linked a pull request May 28, 2024 that will close this issue
@joc-a joc-a closed this as completed May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants