Amazon S3

Load Parquet, CSV, JSON and Avro files from an S3 bucket into warehouse tables, and keep them current as new files arrive.

Amazon S3 is in beta. Point Contrast at a location in a bucket, describe the files to load, and each group of files becomes a warehouse table. Every sync loads the files that arrived since the last one.

Before you connect

You need the S3 location (s3://bucket/path) and the bucket's region. Contrast lists and reads objects under that path only. It never writes, tags or deletes an object.

Contrast can read as a cross-account IAM role in your account (recommended) or with an access key.

Cross-account role

  1. In the connect form, choose Cross-account role. The form shows the Contrast principal and your workspace's external ID, and fills in both policies below for your location.

  2. In IAM, create a role with this trust policy. Only Contrast can assume it, and only for your workspace, because the policy requires your workspace's external ID (contrast-<workspace ID>).

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Principal": { "AWS": "<Contrast principal from the form>" },
          "Action": "sts:AssumeRole",
          "Condition": { "StringEquals": { "sts:ExternalId": "<external ID from the form>" } }
        }
      ]
    }
  3. Attach this permissions policy to the role. For the location s3://lake-bucket/raw:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": "s3:ListBucket",
          "Resource": "arn:aws:s3:::lake-bucket",
          "Condition": { "StringLike": { "s3:prefix": ["raw/*"] } }
        },
        {
          "Effect": "Allow",
          "Action": "s3:GetObject",
          "Resource": "arn:aws:s3:::lake-bucket/raw/*"
        }
      ]
    }

    If the bucket uses SSE-KMS with a customer managed key, also allow kms:Decrypt on that key.

  4. Paste the role ARN into the form. The role must belong to your AWS account; Contrast refuses roles in its own account. The external ID is set by Contrast and can't be changed in the form, so another workspace can't reuse your role.

Access keys

Create an IAM user with the permissions policy above, create an access key for it, and paste the access key ID and secret access key. A session token is accepted for temporary credentials, which stop working when the session expires. Keep the user read-only and rotate its key.

Connect

You need to be a workspace administrator to start a sync. Editors can connect the bucket.

  1. Open the Amazon S3 setup link.
  2. Enter the location and the bucket's region, choose how Contrast signs in, and finish the steps above.
  3. Add a dataset for each group of files, or select Suggest datasets to start from proposals. Select Preview on a dataset to check it before you save. See Datasets.
  4. Select the datasets to sync and start the sync.

When you connect, Contrast checks that it can sign in, list the location and read a file. Credentials are stored encrypted and are never shown again.

Datasets

A dataset is one table, files.<name>, loaded from the files its pattern matches. Start with one and add more for other file groups in the same location. The same file can belong to two datasets, and each loads it separately.

SettingWhat it does
NameThe table name: lowercase letters, digits and underscores, starting with a letter, at most 63 characters.
PatternWhich files belong to the table, relative to the location. * and ? match within one folder, ** matches across folders, and {a,b} and [a-z] match a set. events/**/*.parquet matches every Parquet file at any depth under events/.
FormatParquet, CSV, JSON or Avro.
CompressionFor CSV and JSON: from the file extension (the default), none, gzip, Zstandard or bzip2. Parquet and Avro files carry their own compression.
CSV optionsDelimiter, whether the first row holds column names, quote character, escape character (by default a doubled quote reads as one quote), null values, encoding, rows to skip before the header, and a comment character.
JSON layoutDetect (the default), one object per line, or one array per file.
Row keysFile and row number (the default) keeps every row of every file. Key columns merges rows by the columns you name, so a later row replaces an earlier one with the same key.
When a file has bad dataKeep the row (the default) loads the row and moves values that don't fit to _rescued_data. Skip the file stops loading a file at its first bad value and records it as failed; rows already saved from earlier parts of a large file stay in the table. Stop the sync stops the table's sync at the first bad value.
LookbackHow far behind the last sync a file's timestamp can be and still load: 1 to 720 hours, 168 (a week) by default. See How new files are found.

The connect form says in plain words what each pattern matches. Contrast skips paths with a folder or file name that starts with _ or . (such as _SUCCESS, _temporary/ and .crc files), so a pattern that names one matches nothing.

Preview a dataset

Select Preview on a dataset to see what it would load before you save it. Contrast lists up to 10,000 objects under the location and reads up to 32 MB for at most 20 seconds. It samples up to 3 matching files and shows up to 20 rows. The preview shows:

  • The files the pattern matched: the first 20 in key order, and how many match in all.
  • When nothing matches, the nearest files that almost did, so you can see what to change in the pattern.
  • The columns Contrast inferred.
  • The sample rows.
  • Warnings: files with different schemas, values that don't fit and would go to _rescued_data, a Delta or Iceberg table under the location, and a note when a limit cut the preview short.

A preview reads files but loads nothing and creates no table.

Suggest datasets

Select Suggest datasets on the location to have Contrast look at what is there. It groups files by their leading folders and file extension and proposes up to 50 datasets, each with a pattern and format. Keep the ones you want, change them as needed, and preview them like any other dataset.

Edit datasets later

You can change a connected bucket's datasets after the first save. You need to be a workspace administrator to do this. The location stays the one you connected, and every pattern is read under it. To read another location, connect it as a new source.

  • Add a dataset. Saving adds its table, and the next sync loads it from every matching file. If the files can't load yet, for example because they have more than 1,000 columns, the table is saved without syncing and the app says why. Each sync checks it again.
  • Change a saved dataset's pattern, format, compression or options. This requires a full resync of that table, because the rows already loaded were read under the old settings. The app tells you which tables will reload from every file and asks you to confirm before it saves. Only those tables reload. When several change, one sync reloads them and reads only new files for the other tables.
  • Remove a dataset. Its table stops syncing. The rows already loaded and the table's file history stay. To resume the table from where it stopped, add a dataset with the same name back. If it comes back with a different pattern, format, compression or options, the table is resynced as for any such change.
  • Row keys can't change after a dataset's table is created. A resync merges the reread rows by key and keeps every row it touches, so rows loaded under the old keys would stay. To key rows differently, add a new dataset with the new row keys, then remove the old one.
  • Rename a dataset. A rename removes the old dataset and adds a new one: the old table stops syncing and keeps its rows, and a table with the new name loads from every matching file. The app asks you to confirm before it saves a removal or a rename.
  • If someone else changed the datasets while you were editing, the save is refused. Reload and edit again.

Columns Contrast adds

Every table has these columns besides the file's own:

ColumnTypeContents
_row_idstringA hash of the file's key and the row number. The primary key when rows are keyed by file and row number.
_file_pathstringThe file's key in the bucket
_file_row_numberlongThe row's position in its file, counting from 0
_file_last_modifiedtimestamp with time zoneWhen the file's content was written
_rescued_datastringValues that didn't fit, as JSON text with the reason; null for clean rows

A data column whose name matches one of these is renamed with a data_ prefix. Folder names in the form key=value under a dataset become string columns.

How new files are found

Each sync lists everything under the dataset's part of the location and loads the files it hasn't recorded yet.

  • Any key order. Files don't need names that sort after the last one loaded. A file whose name sorts first still loads.
  • One load per path. Once a file has loaded, a new upload to the same path is recorded as an ignored overwrite and is not read. To load changed data, write it to a new path. A renamed or moved file is a new path and loads again.
  • Failed files. A file that failed is read again only when its contents change. See File history.
  • Deleted files. Rows stay in the table after their file is deleted.
  • Lookback. A sync reads files whose timestamp falls after the previous sync's cutoff minus the lookback. Some uploads carry the time they started, and copied files can keep their original time, so a file can arrive with a timestamp the last sync already passed. A file older than the lookback allows is only picked up by a full resync.
  • Skipped without a record. Folder markers, empty (zero-byte) files, and paths with a folder or file name that starts with _ or ..

Contrast finds files by listing on each scheduled sync. It does not use event notifications.

File history

Open a table's Files view to see each file Contrast has recorded for it, newest first. Each file has one status:

StatusMeaning
LoadedThe file's rows were loaded.
FailedThe file couldn't be read. The record shows its first error.
SkippedThe file couldn't be read as listed: it is in an archive storage class, or it was deleted or overwritten while being read. It is read again when its contents change, and an archived file is read by the next sync after you restore it.
Ignored overwriteThe path had already loaded, so the new upload was not read.

Select Failed only to show just the files that failed. A failed file is read again only when its contents change. After you fix the cause, such as the format settings, upload a corrected file to a new path.

Bad files and bad values

  • A value that doesn't fit its column, such as text in a number column, is set to null and kept in _rescued_data with the reason, when the dataset keeps rows. Values are never truncated.
  • Nested values (structs, lists and maps, or JSON objects and arrays) land as JSON text.
  • Decimals with more than 38 digits and timestamps with nanosecond precision are rescued, not rounded.
  • New columns are added as nullable, and a column missing from a file reads as null. Integers widen to longs, floats to doubles, and decimals to wider decimals. Any other type change leaves the table's column as it is and rescues the values.
  • With key columns, a row whose key is null or missing is not loaded and is counted on its file's record.
  • A file that can't be parsed at all is recorded as failed with its first error, and the table carries on with other files unless the dataset stops the sync on bad data.

Limits in beta

  • New files are found by listing the location on each scheduled sync: every 15 minutes by default, and never more often. S3 event notifications are not used.
  • Column types come from the first files read. A number column inferred from whole numbers stays a whole-number column: fractional values that arrive later are set to null and kept in _rescued_data rather than widening the column. If a column can hold fractions, make sure the first file has one, or expect rescued values.
  • A file is loaded once per path. Overwriting a file does not reload it.
  • Deleting a file doesn't remove its rows. Only a full resync drops the rows of files that are gone. If a resync would remove more than a fifth of a table's rows (and more than 25), or all of them, Contrast keeps those rows until a workspace editor or administrator approves the deletion. A full resync that couldn't read every file removes nothing, so the rows of an archived or failed file are never dropped by mistake; the table says so, and the next full resync that reads every file removes the rows of deleted files.
  • A table can have at most 1,000 columns besides the ones Contrast adds.
  • Each sync lists every file under the dataset's folder. Datasets of up to about a million files have been tested; larger ones take longer to list on every sync.
  • Only Amazon S3 is supported. S3-compatible stores with their own endpoints are not.
  • Objects in the Glacier and Deep Archive storage classes are listed but can't be read until you restore them. The next sync after a restore loads them.
  • Formats are Parquet, CSV, JSON and Avro. ORC and XML are not supported.
  • Lookback is at most 720 hours.

Troubleshooting

Sync errors name one of these codes.

CodeWhat to do
object_storage_invalid_locationEnter the location as s3://bucket/path, without . or .. folders.
object_storage_invalid_credentialsThe role ARN or access key is incomplete or malformed. Paste it again.
object_storage_auth_failedAWS rejected the access key, or the role can't be assumed. Check the key is active, or that the role's trust policy names the Contrast principal and your workspace's external ID exactly.
object_storage_access_deniedThe error names the action that was denied: assume_role (check the trust policy), list (allow s3:ListBucket for the location's prefix), read (allow s3:GetObject under the location), or decrypt (allow kms:Decrypt on the bucket's KMS key).
object_storage_bucket_not_foundCheck the bucket name.
object_storage_region_mismatchThe bucket is in a different region. Enter the region shown on the bucket's Properties tab.
object_storage_object_archivedThe file is in Glacier or Deep Archive. Restore it; the next sync loads it.
object_storage_object_goneThe file was deleted between listing and reading. It is recorded as skipped and the table carries on.
object_storage_object_changedThe file was overwritten while it was read. If no rows from it were saved yet, it is recorded as skipped; otherwise it is recorded as failed and the rows already saved from it stay.
object_storage_resync_kept_rowsA full resync couldn't read every file (one was archived, failed, or changed while it was read), so it removed no rows. Fix or restore the file, then run the full resync again to drop the rows of deleted files.
object_storage_throttledThe provider limited request rates. The sync retries.
object_storage_unavailableThe provider timed out or returned a server error. The sync retries.
object_storage_too_many_columnsThe dataset's files, or a new file joining it, would give the table more than 1,000 columns. A new table isn't created and a new file is recorded as failed (or stops the sync, if the dataset stops on bad data). Narrow the pattern to files with fewer columns, or split the files into datasets with their own patterns.
object_storage_identity_columns_missingThe dataset's key columns aren't in its files, so the table can't sync yet. Check the key column names against the preview's columns, add a file that has them, or key rows by file and row number.
object_storage_rows_rescuedValues didn't fit the table's columns in a dataset that skips the file or stops the sync on bad data. With Skip the file the file is recorded as failed; with Stop the sync the sync stops. Fix the values and upload the file to a new path, or switch the dataset to Keep the row to load such rows with the values in _rescued_data.
object_storage_key_missingShown on a loaded file's record: some rows had no value for a key column and weren't loaded. The file's other rows loaded. Fill in the key values and upload the file to a new path, or choose key columns every row has.
object_storage_file_invalidThe file can't be parsed as the dataset's format. Check the format, compression and CSV or JSON options, or fix the file and upload it to a new path.
object_storage_reader_memory_exceeded, object_storage_reader_timeout, object_storage_reader_crashedContrast reads each file in an isolated process with a memory and time limit. A timeout or crash is tried again; after three failures in a row at the same place the file is recorded as failed. Split very large files, row groups or lines, then upload them to a new path.

See AWS's documentation on roles for a third party and S3 policy keys.