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

#339. Use more effective record count when JDBC source is used #460

Merged
merged 3 commits into from
Aug 13, 2024

Conversation

VladimirRybalko
Copy link
Collaborator

No description provided.

Copy link

github-actions bot commented Aug 12, 2024

Unit Test Coverage

File Coverage [84.34%] 🍏
TableReaderJdbc.scala 84.34% 🍏
Total Project Coverage 82.23% 🍏

Copy link
Collaborator

@yruslan yruslan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Looks good.

@yruslan
Copy link
Collaborator

yruslan commented Aug 12, 2024

Alternatively, we don't really need Spark to execute a count() query.

You can also do it like thins:

  private[core] def getCountForSql(sql: String, infoDateBegin: LocalDate, infoDateEnd: LocalDate): Long = {
    val filteredSql = TableReaderJdbcNative.getFilteredSql(sql, infoDateBegin, infoDateEnd)
    val countSql = s"SELECT COUNT(*) FROM ($filteredSql)"
    var count = 0L

    JdbcNativeUtils.withResultSet(jdbcUrlSelector, countSql, jdbcRetries) { rs =>
      if (!rs.next())
        throw new IllegalStateException(s"No rows returned by the count query: $countSql")
      else {
        count = rs.getLong(1)
      }
    }

    count

But this requires rebasing against the latest main

Copy link
Collaborator

@yruslan yruslan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@VladimirRybalko VladimirRybalko merged commit 0689321 into main Aug 13, 2024
8 checks passed
@VladimirRybalko VladimirRybalko deleted the feature/339-optimized-record-count-for-query branch August 13, 2024 09:22
@yruslan yruslan mentioned this pull request Aug 15, 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
Development

Successfully merging this pull request may close these issues.

2 participants