

 Amazon Redshift는 패치 198부터 새 Python UDF 생성을 더 이상 지원하지 않습니다. 기존 Python UDF는 2026년 6월 30일까지 계속 작동합니다. 자세한 내용은 [블로그 게시물](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)을 참조하세요.

# Apache Spark용 Amazon Redshift 통합
<a name="spark-redshift-connector"></a>

 [Apache Spark](https://aws.amazon.com/emr/features/spark/)는 기계 학습, 스트림 처리 또는 그래픽 분석을 수행하는 데 도움이 되는 분산 처리 프레임워크 및 프로그래밍 모델입니다. Apache Hadoop과 마찬가지로, Spark는 빅 데이터 워크로드에 일반적으로 사용되는 오픈 소스 분산형 처리 시스템입니다. Spark에는 최적화된 비순환 방향 그래프(DAG) 실행 엔진이 있으며 메모리 안에 데이터를 능동적으로 캐시합니다. 이렇게 하면 특히 특정 알고리즘 및 대화형 쿼리의 성능을 향상시킬 수 있습니다.

 이 통합은 Amazon Redshift와 Amazon Redshift Serverless에서 데이터를 읽고 쓰는 Apache Spark 애플리케이션을 빌드할 수 있는 Spark 커넥터를 제공합니다. 이러한 애플리케이션은 애플리케이션 성능이나 데이터의 트랜잭션 일관성을 손상시키지 않습니다. 이 통합은 [Amazon EMR](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/) 및 [AWS Glue](https://docs.aws.amazon.com/glue/latest/dg/)에 자동으로 포함되므로 데이터 수집 및 변환 파이프라인의 일부로 Amazon Redshift에 데이터를 액세스하고 로드하는 Apache Spark 작업을 즉시 실행할 수 있습니다.

현재 이 통합과 함께 Spark 버전 3.3.x, 3.4.x, 3.5.x 및 4.0.0을 사용할 수 있습니다.

 이 통합은 다음을 제공합니다.
+  AWS Identity and Access Management(IAM) 인증. 자세한 내용은 [Amazon Redshift의 Identity and Access Management](https://docs.aws.amazon.com/redshift/latest/mgmt/redshift-iam-authentication-access-control.html)를 참조하세요.
+ 조건자 및 쿼리 푸시다운을 통한 성능 향상.
+  Amazon Redshift 데이터 형식.
+ Amazon Redshift와 Amazon Redshift Serverless에 대한 연결.

## Spark 커넥터 사용 시 고려 사항 및 제한 사항
<a name="spark-redshift-connector-considerations"></a>
+  tempdir URI는 Amazon S3 위치를 가리킵니다. 이 임시 디렉터리는 자동으로 정리되지 않으며 추가 비용이 발생할 수 있습니다. *Amazon Simple Storage Service 사용 설명서*의 [Amazon S3 수명 주기 정책](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html)을 사용하여 Amazon S3 버킷에 대한 보존 규칙을 정의하는 것이 좋습니다.
+  기본적으로 Amazon S3와 Redshift 간의 복사는 S3 버킷과 Redshift 클러스터가 서로 다른 AWS 리전에 있는 경우 작동하지 않습니다. 별도의 AWS 리전을 사용하려면 `tempdir_region` 파라미터를 `tempdir`에 사용되는 S3 버킷의 리전으로 설정합니다.
+ `tempformat` 파라미터를 사용하여 Parquet 데이터를 쓰는 경우 교차 리전은 S3와 Redshift 사이에 씁니다.
+ [Amazon S3 서버 측 암호화](https://docs.aws.amazon.com/AmazonS3/latest/userguide/serv-side-encryption.html)를 사용하여 사용된 Amazon S3 버킷을 암호화하는 것이 좋습니다.
+ [Amazon S3 버킷에 대한 퍼블릭 액세스를 차단](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html)하는 것이 좋습니다.
+  Amazon Redshift 클러스터는 공개적으로 액세스할 수 없도록 하는 것이 좋습니다.
+  [Amazon Redshift 감사 로깅](https://docs.aws.amazon.com/redshift/latest/mgmt/db-auditing.html)을 켜는 것이 좋습니다.
+  [Amazon Redshift 저장된 데이터 암호화](https://docs.aws.amazon.com/redshift/latest/mgmt/security-server-side-encryption.html)를 켜는 것이 좋습니다.
+  Amazon EMR의 Spark에서 Amazon Redshift로의 JDBC 연결에 대해 SSL을 켜는 것이 좋습니다.
+ Amazon Redshift 인증 파라미터에 대해 `aws_iam_role` 파라미터를 사용하여 IAM 역할을 전달하는 것이 좋습니다.

# Spark 커넥터를 사용한 인증
<a name="redshift-spark-connector-authentication"></a>

다음 다이어그램은 Amazon S3, Amazon Redshift, Spark 드라이버 및 Spark 실행기 간의 인증을 설명합니다.

![\[Spark 커넥터 인증 다이어그램입니다.\]](http://docs.aws.amazon.com/ko_kr/redshift/latest/mgmt/images/spark-connector-authentication.png)


## Redshift와 Spark 간의 인증
<a name="redshift-spark-authentication"></a>

 Amazon Redshift 제공 JDBC 드라이버 버전 2.x 드라이버를 사용해 로그인 자격 증명을 지정하여 Spark 커넥터로 Amazon Redshift에 연결할 수 있습니다. IAM을 사용하려면 [IAM 인증을 사용하도록 JDBC URL을 구성](https://docs.aws.amazon.com/redshift/latest/mgmt/generating-iam-credentials-configure-jdbc-odbc.html)하세요. Amazon EMR 또는 AWS Glue에서 Redshift 클러스터에 연결하려면 IAM 역할에 임시 IAM 자격 증명을 검색하는 데 필요한 권한이 있는지 확인하세요. 다음 목록은 IAM 역할이 자격 증명을 검색하고 Amazon S3 작업을 실행하는 데 필요한 모든 권한을 설명합니다.
+ [ Redshift:GetClusterCredentials](https://docs.aws.amazon.com/redshift/latest/APIReference/API_GetClusterCredentials.html)(프로비저닝된 Redshift 클러스터용)
+ [ Redshift:DescribeClusters](https://docs.aws.amazon.com/redshift/latest/APIReference/API_DescribeClusters.html)(프로비저닝된 Redshift 클러스터용)
+ [ Redshift:GetWorkgroup](https://docs.aws.amazon.com/redshift-serverless/latest/APIReference/API_GetWorkgroup.html)(Amazon Redshift Serverless 작업 그룹)
+ [ Redshift:GetCredentials](https://docs.aws.amazon.com/redshift-serverless/latest/APIReference/API_GetCredentials.html)(Amazon Redshift Serverless 작업 그룹)
+ [ s3:ListBucket](https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListBuckets.html)
+ [ s3:GetBucket](https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_GetBucket.html)
+ [ s3:GetObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html)
+ [ s3:PutObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html)
+ [ s3:GetBucketLifecycleConfiguration](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketLifecycleConfiguration.html)

 GetClusterCredentials에 대한 자세한 내용은 [GetClusterCredentials에 대한 IAM 정책](https://docs.aws.amazon.com/redshift/latest/mgmt/redshift-iam-access-control-identity-based.html#redshift-policy-resources.getclustercredentials-resources)을 참조하세요.

또한 `COPY` 및 `UNLOAD` 작업 중에 Amazon Redshift가 IAM 역할을 맡을 수 있는지 확인해야 합니다.

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "redshift.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}
```

------

최신 JDBC 드라이버를 사용하는 경우 드라이버는 Amazon Redshift 자체 서명 인증서에서 ACM 인증서로의 전환을 자동으로 관리합니다. 하지만 [JDBC URL에 SSL 옵션을 지정](https://docs.aws.amazon.com/redshift/latest/mgmt/jdbc20-configuration-options.html#jdbc20-ssl-option)해야 합니다.

 다음은 Amazon Redshift에 연결하기 위해 JDBC 드라이버 URL 및 `aws_iam_role`을 지정하는 방법의 예입니다.

```
df.write \
  .format("io.github.spark_redshift_community.spark.redshift ") \
  .option("url", "jdbc:redshift:iam://<the-rest-of-the-connection-string>") \
  .option("dbtable", "<your-table-name>") \
  .option("tempdir", "s3a://<your-bucket>/<your-directory-path>") \
  .option("aws_iam_role", "<your-aws-role-arn>") \
  .mode("error") \
  .save()
```

## Amazon S3와 Spark 간의 인증
<a name="spark-s3-authentication"></a>

 IAM 역할을 사용하여 Spark와 Amazon S3 간에 인증하는 경우 다음 방법 중 하나를 사용하세요.
+ Java용 AWS SDK는 DefaultAWSCredentialsProviderChain 클래스에 의해 구현된 기본 자격 증명 공급자 체인을 사용하여 자동으로 AWS 자격 증명을 찾으려고 시도합니다. 자세한 내용은 [기본 자격 증명 공급자 체인 사용](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html#credentials-default)을 참조하세요.
+ [Hadoop 구성 속성](https://github.com/apache/hadoop/blob/trunk/hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/index.md)을 통해 AWS 키를 지정할 수 있습니다. 예를 들어 `tempdir` 구성이 `s3n://` 파일 시스템을 가리키는 경우 Hadoop XML 구성 파일에서 `fs.s3n.awsAccessKeyId` 및 `fs.s3n.awsSecretAccessKey` 속성을 설정하거나 `sc.hadoopConfiguration.set()`을 호출하여 Spark의 전역 Hadoop 구성을 변경합니다.

예를 들어 s3n 파일 시스템을 사용하는 경우 다음을 추가합니다.

```
sc.hadoopConfiguration.set("fs.s3n.awsAccessKeyId", "YOUR_KEY_ID")
sc.hadoopConfiguration.set("fs.s3n.awsSecretAccessKey", "YOUR_SECRET_ACCESS_KEY")
```

s3a 파일 시스템을 사용하는 경우 다음을 추가합니다.

```
sc.hadoopConfiguration.set("fs.s3a.access.key", "YOUR_KEY_ID")
sc.hadoopConfiguration.set("fs.s3a.secret.key", "YOUR_SECRET_ACCESS_KEY")
```

Python을 사용하는 경우 다음 작업을 사용합니다.

```
sc._jsc.hadoopConfiguration().set("fs.s3n.awsAccessKeyId", "YOUR_KEY_ID")
sc._jsc.hadoopConfiguration().set("fs.s3n.awsSecretAccessKey", "YOUR_SECRET_ACCESS_KEY")
```
+ `tempdir` URL에서 인증 키를 인코딩합니다. 예를 들어 URI `s3n://ACCESSKEY:SECRETKEY@bucket/path/to/temp/dir`은 키 쌍(`ACCESSKEY`, `SECRETKEY`)을 인코딩합니다.

## Redshift와 Amazon S3 간의 인증
<a name="redshift-s3-authentication"></a>

 쿼리에서 COPY 및 UNLOAD 명령을 사용하는 경우 사용자 대신 쿼리를 실행할 수 있도록 Amazon Redshift에 대한 Amazon S3 액세스 권한도 부여해야 합니다. 이렇게 하려면 먼저 [다른 AWS 서비스에 액세스할 수 있도록 Amazon Redshift에 권한을 부여](https://docs.aws.amazon.com/redshift/latest/mgmt/authorizing-redshift-service.html)한 다음 [IAM 역할을 사용하여 COPY 및 UNLOAD 작업에 권한을 부여](https://docs.aws.amazon.com/redshift/latest/mgmt/copy-unload-iam-role.html)합니다.

가장 좋은 방법은 권한 정책을 IAM 역할에 연결한 다음 필요에 따라 사용자 및 그룹에 할당하는 것입니다. 자세한 내용은 [Amazon Redshift의 Identity and Access Management](https://docs.aws.amazon.com/redshift/latest/mgmt/redshift-iam-authentication-access-control.html)를 참조하세요.

## 와의 통합AWS Secrets Manager
<a name="redshift-secrets-manager-authentication"></a>

AWS Secrets Manager에 저장된 시크릿에서 Redshift 사용자 이름 및 암호 보안 인증 정보를 검색할 수 있습니다. Redshift 보안 인증을 자동으로 제공하려면 `secret.id` 파라미터를 사용하세요. Redshift 보안 인증 시크릿을 만드는 방법에 대한 자세한 내용은 [AWS Secrets Manager 데이터베이스 보안 암호 생성](https://docs.aws.amazon.com/secretsmanager/latest/userguide/create_database_secret.html)을 참조하세요.

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/redshift/latest/mgmt/redshift-spark-connector-authentication.html)

**참고**  
 인정 조항: 이 문서에는 [Apache 2.0 라이선스](https://www.apache.org/licenses/LICENSE-2.0)에 따라 라이선스가 부여된 [Apache Software Foundation](http://www.apache.org/)에서 개발한 샘플 코드 및 언어가 포함되어 있습니다.

# 푸시다운을 통한 성능 향상
<a name="spark-redshift-connector-pushdown"></a>

 Spark 커넥터는 조건자 및 쿼리 푸시다운을 자동으로 적용하여 성능을 최적화합니다. 이 지원은 쿼리에서 지원되는 함수를 사용하는 경우 Spark 커넥터가 함수를 SQL 쿼리로 변환하고 Amazon Redshift에서 쿼리를 실행함을 의미합니다. 이 최적화로 인해 검색되는 데이터가 적어지므로 Apache Spark는 더 적은 데이터를 처리하고 더 나은 성능을 가질 수 있습니다. 기본적으로 푸시다운은 자동으로 활성화됩니다. 비활성화하려면 `autopushdown`을 false로 설정하세요.

```
import sqlContext.implicits._val 
 sample= sqlContext.read
    .format("io.github.spark_redshift_community.spark.redshift")
    .option("url",jdbcURL )
    .option("tempdir", tempS3Dir)
    .option("dbtable", "event")
    .option("autopushdown", "false")
    .load()
```

 푸시다운에서는 다음 함수가 지원됩니다. 이 목록에 없는 함수를 사용하는 경우 Spark 커넥터는 Amazon Redshift 대신 Spark에서 함수를 수행하므로 성능이 최적화되지 않습니다. Spark의 전체 함수 목록은 [내장 함수](https://spark.apache.org/docs/latest/api/sql/index.html)를 참조하세요.
+ 집계 함수
  + avg
  + count
  + 최대
  + min
  + sum
  + stddev\$1samp
  + stddev\$1pop
  + var\$1samp
  + var\$1pop
+ 부울 연산자
  + in
  + isnull
  + isnotnull
  + contains
  + endswith
  + startswith
+ 논리 연산자
  + 및
  + 또는
  + not(또는 \$1)
+ 수학 함수
  + \$1
  + -
  + \$1
  + /
  + -(단항)
  + abs
  + acos
  + asin
  + atan
  + ceil
  + cos
  + exp
  + floor
  + greatest
  + least
  + log10
  + pi
  + pow
  + round
  + sin
  + sqrt
  + tan
+ 기타 함수
  + cast
  + coalesce
  + decimal
  + 다음과 같은 경우
  + in
+ 관계형 연산자
  + \$1=
  + =
  + >
  + >=
  + <
  + <=
+ 문자열 함수
  + ASCII
  + lpad
  + rpad
  + translate
  + upper
  + lower
  + length
  + trim
  + ltrim
  + rtrim
  + like
  + substring
  + concat
+ 시간 및 날짜 함수
  + add\$1months
  + 날짜
  + date\$1add
  + date\$1sub
  + date\$1trunc
  + timestamp
  + trunc
+ 수학적 연산
  + CheckOverflow
  + 정밀성 증진
+ 관계형 연산
  + Aliases(예: AS)
  + 사례: 언제
  + Distinct
  + InSet
  + Joins and cross joins
  + 한도
  + Unions, union all
  + ScalarSubquery
  + Sorts(오름차순 및 내림차순)
  + UnscaledValue

# 기타 구성 옵션
<a name="spark-redshift-connector-other-config"></a>

이 페이지에서 Amazon Redshift Spark 커넥터에 지정할 수 있는 옵션에 관한 설명을 확인합니다.

## 문자열 열의 최대 크기
<a name="spark-redshift-connector-other-config-max-size"></a>

Redshift는 VARCHAR(256)로 저장되는 테이블 생성 시 문자열 열을 텍스트 열로 생성합니다. 더 큰 크기를 지원하는 열을 원하면 maxlength를 사용하여 문자열 열의 최대 길이를 지정할 수 있습니다. 다음은 `maxlength`를 지정하는 방법의 예입니다.

```
columnLengthMap.foreach { case (colName, length) =>
  val metadata = new MetadataBuilder().putLong("maxlength", length).build()
  df = df.withColumn(colName, df(colName).as(colName, metadata))
}
```

## 열 유형
<a name="spark-redshift-connector-other-config-column-type"></a>

열 유형을 설정하려면 `redshift_type` 필드를 사용합니다.

```
columnTypeMap.foreach { case (colName, colType) =>
  val metadata = new MetadataBuilder().putString("redshift_type", colType).build()
  df = df.withColumn(colName, df(colName).as(colName, metadata))
}
```

## 열에 대한 압축 인코딩
<a name="spark-redshift-connector-other-config-compression-encoding"></a>

 열에서 특정 압축 인코딩을 사용하려면 인코딩 필드를 사용하세요. 지원되는 압축 인코딩의 전체 목록은 [압축 인코딩](https://docs.aws.amazon.com/redshift/latest/dg/c_Compression_encodings.html)을 참조하세요.

## 열에 대한 설명
<a name="spark-redshift-connector-other-config-description"></a>

설명을 설정하려면 `description` 필드를 사용합니다.

## Redshift와 Amazon S3 간의 인증
<a name="spark-redshift-connector-other-config-unload-as-text"></a>

 기본적으로 결과는 Parquet 형식으로 Amazon S3에 언로드됩니다. 파이프로 구분된 텍스트 파일로 결과를 언로드하려면 다음 옵션을 지정합니다.

```
.option("unload_s3_format", "TEXT")
```

## 푸시다운 문
<a name="spark-redshift-connector-other-config-lazy-pushdown"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/redshift/latest/mgmt/spark-redshift-connector-other-config.html)

## 커넥터 파라미터
<a name="spark-redshift-connector-other-config-spark-parameters"></a>

Spark SQL의 파라미터 맵 또는 `OPTIONS`는 다음 설정을 지원합니다.

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/redshift/latest/mgmt/spark-redshift-connector-other-config.html)

**참고**  
 인정 조항: 이 문서에는 [Apache 2.0 라이선스](https://www.apache.org/licenses/LICENSE-2.0)에 따라 라이선스가 부여된 [Apache Software Foundation](http://www.apache.org/)에서 개발한 샘플 코드 및 언어가 포함되어 있습니다.

# 지원되는 데이터 유형
<a name="spark-redshift-connector-data-types"></a>

Amazon Redshift의 다음 데이터 형식은 Spark 커넥터에서 지원됩니다. Amazon Redshift에서 지원되는 데이터 형식의 전체 목록은 [데이터 유형](https://docs.aws.amazon.com//redshift/latest/dg/c_Supported_data_types.html)을 참조하세요. 아래 테이블에 없는 데이터 형식은 Spark 커넥터에서 지원되지 않습니다.

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/redshift/latest/mgmt/spark-redshift-connector-data-types.html)

## 복잡한 데이터 형식
<a name="spark-redshift-connector-complex-data-types"></a>

 spark 커넥터를 사용하여 `ArrayType`, `MapType`, `StructType`과 같은 Spark 복합 데이터 형식을 Redshift SUPER 데이터 형식 열에 읽고 쓸 수 있습니다. 읽기 작업 중에 스키마를 제공하는 경우 열의 데이터는 중첩된 형식을 포함하여 Spark에서 해당 복합 형식으로 변환됩니다 또한 `autopushdown`을 활성화하면 중첩된 속성, 맵 값 및 배열 인덱스의 투영이 Redshift로 푸시다운되므로 데이터의 일부만 액세스할 때 중첩된 전체 데이터 구조를 더 이상 언로드할 필요가 없습니다.

커넥터에서 데이터 프레임을 작성할 때 `MapType`(`StringType` 사용), `StructType` 또는 `ArrayType` 형식의 모든 열은 Redshift SUPER 데이터 형식 열에 기록됩니다. 이러한 중첩된 데이터 구조를 작성할 때 `tempformat` 파라미터는 `CSV`, `CSV GZIP` 또는 `PARQUET` 형식이어야 합니다. `AVRO`를 사용하면 예외가 발생합니다. 키 형식이 `StringType`이 아닌 `MapType` 데이터 구조를 작성하는 경우에도 예외가 발생합니다.

### StructType
<a name="spark-redshift-connector-complex-data-types-examples-structtype"></a>

다음 예제에서는 구조체를 포함하는 SUPER 데이터 형식으로 테이블을 만드는 방법을 보여 줍니다.

```
create table contains_super (a super);
```

그런 다음 커넥터를 사용하여 다음 예제와 같은 스키마를 사용하여 테이블의 SUPER 열 `a`에서 `StringType` 필드 `hello`를 쿼리할 수 있습니다.

```
import org.apache.spark.sql.types._

val sc = // existing SparkContext
val sqlContext = new SQLContext(sc)

val schema = StructType(StructField("a", StructType(StructField("hello", StringType) ::Nil)) :: Nil)

val helloDF = sqlContext.read
.format("io.github.spark_redshift_community.spark.redshift")
.option("url", jdbcURL )
.option("tempdir", tempS3Dir)
.option("dbtable", "contains_super")
.schema(schema)
.load().selectExpr("a.hello")
```

다음 예제는 열 `a`에 구조체를 작성하는 방법을 보여줍니다.

```
import org.apache.spark.sql.types._
import org.apache.spark.sql._

val sc = // existing SparkContext
val sqlContext = new SQLContext(sc)

val schema = StructType(StructField("a", StructType(StructField("hello", StringType) ::Nil)) :: Nil)
val data = sc.parallelize(Seq(Row(Row("world"))))
val mydf = sqlContext.createDataFrame(data, schema)

mydf.write.format("io.github.spark_redshift_community.spark.redshift").
option("url", jdbcUrl).
option("dbtable", tableName).
option("tempdir", tempS3Dir).
option("tempformat", "CSV").
mode(SaveMode.Append).save
```

### MapType
<a name="spark-redshift-connector-complex-data-types-examples-maptype"></a>

`MapType`을 사용하여 데이터를 표현하려는 경우 스키마에서 `MapType` 데이터 구조를 사용하여 맵의 키에 해당하는 값을 검색할 수 있습니다. `MapType` 데이터 구조의 모든 키는 문자열 형식이어야 하며 모든 값은 int와 같은 동일한 형식이어야 한다는 점에 유의합니다.

다음 예는 열 `hello`에서 hello 키의 값을 가져오는 방법을 보여 줍니다.

```
import org.apache.spark.sql.types._

val sc = // existing SparkContext
val sqlContext = new SQLContext(sc)

val schema = StructType(StructField("a", MapType(StringType, IntegerType))::Nil)

val helloDF = sqlContext.read
    .format("io.github.spark_redshift_community.spark.redshift")
    .option("url", jdbcURL )
    .option("tempdir", tempS3Dir)
    .option("dbtable", "contains_super")
    .schema(schema)
    .load().selectExpr("a['hello']")
```

### ArrayType
<a name="spark-redshift-connector-complex-data-types-examples-arraytype"></a>

열에 구조체 대신 배열이 포함된 경우 커넥터를 사용하여 배열의 첫 번째 요소를 쿼리할 수 있습니다.

```
import org.apache.spark.sql.types._

val sc = // existing SparkContext
val sqlContext = new SQLContext(sc)

val schema = StructType(StructField("a", ArrayType(IntegerType)):: Nil)

val helloDF = sqlContext.read
    .format("io.github.spark_redshift_community.spark.redshift")
    .option("url", jdbcURL )
    .option("tempdir", tempS3Dir)
    .option("dbtable", "contains_super")
    .schema(schema)
    .load().selectExpr("a[0]")
```

### 제한 사항
<a name="spark-redshift-connector-complex-data-types-limitations"></a>

복잡한 데이터 형식을 Spark 커넥터와 함께 사용하면 다음과 같은 제한 사항이 있습니다.
+ 중첩된 모든 구조체 필드 이름과 맵 키는 소문자여야 합니다. 대문자가 포함된 복잡한 필드 이름을 쿼리하는 경우 스키마를 생략하고 `from_json` spark 함수를 사용하여 반환된 문자열을 로컬로 변환하는 해결 방법을 시도해 볼 수 있습니다.
+ 읽기 또는 쓰기 작업에 사용되는 모든 맵 필드에는 `StringType` 키만 있어야 합니다.
+ 복잡한 형식을 Redshift에 쓰기 위한 임시 형식 값은 `CSV`, `CSV GZIP` 및 `PARQUET `만 지원됩니다. `AVRO `를 사용하려고 하면 예외가 발생합니다.