Skip to content
New issue

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

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

Already on GitHub? # to your account

Support table truncate when writing in overwrite mode #507

Closed
jmyrberg opened this issue Oct 5, 2022 · 3 comments · Fixed by #510
Closed

Support table truncate when writing in overwrite mode #507

jmyrberg opened this issue Oct 5, 2022 · 3 comments · Fixed by #510
Assignees
Labels
enhancement New feature or request High Priority
Milestone

Comments

@jmyrberg
Copy link

jmyrberg commented Oct 5, 2022

Is your feature request related to a problem? Please describe.

We have a table where all the rows need to be re-written after a Spark batch job. The table has existing permissions that should be preserved. However, the table permissions are lost when the rows are written in overwrite mode:

(sdf.write.format('com.vertica.spark.datasource.VerticaSource')
    .mode('overwrite').options(**options).save())

Describe the solution you'd like

In overwrite mode, there should be an option to truncate the target table instead of dropping it before re-write.

The standard Spark JDBC connector allows one to set truncate option to solve this (link).

Describe alternatives you've considered

Workarounds exist, but they are not very practical:

  • Execute truncate statement through JDBC using some other library and write the rows using the connector in append mode
  • Pass the privileges through target_table_sql parameter
  • Using some external script/procedure to re-set the privileges

Additional context

What the solution could look like after implementation:

options['truncate'] = True

(sdf.write.format('com.vertica.spark.datasource.VerticaSource')
    .mode('overwrite').options(**options).save())
@jmyrberg jmyrberg added the enhancement New feature or request label Oct 5, 2022
@alexey-temnikov alexey-temnikov added this to the 3.3.4 milestone Oct 7, 2022
@ai-bq ai-bq self-assigned this Oct 7, 2022
@alexey-temnikov
Copy link
Collaborator

Hi @jmyrberg, thank you for raising this. I agree with your suggestion, we will look into this enhancement.

@jeremyprime
Copy link
Collaborator

@jmyrberg, the truncate option (see the documentation in README.md) has been added as part of release 3.3.4, which is now available in Maven.

@jmyrberg
Copy link
Author

@jmyrberg, the truncate option (see the documentation in README.md) has been added as part of release 3.3.4, which is now available in Maven.

Awesome, we’ll have a look, thank you! 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request High Priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants