# CsvOptions

The options for imported source files in CSV format.

Used as argument in: [InputFormat.csv](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.InputFormat.html#csv)

- Source: [`aws-dynamodb/lib/table.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-dynamodb/lib/table.ts#L102)
- Type last changed: v2.123.0 · 24 Jan 2024

## Example

TypeScript:

```ts
import * as cdk from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');

declare const bucket: s3.IBucket;

new dynamodb.Table(stack, 'Table', {
  partitionKey: {
    name: 'id',
    type: dynamodb.AttributeType.STRING,
  },
  importSource: {
    compressionType: dynamodb.InputCompressionType.GZIP,
    inputFormat: dynamodb.InputFormat.csv({
      delimiter: ',',
      headerList: ['id', 'name'],
    }),
    bucket,
    keyPrefix: 'prefix',
  },
});
```

Python:

```python
import aws_cdk as cdk
import aws_cdk.aws_s3 as s3

# bucket: s3.IBucket

app = cdk.App()
stack = cdk.Stack(app, "Stack")

dynamodb.Table(stack, "Table",
    partition_key=dynamodb.Attribute(
        name="id",
        type=dynamodb.AttributeType.STRING
    ),
    import_source=dynamodb.ImportSourceSpecification(
        compression_type=dynamodb.InputCompressionType.GZIP,
        input_format=dynamodb.InputFormat.csv(
            delimiter=",",
            header_list=["id", "name"]
        ),
        bucket=bucket,
        key_prefix="prefix"
    )
)
```

Java:

```java
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.s3.*;

IBucket bucket;

App app = new App();
Stack stack = new Stack(app, "Stack");

Table.Builder.create(stack, "Table")
        .partitionKey(Attribute.builder()
                .name("id")
                .type(AttributeType.STRING)
                .build())
        .importSource(ImportSourceSpecification.builder()
                .compressionType(InputCompressionType.GZIP)
                .inputFormat(InputFormat.csv(CsvOptions.builder()
                        .delimiter(",")
                        .headerList(List.of("id", "name"))
                        .build()))
                .bucket(bucket)
                .keyPrefix("prefix")
                .build())
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK;
using Amazon.CDK.AWS.S3;

IBucket bucket;

var app = new App();
var stack = new Stack(app, "Stack");

new Table(stack, "Table", new TableProps {
    PartitionKey = new Attribute {
        Name = "id",
        Type = AttributeType.STRING
    },
    ImportSource = new ImportSourceSpecification {
        CompressionType = InputCompressionType.GZIP,
        InputFormat = InputFormat.Csv(new CsvOptions {
            Delimiter = ",",
            HeaderList = new [] { "id", "name" }
        }),
        Bucket = bucket,
        KeyPrefix = "prefix"
    }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import s3 "github.com/aws/aws-cdk-go/awscdk"

var bucket IBucket

app := cdk.NewApp()
stack := cdk.NewStack(app, jsii.String("Stack"))

dynamodb.NewTable(stack, jsii.String("Table"), &TableProps{
	PartitionKey: &Attribute{
		Name: jsii.String("id"),
		Type: dynamodb.AttributeType_STRING,
	},
	ImportSource: &ImportSourceSpecification{
		CompressionType: dynamodb.InputCompressionType_GZIP,
		InputFormat: dynamodb.InputFormat_Csv(&CsvOptions{
			Delimiter: jsii.String(","),
			HeaderList: []*string{
				jsii.String("id"),
				jsii.String("name"),
			},
		}),
		Bucket: *Bucket,
		KeyPrefix: jsii.String("prefix"),
	},
})
```

## Properties

- `delimiter`: string — The delimiter used for separating items in the CSV file being imported.

  **Default:** use comma as a delimiter.

  Valid delimiters are as follows:
  - comma (`,`)
  - tab (`\t`)
  - colon (`:`)
  - semicolon (`;`)
  - pipe (`|`)
  - space (` `)

- `headerList`: string[] — List of the headers used to specify a common header for all source CSV files being imported.

  **Default:** the first line of the CSV file is treated as the header

  **NOTE**: If this field is specified then the first line of each CSV file is treated as data instead of the header.
  If this field is not specified the first line of each CSV file is treated as the header.
