Skip to content

Commit

Permalink
add colsMeta support
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Feb 26, 2021
1 parent 0566024 commit ad7c660
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.qlangtech.tis.runtime.module.action.SchemaAction;
import com.qlangtech.tis.runtime.module.action.SysInitializeAction;
import com.qlangtech.tis.runtime.module.misc.IMessageHandler;
import com.qlangtech.tis.runtime.module.screen.IndexQuery;
import com.qlangtech.tis.runtime.module.screen.ViewPojo;
import com.qlangtech.tis.solrdao.ISchemaField;
import com.qlangtech.tis.solrdao.ISchemaPluginContext;
Expand Down Expand Up @@ -86,8 +87,6 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

//import com.qlangtech.tis.coredefine.biz.CoreNode;

/**
* @author 百岁([email protected]
* @date 2020-12-13 16:10
Expand Down Expand Up @@ -115,6 +114,7 @@ public class CollectionAction extends com.qlangtech.tis.runtime.module.action.Ad
public static final String KEY_CORE_URL = "coreUrl";
public static final String KEY_IS_ACTIVE = "active";
public static final String KEY_REPLICS = "replics";
public static final String KEY_COLS_META = "colMetas";


// private
Expand Down Expand Up @@ -177,6 +177,27 @@ public void doGetIndexTopology(Context context) throws Exception {
}).getSchemaParseResult();

biz.put(KEY_PK, parseResult.getUniqueKey());


QueryResutStrategy queryStrategy = QueryIndexServlet.createQueryResutStrategy(
this.getAppDomain(), new IndexQuery.QueryRequestWrapper(getRequest(), context), getResponse(), getDaoContext());
List<ServerJoinGroup> nodes = queryStrategy.queryProcess();
List<PSchemaField> sfields = IndexQuery.getSfields(this.getRequest(), queryStrategy, nodes);
JSONArray colsMeta = new JSONArray();
JSONObject colmeta = null;
for (PSchemaField field : sfields) {
colmeta = new JSONObject();
colmeta.put("name", field.getName());
colmeta.put("typeName", field.getType().getJavaType().getSimpleName());
colmeta.put("typeCode", field.getType().getJavaType().getTypeCode());
colmeta.put("docval", field.isDocValue());
colmeta.put("indexd", field.isIndexed());
colmeta.put("stored", field.isStored());
colmeta.put("dynamic", field.isDynamic());
colsMeta.add(colmeta);
}
biz.put(KEY_COLS_META, colsMeta);

this.setBizResult(context, biz);
}

Expand Down Expand Up @@ -296,9 +317,6 @@ public void doCreate(Context context) throws Exception {
}
this.setBizResult(context, new Object());
Objects.requireNonNull(dsTable, "dsTable can not be null");
// DataSourceFactoryPluginStore dsPluginStore = TIS.getDataBasePluginStore(new PostedDSProp(targetTable));
// // 保存表
// dsPluginStore.saveTable(targetTable, targetColMetas.targetColMetas);

// 开始创建DF
final String topologyName = indexName.param;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ protected DocCollection buildDocCollectionMock(boolean getSlicesMap, boolean fet
EasyMock.expect(replica.getBaseUrl()).andReturn("baseurl").anyTimes();
}

EasyMock.expect(docCollection.getSlicesMap()).andReturn(sliceMap);
EasyMock.expect(docCollection.getSlicesMap()).andReturn(sliceMap).anyTimes();


EasyMock.expect(tisZkStateReader.fetchCollectionState(collectionName, null))
.andReturn(docCollection);
.andReturn(docCollection).anyTimes();
}
return docCollection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
* @date 2020-12-16 10:39
*/
public class TestCollectionAction extends BasicActionTestCase {
private static final String TEST_TABLE_EMPLOYEES_NAME = "employees";
private static final String COLLECTION_NAME = TISCollectionUtils.NAME_PREFIX + TEST_TABLE_EMPLOYEES_NAME;

static {

Expand All @@ -85,14 +87,15 @@ public class TestCollectionAction extends BasicActionTestCase {
return TestCollectionAction.class.getResourceAsStream("s4employees_create_success.json");
});

HttpUtils.addMockApply(0, "/solr/" + COLLECTION_NAME + "/admin/file/?file=schema.xml", "s4employee_schema.xml", TestCollectionAction.class);

// stub trigger collection indexbuild
HttpUtils.addMockApply(CoreAction.TRIGGER_FULL_BUILD_COLLECTION_PATH, () -> {
return TestCollectionAction.class.getResourceAsStream("s4employees_trigger_index_build_success.json");
});

}

private static final String TEST_TABLE_EMPLOYEES_NAME = "employees";

// private static final String TEST_TABLE_EMPLOYEES_NAME = "singleEmployee";

Expand All @@ -114,7 +117,6 @@ public class TestCollectionAction extends BasicActionTestCase {
tabCols.put(TEST_TABLE_DEPARTMENT_NAME, getBuildDepartmentCols());
}

private static final String COLLECTION_NAME = TISCollectionUtils.NAME_PREFIX + TEST_TABLE_EMPLOYEES_NAME;

// public void testSend2RemoteServer() throws Exception {
// this.clearUpDB();
Expand Down Expand Up @@ -180,6 +182,10 @@ public void testGetIndexTopology() throws Exception {
JSONObject replic = replics.getJSONObject(0);
assertEquals(replica_core_url, replic.getString(CollectionAction.KEY_CORE_URL));
assertTrue(replic.getBoolean(CollectionAction.KEY_IS_ACTIVE));

JSONArray colsMeta = topology.getJSONArray(CollectionAction.KEY_COLS_META);
assertNotNull(colsMeta);
assertEquals(9, colsMeta.size());
}

public void testDeleteCollection() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE schema SYSTEM "solrres://tisrepository/dtd/solrschema.dtd">
<schema name="template" version="1.5">
<types>
<fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true" omitTermFreqAndPositions="true" />
<fieldType name="int" class="solr.IntPointField" docValues="false" />
<fieldType name="float" class="solr.FloatPointField" docValues="false" />
<fieldType name="long" class="solr.LongPointField" docValues="false" />
<fieldType name="double" class="solr.DoublePointField" docValues="false" />
<fieldType name="date" class="com.qlangtech.tis.solrextend.fieldtype.TisDateField" docValues="false" />
<fieldType name="timestamp" class="com.qlangtech.tis.solrextend.fieldtype.TisTimestampField" docValues="false" />
<fieldType name="bitwise" class="com.qlangtech.tis.solrextend.fieldtype.BitwiseField" omitNorms="true" omitTermFreqAndPositions="true" />
<fieldType name="ik" class="solr.TextField" autoGeneratePhraseQueries="false" omitNorms="true" omitTermFreqAndPositions="false">
<analyzer type="query">
<tokenizer class="com.qlangtech.tis.solrextend.fieldtype.st.STConvertTokenizerFactory" />
<filter class="com.qlangtech.tis.solrextend.analyzer.IKTokenFilterFactory" />
<filter class="solr.LowerCaseFilterFactory" />
<filter class="solr.TrimFilterFactory" />
</analyzer>
<analyzer type="index">
<tokenizer class="com.qlangtech.tis.solrextend.fieldtype.st.STConvertTokenizerFactory" />
<filter class="com.qlangtech.tis.solrextend.analyzer.IKTokenFilterFactory" />
</analyzer>
</fieldType>
<fieldType name="text_ws" class="solr.TextField" sortMissingLast="true" omitNorms="true" autoGeneratePhraseQueries="false" omitTermFreqAndPositions="true">
<analyzer>
<tokenizer class="solr.WhitespaceTokenizerFactory" />
</analyzer>
</fieldType>
<fieldType name="like" class="solr.TextField" sortMissingLast="true" omitNorms="true" autoGeneratePhraseQueries="false" omitTermFreqAndPositions="true">
<analyzer type="index">
<tokenizer class="solr.NGramTokenizerFactory" minGramSize="2" maxGramSize="7" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
<fieldType name="pinyin" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="false" omitNorms="true" omitPositions="true">
<analyzer type="index">
<tokenizer class="solr.PatternTokenizerFactory" pattern=",\s*" />
<filter class="solr.NGramFilterFactory" minGramSize="1" maxGramSize="7" />
<filter class="solr.LowerCaseFilterFactory" />
<filter class="solr.TrimFilterFactory" />
<filter class="com.qlangtech.tis.solrextend.fieldtype.pinyin.PinyinTokenFilterFactory" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.PatternTokenizerFactory" pattern=",\s*" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
<fieldType name="test" class="plugin:test" positionIncrementGap="0" />
</types>
<fields>
<field name="emp_no" type="string" stored="true" indexed="true" docValues="true" multiValued="false" />
<field name="birth_date" type="date" stored="true" indexed="false" docValues="true" multiValued="false" />
<field name="first_name" type="test" stored="true" indexed="false" docValues="true" multiValued="false" />
<field name="last_name" type="string" stored="true" indexed="false" docValues="true" multiValued="false" />
<field name="gender" type="string" stored="true" indexed="false" docValues="true" multiValued="false" />
<field name="hire_date" type="timestamp" stored="true" indexed="false" docValues="true" multiValued="false" />
<field name="_version_" type="long" stored="true" indexed="false" docValues="true" multiValued="false" />
<field name="text" type="string" stored="false" indexed="true" docValues="false" multiValued="true" />
<dynamicField name="json_*" type="string" stored="true" indexed="true" docValues="true" multiValued="false" />
</fields>
<uniqueKey>emp_no</uniqueKey>
<sharedKey>emp_no</sharedKey>
</schema>
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.io.StringReader;
import java.lang.reflect.Method;
import java.net.URL;
import java.sql.Timestamp;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -518,24 +519,32 @@ public static SolrType parseFieldType(String name, String fieldType, boolean spl
Type t = new Type(name);
t.setSolrType(fieldType);
type.setSolrType(t);
if (isTypeMatch(fieldType, "int")) {
type.setJavaType(Integer.class);
return type;
} else if (isTypeMatch(fieldType, "float")) {
type.setJavaType(Float.class);
return type;
} else if (isTypeMatch(fieldType, "double")) {
type.setJavaType(Double.class);
return type;
} else if (isTypeMatch(fieldType, "long")) {
type.setJavaType(Long.class);
return type;
} else if (isTypeMatch(fieldType, "short")) {
type.setJavaType(Short.class);
return type;
}
type.setJavaType(String.class);
type.setJavaType(SolrJavaType.parse(fieldType));
return type;
// if (isTypeMatch(fieldType, "int")) {
// type.setJavaType(Integer.class);
// return type;
// } else if (isTypeMatch(fieldType, "float")) {
// type.setJavaType(Float.class);
// return type;
// } else if (isTypeMatch(fieldType, "double")) {
// type.setJavaType(Double.class);
// return type;
// } else if (isTypeMatch(fieldType, "long")) {
// type.setJavaType(Long.class);
// return type;
// } else if (isTypeMatch(fieldType, "short")) {
// type.setJavaType(Short.class);
// return type;
// } else if (isTypeMatch(fieldType, "timestamp")) {
// type.setJavaType(Timestamp.class);
// return type;
// } else if (isTypeMatch(fieldType, "date")) {
// type.setJavaType(Date.class);
// return type;
// }


}

public static class Type {
Expand Down Expand Up @@ -579,30 +588,30 @@ public String getPluginName() {
return StringUtils.substringAfter(this.getSolrType(), SolrFieldsParser.KEY_PLUGIN + ":");
}

private Class<?> javaType;
private SolrJavaType javaType;

private Type solrType;

private Method valueof;

public Class<?> getJavaType() {
public SolrJavaType getJavaType() {
return this.javaType;
}

public Object valueOf(Object val) throws Exception {
return valueof.invoke(null, val);
}

public void setJavaType(Class<?> javaType) {
try {
if (javaType == String.class) {
valueof = javaType.getMethod("valueOf", Object.class);
} else {
valueof = javaType.getMethod("valueOf", String.class);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
public void setJavaType(SolrJavaType javaType) {
// try {
// if (javaType == String.class) {
// valueof = javaType.getMethod("valueOf", Object.class);
// } else {
// valueof = javaType.getMethod("valueOf", String.class);
// }
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
this.javaType = javaType;
}

Expand All @@ -619,9 +628,7 @@ public void setSolrType(Type solrType) {
}
}

private static boolean isTypeMatch(String fieldType, String matchLetter) {
return StringUtils.indexOfAny(fieldType, new String[]{matchLetter, StringUtils.capitalize(matchLetter)}) > -1;
}


public static class SchemaFields extends ArrayList<PSchemaField> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Copyright (c) 2020 QingLang, Inc. <[email protected]>
* <p>
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* <p>
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.qlangtech.tis.solrdao;

import org.apache.commons.lang.StringUtils;

import java.sql.Timestamp;
import java.util.Date;

/**
* @author 百岁([email protected]
* @date 2021-02-25 17:00
*/
public enum SolrJavaType {
INT(Integer.class, 1), FLOAT(Float.class, 2), DOUBLE(Double.class, 3), LONG(Long.class, 4), TIMESTAMP(Timestamp.class, 4), DATE(Date.class, 5), STRING(String.class, 6);

public static SolrJavaType parse(String fieldType) {
if (isTypeMatch(fieldType, "int")) {
return INT;
} else if (isTypeMatch(fieldType, "float")) {
return FLOAT;
} else if (isTypeMatch(fieldType, "double")) {
return DOUBLE;
} else if (isTypeMatch(fieldType, "long")) {
return LONG;
} else if (isTypeMatch(fieldType, "timestamp")) {
return TIMESTAMP;
} else if (isTypeMatch(fieldType, "date")) {
return DATE;
}
return STRING;
}

private static boolean isTypeMatch(String fieldType, String matchLetter) {
return StringUtils.indexOfAny(fieldType, new String[]{matchLetter, StringUtils.capitalize(matchLetter)}) > -1;
}

private final Class<?> javaType;
private final int typeCode;
// private final Method valueof;

private SolrJavaType(Class<?> javaType, int typeCode) {
this.javaType = javaType;
this.typeCode = typeCode;
// try {
// if (javaType == String.class) {
// valueof = javaType.getMethod("valueOf", Object.class);
// } else {
// valueof = javaType.getMethod("valueOf", String.class);
// }
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
}

public int getTypeCode() {
return typeCode;
}

public String getSimpleName() {
return StringUtils.lowerCase(javaType.getSimpleName());
}
}
Loading

0 comments on commit ad7c660

Please sign in to comment.