문서 메뉴

문서 홈보기 & 데이터 분석BI 커넥터

문서 관계형 정의 언어

이 페이지의 내용

  • 파일 형식
  • 필드 유형
  • 포함된 문서
  • 사용자 지정 필터
  • 집계 파이프라인

문서 관계형 정의 언어(DRDL)는 MongoDB 스키마의 관계형 뷰를 정의합니다.

mongodrdl 는 MongoDB collection에서 문서를 샘플링하고 해당 문서에서 DRDL 파일을 파생합니다. 그런 다음 mongosqld 은(는) DRDL 파일에 정의된 스키마를 사용하여 MySQL 클라이언트가 MongoDB 데이터를 쿼리할 수 있도록 허용합니다.

파일은 DRDL YAML 의 데이터베이스, 테이블 및 열을 나열합니다. 형식.

schema:
- db: <database name>
tables:
- table: <SQL table name>
collection: <MongoDB collection name>
pipeline:
- <optional pipeline elements>
columns:
- Name: <MongoDB field name>
MongoType: <MongoDB field type>
SqlName: <mapped SQL column name>
SqlType: <mapped SQL column type>

test 데이터베이스의 abc 컬렉션에 다음과 같은 형태의 문서가 주어집니다:

{
"_id": ObjectId(),
"close": 7.45,
"detail": { "a": 2, "b": 3 }
}

mongodrdl 를 실행하여 이 collection을 기반으로 스키마를 생성합니다.

mongodrdl -d test -c abc -o schema.drdl

생성된 스키마 파일(schema.drdl)은 다음과 유사하게 표시됩니다:

schema:
- db: test
tables:
- table: abc
collection: abc
pipeline: []
columns:
- Name: _id
MongoType: bson.ObjectId
SqlName: _id
SqlType: varchar
- Name: close
MongoType: float64
SqlName: close
SqlType: numeric
- Name: detail.a
MongoType: float64
SqlName: detail.a
SqlType: numeric
- Name: detail.b
MongoType: float64
SqlName: detail.b
SqlType: numeric

BI Connector는 항상 동일한 데이터 유형을 포함하는 필드를 관계형 모델에 매핑합니다. 스키마 생성은 특히 다음과 같은 경우를 다룹니다.

숫자

BI Connector는 샘플링된 문서와 일치하는 가장 정확한 숫자 유형을 사용합니다.

collection의 필드에 항상 동일한 데이터 유형이 있는 경우 BI Connector는 해당 유형을 사용합니다.

collection의 필드에 부동 소수점 값이나 정수가 포함될 수 있는 경우 BI Connector는 numeric 유형을 사용합니다.

날짜
BI Connector는 data_date 유형의 모든 필드를 SQL timestamp 유형으로 취급합니다.
타임스탬프
BI Connector는 data_timestamp 유형의 모든 필드를 무시합니다.
객체 ID
BI Connector는 data_oid 유형의 모든 필드를 SQL 유형 varchar 로 취급합니다.
UUID
BI Connector는 UUID 유형의 모든 필드를 SQL 유형 varchar 으로 취급합니다.
지리 공간

컬렉션에 지리 공간적 인덱스 가 포함된 경우 BI Connector는 인덱싱된 필드를 숫자 경도-위도 좌표 배열에 매핑합니다.

예는 지리 공간적 데이터 를 참조하세요.

참고

이기종 필드

필드에 일치하지 않는 유형이 포함된 경우 BI Connector는 가장 자주 샘플링된 유형을 선택합니다.

필드에 해당 유형의 유형 또는 배열이 포함될 수 있는 경우, 생성된 스키마는 항상 필드에 배열이 포함되도록 지정합니다.

다음도 참조하세요.

BI Connector는 내장된 문서를 . 구분 문자가 있는 간단한 필드에 매핑하여 MongoDB 쿼리에서 점 표기법 을 사용하여 참조하는 방식과 유사하게 표시합니다.

Tableau 는 식별자를 올바르게 따옴표로 묶지만, 임시 SQL 표현식 내에서는 . 자 또는 대소문자 혼합 문자가 포함된 모든 식별자를 큰따옴표로 묶어야 합니다.

다음 문서를 살펴보세요.

{
"_id": 1,
"familyName": "Partridge",
"hometown" : "Hollywood Hills",
"address" : { "street": "123 Main Street",
"city" : "Hollywood",
"state" : "CA",
"zip" : "90210" },
"members_since" : ISODate("2002-04-12T00:00:00Z")
}

이 문서가 포함된 collection에서 mongodrdl 를 실행하면 생성된 스키마에 다음 필드가 생성됩니다.

_id
numeric
familyName
varchar
hometown
varchar
address.street
varchar
address.city
varchar
address.state
varchar
address.zip
varchar
members_since
timestamp

BI Connector는 배열이 없는 collection과 배열 요소당 문서가 하나씩 있는 collection, 이렇게 두 collection을 사용하여 비즈니스 인텔리전스 도구에 배열을 노출합니다.

다음 문서가 포함된 families 이라는 컬렉션에서 mongodrdl 를 실행하는 경우:

{
"_id": 1,
"familyName": "Partridge",
"hometown" : "Hollywood Hills",
"familyMembers" : [
{
"firstname" : "Shirley",
"age" : 42,
"attributes" : [
{ "name" : "instrument", "value" : "singer" },
{ "name" : "role", "value" : "mom" }
]
},
{
"firstname" : "Keith",
"age" : 18,
"attributes" : [
{ "name" : "instrument", "value" : "guitar" },
{ "name" : "role", "value" : "son" }
]
},
{
"firstname" : "Laurie",
"age" : 16,
"attributes" : [
{ "name" : "instrument", "value" : "keyboard" },
{ "name" : "role", "value" : "sister" }
]
}]
}

그 결과 다음과 같은 세 개의 테이블이 생성됩니다.

families
_id
numeric
familyName
varchar
hometown
varchar
families_familyMembers
_id
numeric
familyMembers.age
numeric
familyMembers.firstname
varchar
familyMembers_idx
numeric
families_familyMembers_attributes
_id
numeric
familyMembers.attributes.name
varchar
familyMembers.attributes.value
varchar
familyMembers.attributes_idx
numeric
familyMembers_idx
numeric

이러한 테이블을 함께 조인하여 비정규화된 형식으로 데이터를 볼 수 있습니다. 예를 들어, 다음 쿼리를 사용하여 위의 스키마에 이름이 지정된 사람들을 해당 가족 정보와 함께 나열할 수 있습니다.

SELECT f.*, m.`familyMembers.firstname`
FROM families_familyMembers m
JOIN families f
ON m._id = f._id;

--preJoined 에 옵션을 제공하면 BI Connector는 포함 문서의 필드를 각 배열 요소의 문서에 추가하여 테이블을 "사전 조인"합니다.mongodrdl

이전 예의 경우 테이블에 다음과 같은 추가 열이 포함됩니다.

families_familyMembers
familyName
varchar
hometown
varchar
families_familyMembers_attributes
familyMembers.age
numeric
familyMembers.firstname
varchar
familyMembers_idx
numeric
familyName
varchar
hometown
varchar

DRDL 파일의 컬렉션에 mongo.Filter 유형의 열을 추가할 수 있습니다. 이 열 유형을 사용하면 사용자 지정 $match 쿼리를 수행할 수 있습니다.

예를 들어, 최대 3개의 구성 요소로 구성된 점 cloud를 설명하는 다음 스키마가 있다고 가정해 보겠습니다.

schema:
- db: test
tables:
- table: points
collection: points
pipeline: []
columns:
- Name: _id
MongoType: bson.ObjectId
SqlName: _id
SqlType: varchar
- Name: x
MongoType: float64
SqlName: x
SqlType: numeric
- Name: "y"
MongoType: float64
SqlName: "y"
SqlType: numeric
- Name: z
MongoType: float64
SqlName: z
SqlType: numeric
- Name: filter
MongoType: mongo.Filter
SqlName: filter
SqlType: varchar

다음 쿼리를 사용하여 3차원 점만 선택할 수 있습니다.

SELECT x, y, z
FROM points
WHERE filter='{"z": {"$exists": true}}';

MongoDB 3.4 에는 호환되지 않는 데이터를 필터링하는 데 사용할 수 있는 읽기 전용 보기 가 도입되었습니다.

예를 들어, grades collection의 grade 필드에 숫자가 포함된 문서만 포함하는 test 데이터베이스에 뷰를 만들 수 있습니다.

db.runCommand( { create: "numericGrades", viewOn: "grades", pipeline: [ { "$match": { "grade": { "$type": "number" } } } ] } )

그런 다음 mongodrdl 를 사용하여 collection을 생성하는 것처럼 이 뷰에서 스키마를 생성할 수 있습니다.

mongodrdl -d test -c numericGrades

BI Connector는 스키마의 일부로 집계 파이프라인 을 사용하여 컬렉션의 문서를 관계형 테이블에 적합한 형식으로 변환할 수 있습니다.

예를 들어 simpleFamilies 컬렉션의 간단한 문서를 가정해 보겠습니다.

{
"_id": 1,
"familyName": "Partridge",
"familyMembers" : [ "Shirley", "Keith", "Laurie"]
}

mongodrdlsimpleFamiliessimpleFamilies_familyMembers 테이블이 있는 스키마를 생성합니다.

simpleFamilies_familyMembers 테이블에는 각 패밀리 멤버가 열거되며 다음과 같은 파이프라인이 있습니다.

pipeline:
- $unwind:
includeArrayIndex: familyMembers_idx
path: $familyMembers

이 파이프라인은 $unwind 를 사용하여 familyMembers 의 각 멤버에 대한 새 레코드를 생성합니다. 스키마는 familyMembers_idx 필드의 배열 인덱스를 추적합니다.

컬렉션에 2d 또는 2dsphere 지리 공간적 인덱스 가 포함된 경우 BI Connector는 인덱싱된 필드를 숫자 경도-위도 좌표 배열에 매핑합니다.

다음 collection이 주어집니다:

db.points.createIndex( { pos : "2dsphere" } )
db.points.insertOne({
pos : { type: "Point", coordinates: [ -73.97, 40.77 ] },
name: "Central Park",
category : "Parks"
})

BI Connector는 다음 스키마를 생성합니다.

schema:
- db: test
tables:
- table: points
collection: points
pipeline: []
columns:
- Name: _id
MongoType: bson.ObjectId
SqlName: _id
SqlType: varchar
- Name: category
MongoType: string
SqlName: category
SqlType: varchar
- Name: name
MongoType: string
SqlName: name
SqlType: varchar
- Name: pos.coordinates
MongoType: geo.2darray
SqlName: pos.coordinates
SqlType: numeric[]
← BI Connector용 TLS 구성