Search in sources :

Example 1 with SchemaMetaContent

use of com.qlangtech.tis.solrdao.SchemaMetaContent in project plugins by qlangtech.

the class TestDataXElasticsearchWriter method testInitSchemaMetaContent.

public void testInitSchemaMetaContent() {
    DataXElasticsearchWriter dataXWriter = new DataXElasticsearchWriter();
    ISelectedTab selectedTab = EasyMock.createMock("selectedTab", ISelectedTab.class);
    // ISelectedTab
    List<ISelectedTab.ColMeta> cols = Lists.newArrayList();
    ISelectedTab.ColMeta col = null;
    col = new ISelectedTab.ColMeta();
    col.setName(null);
    col.setType(DataXReaderColType.STRING.dataType);
    cols.add(col);
    col = new ISelectedTab.ColMeta();
    col.setName(null);
    col.setType(DataXReaderColType.Long.dataType);
    cols.add(col);
    EasyMock.expect(selectedTab.getCols()).andReturn(cols);
    EasyMock.replay(selectedTab);
    SchemaMetaContent metaContent = dataXWriter.initSchemaMetaContent(selectedTab);
    // System.out.println(JsonUtil.toString(metaContent.toJSON()));
    JsonUtil.assertJSONEqual(DataXElasticsearchWriter.class, "initSchemaMetaContent_assert.json", metaContent.toJSON(), (m, e, a) -> {
        assertEquals(m, e, a);
    });
    EasyMock.verify(selectedTab);
}
Also used : SchemaMetaContent(com.qlangtech.tis.solrdao.SchemaMetaContent) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab)

Example 2 with SchemaMetaContent

use of com.qlangtech.tis.solrdao.SchemaMetaContent in project plugins by qlangtech.

the class TestDataXElasticsearchWriter method testProjectionFromExpertModel.

public void testProjectionFromExpertModel() {
    DataXElasticsearchWriter dataXWriter = new DataXElasticsearchWriter();
    JSONObject body = new JSONObject();
    body.put("content", IOUtils.loadResourceFromClasspath(DataXElasticsearchWriter.class, "mergeFromStupidModel_assert.json"));
    ISchema schema = dataXWriter.projectionFromExpertModel(body);
    assertNotNull(schema);
    List<ESField> fields = schema.getSchemaFields();
    assertEquals(2, fields.size());
    ESField aaa = fields.get(0);
    assertEquals("aaa", aaa.getName());
    assertEquals(EsTokenizerType.visualTypeMap.get("long").type, aaa.getTisFieldTypeName());
    assertTrue(aaa.isDocValue());
    assertTrue(aaa.isIndexed());
    assertTrue(aaa.isStored());
    ESField bbb = fields.get(1);
    assertEquals("bbb", bbb.getName());
    assertEquals(DataXElasticsearchWriter.ES_TYPE_TEXT.getType(), bbb.getTisFieldTypeName());
    assertEquals(EsTokenizerType.NULL.getKey(), bbb.getTokenizerType());
    assertTrue(bbb.isDocValue());
    assertTrue(bbb.isIndexed());
    assertTrue(bbb.isStored());
    SchemaMetaContent schemaContent = new SchemaMetaContent();
    schemaContent.content = StringUtils.EMPTY.getBytes(TisUTF8.get());
    schemaContent.parseResult = schema;
    JSONObject schemaContentJson = schemaContent.toJSON();
    // System.out.println(JsonUtil.toString(schemaContentJson));
    JsonUtil.assertJSONEqual(DataXElasticsearchWriter.class, "projectionFromExpertModel_assert.json", schemaContentJson, (m, e, a) -> {
        assertEquals(m, e, a);
    });
}
Also used : SchemaMetaContent(com.qlangtech.tis.solrdao.SchemaMetaContent) JSONObject(com.alibaba.fastjson.JSONObject) ISchema(com.qlangtech.tis.solrdao.ISchema)

Example 3 with SchemaMetaContent

use of com.qlangtech.tis.solrdao.SchemaMetaContent in project plugins by qlangtech.

the class DataXElasticsearchWriter method initSchemaMetaContent.

@Override
public SchemaMetaContent initSchemaMetaContent(ISelectedTab tab) {
    SchemaMetaContent metaContent = new SchemaMetaContent();
    ESSchema schema = new ESSchema();
    metaContent.parseResult = schema;
    ESField field = null;
    for (ISelectedTab.ColMeta m : tab.getCols()) {
        field = new ESField();
        field.setName(m.getName());
        field.setStored(true);
        field.setIndexed(true);
        field.setType(this.mapSearchEngineType(m.getType().getCollapse()));
        // field.setSharedKey();
        // field.setUniqueKey();
        schema.fields.add(field);
    }
    byte[] schemaContent = null;
    metaContent.content = schemaContent;
    return metaContent;
}
Also used : SchemaMetaContent(com.qlangtech.tis.solrdao.SchemaMetaContent) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab)

Aggregations

SchemaMetaContent (com.qlangtech.tis.solrdao.SchemaMetaContent)3 ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)2 JSONObject (com.alibaba.fastjson.JSONObject)1 ISchema (com.qlangtech.tis.solrdao.ISchema)1