创建一个与MongoDB和Teiid一起使用的模式,该模式在文档中有一个mongo数组

时间:2014-06-16 17:21:04

标签: mongodb schema teiid

我在MongoDB中有以下文档:

{
    "_id" : ObjectId("529632350083bc14d145bb56"),
    "CaseId" : "8f68cf65-80ad-4950-88d5-e322d0296461",
    "CaseAddressString" : "527 Irving Avenue, Rivereno",
    "CaseOpenDatetime" : ISODate("2013-11-22T17:54:50.198Z"),
    "CaseBeginDatetime" : ISODate("2013-11-19T17:54:50.198Z"),
    "CaseDescription" : "Veniam deserunt nisi pariatur non commodo pariatur in.",
    "RequestorFirstName" : "Morgan",
    "RequestorLastName" : "Nunez",
    "age" : 41,
    "gender" : "female",
    "CasePhoneNumbers" : [
        {
            "type" : "home",
            "number" : "+1 (976) 478-2278"
        },
        {
            "type" : "fax",
            "number" : "+1 (801) 463-3144"
        }
    ],
    "location" : [
        -122.394372,
        37.765385
    ],
    "CaseLat" : 37.727456,
    "CaseLong" : -122.416738,
    "ServiceName" : "Missing Sign",
    "CaseCurrentStatusDatetime" : ISODate("0NaN-NaN-NaNTNaN:NaN:NaNZ")
}

CasePhoneNumbers阵列让我有些头疼。我正在尝试构建一个可与Teiid配合使用的模式文件。我已经构建了以下内容,它在我的项目中运行良好。现在我不知所措地进入最后一部分。

CREATE FOREIGN TABLE cases(
    id varchar(50) PRIMARY KEY,
    CaseId varchar(50),
    CaseAddressString varchar(50),
    CaseOpenDatetime date,
    CaseBeginDatetime date,
    CaseDescription varchar(200),
    RequestorFirstName varchar(50),
    RequestorLastName varchar(50),
    CaseCurrentStatus varchar(25),
    age integer,
    gender varchar(20),
    CaseLat float,
    CaseLong float,
    ServiceName varchar(50)
) 
    OPTIONS(UPDATABLE 'TRUE');

2 个答案:

答案 0 :(得分:0)

你可以做到

CREATE FOREIGN TABLE cases(
    id varchar(50) PRIMARY KEY,
    CaseId varchar(50),
    CaseAddressString varchar(50),
    CaseOpenDatetime date,
    CaseBeginDatetime date,
    CaseDescription varchar(200),
    RequestorFirstName varchar(50),
    RequestorLastName varchar(50),
    CaseCurrentStatus varchar(25),
    age integer,
    gender varchar(20),
    CaseLat float,
    CaseLong float,
    ServiceName varchar(50)
) OPTIONS(UPDATABLE 'TRUE');

CREATE FOREIGN TABLE CasePhoneNumbers (
     caseid varchar,
     type string,
     number string,
     FOREIGN KEY (caseid) REFERENCES cases (_id)
) OPTIONS(UPDATABLE 'TRUE', "teiid_mongo:MERGE" 'cases')

您可以在https://docs.jboss.org/author/display/TEIID/MongoDB+Translator

查看更多文档

https://issues.jboss.org/browse/TEIID-3040删除详细的IDREF字段,但这将在Teiid 8.9中

答案 1 :(得分:0)

不确定是否相关,我在控制台上看到以下警告消息:

WARN 11524 --- [main] org.teiid.CONNECTOR: TEIID30003 Without required support 
property TableAlias, pushdown will not be enabled for SelfJoins on translator 
[mongodb, raasagent].

“ raasagent”是我在DataSources.java中定义的MongoDBConnectionFactory bean。

给出MongoDB matrix_variable集合中的以下文档:

{
    "_id" : ObjectId("5b2367c9c9e77c0007ca0111"),
    "createdOn" : ISODate("2018-06-15T07:16:25.459Z"),
    "modifiedOn" : ISODate("2018-07-02T02:04:16.661Z"),
    "variableId" : "183cf101d2334ac09bd0db9aee96081f",
    "name" : "lfzq_test",
    "description" : "",
    "lastModifiedUserEmail" : "admin1@abc.com",
    "headerRow" : {
        "rowId" : "0b002942a5b4424f98fcc270af0290c3",
        "values" : [ 
            "name", 
            "value"
        ],
        "isEncrypted" : [ 
            false, 
            true
        ]
    },
    "rows" : [ 
        {
            "rowId" : "940467f9bb724d1688086baeec05049b",
            "values" : [ 
                "lfzq123q", 
                "751c634ca5e24102a00800b386955a5c"
            ]
        }
    ],
    "deleted" : false
}

在OData模式中,“ headerRow”属性作为单独的实体类型公开,但“ rows”属性则不公开。

我发现以下带有odata / $ metadata的实体类型:

<EntityType Name="headerRow">...</EntityType>
<EntityType Name="matrix_variable">...</EntityType>

希望这很清楚。为什么没有通过OData公开“行”属性的任何线索?