> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-detect-table-modification.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Fabric OneLake

> 이 가이드에서는 Microsoft OneLake의 데이터를 쿼리하는 방법을 단계별로 안내합니다.

export const galaxyOnClick = eventName => () => {
  try {
    if (typeof window !== "undefined" && window.galaxy && eventName) {
      window.galaxy.track(eventName, {
        interaction: "click"
      });
    }
  } catch (e) {}
};

export const BetaBadge = ({link, galaxyTrack, galaxyEvent}) => {
  if (link) {
    return <a href={link} target="_blank" rel="noopener noreferrer" className="betaBadge" onClick={galaxyTrack && galaxyEvent ? galaxyOnClick(galaxyEvent) : undefined}>
                <Icon />
                <span>베타</span>
            </a>;
  }
  return <div className="betaBadge">
            <Icon />
            <span>
                베타 기능. 
                <u>
                    <a href="/docs/beta-and-experimental-features#beta-features">
                        자세히 보기.
                    </a>
                </u>
            </span>
        </div>;
};

ClickHouse는 여러 카탈로그(OneLake, Unity, Glue, Polaris 등)와의 통합을 지원합니다. 이 가이드에서는 ClickHouse와 [OneLake](https://learn.microsoft.com/en-us/fabric/onelake/onelake-overview)를 사용해 Microsoft OneLake에 저장된 데이터를 쿼리하는 방법을 안내합니다.

Microsoft OneLake는 lakehouse에 대해 여러 테이블 포맷을 지원합니다. ClickHouse를 사용하면 Iceberg 테이블을 쿼리할 수 있습니다.

<Note>
  이 기능은 베타이므로 다음 설정을 활성화해야 합니다:
  `SET allow_database_iceberg = 1;`
</Note>

<div id="gathering-requirements">
  ## OneLake 요구 사항 준비
</div>

Microsoft Fabric에서 테이블을 쿼리하기 전에 다음 정보를 준비해야 합니다:

* OneLake 테넌트 ID(Entra ID)
* 애플리케이션(클라이언트) ID
* 클라이언트 시크릿
* 웨어하우스 ID 및 데이터 항목 ID

웨어하우스 ID는 워크스페이스 ID입니다.

데이터 항목 ID로는 Lakehouse ID를 사용하는 것을 권장합니다. 테스트 결과, Warehouse ID로는 작동하지 않았습니다.

이 값들을 찾는 방법은 [Microsoft OneLake 문서](http://learn.microsoft.com/en-us/fabric/onelake/table-apis/table-apis-overview#prerequisites)를 참조하십시오.

<div id="creating-a-connection-between-unity-catalog-and-clickhouse">
  ## OneLake와 ClickHouse 연결 만들기
</div>

위의 필수 정보를 준비했다면 이제 Microsoft OneLake와 ClickHouse 간의 연결을 만들 수 있습니다. 다만 그 전에 카탈로그를 활성화해야 합니다:

```sql theme={null}
SET allow_database_iceberg=1
```

<div id="connect-onelake">
  ### OneLake에 연결하기
</div>

```sql theme={null}
CREATE DATABASE onelake_catalog
ENGINE = DataLakeCatalog('https://onelake.table.fabric.microsoft.com/iceberg')
SETTINGS
catalog_type = 'onelake',
warehouse = 'warehouse_id/data_item_id',
onelake_tenant_id = '<tenant_id>',
oauth_server_uri = 'https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token',
auth_scope = 'https://storage.azure.com/.default',
onelake_client_id = '<client_id>',
onelake_client_secret = '<client_secret>'
```

<div id="querying-onelake-using-clickhouse">
  ## ClickHouse를 사용해 OneLake 쿼리하기
</div>

이제 연결이 완료되었으므로 OneLake에 쿼리를 실행할 수 있습니다:

```sql theme={null}
SHOW TABLES FROM onelake_catalog
```

```response theme={null}
Query id: 8f6124c4-45c2-4351-b49a-89dc13e548a7

   ┌─name──────────────────────────┐
1. │ year_2017.green_tripdata_2017 │
2. │ year_2018.green_tripdata_2018 │
3. │ year_2019.green_tripdata_2019 │
4. │ year_2020.green_tripdata_2020 │
5. │ year_2022.green_tripdata_2022 │
   └───────────────────────────────┘
```

Iceberg 클라이언트를 사용하면 Uniform이 활성화된 Delta 테이블만 표시됩니다:

테이블을 쿼리하려면:

```sql theme={null}
SELECT *
FROM onelake_catalog.`year_2017.green_tripdata_2017`
LIMIT 1
```

```response theme={null}
Query id: db6b4bda-cc58-4ca1-8891-e0d14f02c890

Row 1:
──────
VendorID:              2
lpep_pickup_datetime:  2017-05-18 16:55:43.000000
lpep_dropoff_datetime: 2017-05-18 18:04:11.000000
store_and_fwd_flag:    N
RatecodeID:            2
PULocationID:          130
DOLocationID:          48
passenger_count:       2
trip_distance:         12.43
fare_amount:           52
extra:                 4.5
mta_tax:               0.5
tip_amount:            0
tolls_amount:          33
ehail_fee:             ᴺᵁᴸᴸ
improvement_surcharge: 0.3
total_amount:          90.3
payment_type:          2
trip_type:             1
congestion_surcharge:  ᴺᵁᴸᴸ
source_file:           green_tripdata_2017-05.parquet
```

<Info>
  **백틱이 필요합니다**

  ClickHouse는 여러 네임스페이스를 지원하지 않으므로 백틱이 필요합니다.
</Info>

테이블 DDL을 확인하려면:

```sql theme={null}
SHOW CREATE TABLE onelake_catalog.`year_2017.green_tripdata_2017`
```

```response theme={null}
Query id: 8bd5bd8e-83be-453e-9a88-32de12ba7f24

   ┌─statement───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
1. │ CREATE TABLE onelake_catalog.`year_2017.green_tripdata_2017`                                                                                                               ↴│
   │↳(                                                                                                                                                                          ↴│
   │↳    `VendorID` Nullable(Int64),                                                                                                                                            ↴│
   │↳    `lpep_pickup_datetime` Nullable(DateTime64(6, 'UTC')),                                                                                                                 ↴│
   │↳    `lpep_dropoff_datetime` Nullable(DateTime64(6, 'UTC')),                                                                                                                ↴│
   │↳    `store_and_fwd_flag` Nullable(String),                                                                                                                                 ↴│
   │↳    `RatecodeID` Nullable(Int64),                                                                                                                                          ↴│
   │↳    `PULocationID` Nullable(Int64),                                                                                                                                        ↴│
   │↳    `DOLocationID` Nullable(Int64),                                                                                                                                        ↴│
   │↳    `passenger_count` Nullable(Int64),                                                                                                                                     ↴│
   │↳    `trip_distance` Nullable(Float64),                                                                                                                                     ↴│
   │↳    `fare_amount` Nullable(Float64),                                                                                                                                       ↴│
   │↳    `extra` Nullable(Float64),                                                                                                                                             ↴│
   │↳    `mta_tax` Nullable(Float64),                                                                                                                                           ↴│
   │↳    `tip_amount` Nullable(Float64),                                                                                                                                        ↴│
   │↳    `tolls_amount` Nullable(Float64),                                                                                                                                      ↴│
   │↳    `ehail_fee` Nullable(Float64),                                                                                                                                         ↴│
   │↳    `improvement_surcharge` Nullable(Float64),                                                                                                                             ↴│
   │↳    `total_amount` Nullable(Float64),                                                                                                                                      ↴│
   │↳    `payment_type` Nullable(Int64),                                                                                                                                        ↴│
   │↳    `trip_type` Nullable(Int64),                                                                                                                                           ↴│
   │↳    `congestion_surcharge` Nullable(Float64),                                                                                                                              ↴│
   │↳    `source_file` Nullable(String)                                                                                                                                         ↴│
   │↳)                                                                                                                                                                          ↴│
   │↳ENGINE = Iceberg('abfss://<warehouse_id>@onelake.dfs.fabric.microsoft.com/<data_item_id>/Tables/year_2017/green_tripdata_2017') │
   └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

<div id="loading-data-from-onelake-into-clickhouse">
  ## 데이터 레이크에서 ClickHouse로 데이터 로드하기
</div>

OneLake에서 ClickHouse로 데이터를 로드해야 하는 경우:

```sql theme={null}
CREATE TABLE trips
ENGINE = MergeTree
ORDER BY coalesce(VendorID, 0)
AS SELECT *
FROM onelake_catalog.`year_2017.green_tripdata_2017`
```

```response theme={null}
Query id: d15983a6-ef6a-40fe-80d5-19274b9fe328

Ok.

0 rows in set. Elapsed: 32.570 sec. Processed 11.74 million rows, 275.37 MB (360.36 thousand rows/s., 8.45 MB/s.)
Peak memory usage: 1.31 GiB.
```
