You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/guides/hyper_file/optimize.md
+37-7Lines changed: 37 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,13 +17,43 @@ To use a specific database file format version, you'll need to use the `default_
17
17
Using the latest available database file format version should lessen the need to manually defragment or otherwise optimize your file for size or performance.
18
18
However, for extremely fragmented files you might still benefit from manually optimizing your file.
19
19
20
-
## Rewrite your Hyper file in an optimized format {#rewrite-your-hyper-file-in-an-optimized-format}
21
-
22
-
If you have a Hyper file that has become fragmented or is still using an older file version, one simple solution is to create a new file and copy all the data into it.
23
-
There is a [script that does just that](https://github.com/tableau/hyper-api-samples/tree/main/Community-Supported/convert-hyper-file) available on Github.
24
-
25
-
The Python script uses the Hyper API to copy all the schemas and tables in an existing `.hyper` file and writes them into a new file in a continuous sequence, eliminating any fragmentation that might have occurred.
26
-
By creating the new `.hyper` file with the intended new file format version, you can upgrade / downgrade between the various Hyper file versions.
20
+
## Rewrite your Hyper file in an optimized format
21
+
22
+
If you have a Hyper file that has become fragmented or is still using an older file version where you want to take advantage of new version features, you can
23
+
update your existing Hyper databases by checking the version and updating the version prior to performing other operations on them. For instance the Python script
24
+
below does this while maintaining a backup of the old Hyper file.
25
+
26
+
```python
27
+
import os
28
+
from tableauhyperapi import HyperProcess, Connection, Telemetry, CreateMode
29
+
30
+
TARGET_DATABASE_VERSION="2"
31
+
32
+
with HyperProcess(Telemetry.SEND_USAGE_DATA_TO_TABLEAU,
33
+
parameters= {"default_database_version": TARGET_DATABASE_VERSION}) as hyper:
34
+
should_update_version =False
35
+
with Connection(hyper.endpoint, 'existing.hyper', CreateMode.CREATE_IF_NOT_EXISTS) as connection:
36
+
# check the current version of the extract
37
+
38
+
version = connection.execute_scalar_query("SELECT database_version from pg_catalog.hyper_database")
39
+
if version <TARGET_DATABASE_VERSION:
40
+
print(f'found version {version}, upgrading to version {TARGET_DATABASE_VERSION}')
41
+
should_update_version =True
42
+
43
+
if should_update_version:
44
+
with Connection(hyper.endpoint) as connection:
45
+
connection.execute_command(f"""
46
+
CREATE DATABASE "updatedversion.hyper" WITH VERSION {TARGET_DATABASE_VERSION} FROM "existing.hyper"
47
+
""")
48
+
# make a backup of the existing hyper file - will overwrite any existing file
0 commit comments