use of org.apache.solr.client.solrj.response.LukeResponse.FieldInfo in project teiid by teiid.
the class TestSolrMetadataProcessor method buildField.
private FieldInfo buildField(String name, String type, EnumSet<FieldFlag> flags) {
FieldInfo info = Mockito.mock(FieldInfo.class);
Mockito.stub(info.getName()).toReturn(name);
Mockito.stub(info.getType()).toReturn(type);
Mockito.stub(info.getFlags()).toReturn(flags);
return info;
}
use of org.apache.solr.client.solrj.response.LukeResponse.FieldInfo in project ddf by codice.
the class SchemaFieldResolver method getSchemaField.
public SchemaField getSchemaField(String propertyName, boolean isSearchedAsExactValue) {
SchemaField schemaField = null;
LukeRequest luke = new LukeRequest();
LukeResponse rsp;
try {
rsp = luke.process(solr.getClient());
Map<String, FieldInfo> fieldsInfo = rsp.getFieldInfo();
if (fieldsInfo != null && !fieldsInfo.isEmpty()) {
LOGGER.debug("got fieldsInfo for {} fields", fieldsInfo.size());
for (Map.Entry<String, FieldInfo> entry : fieldsInfo.entrySet()) {
// if suffix matches, then get type of field and cache it
if (entry.getKey().startsWith(propertyName) && StringUtils.endsWithAny(entry.getKey(), FORMAT_SUFFIXES)) {
String fieldType = entry.getValue().getType();
int index = StringUtils.lastIndexOfAny(entry.getKey(), FORMAT_SUFFIXES);
String suffix = entry.getKey().substring(index);
if (!isSearchedAsExactValue) {
suffix = getSpecialIndexSuffix(suffix);
fieldType += suffix;
}
LOGGER.debug("field {} has type {}", entry.getKey(), fieldType);
schemaField = new SchemaField(entry.getKey(), fieldType);
schemaField.setSuffix(suffix);
return schemaField;
}
}
} else {
LOGGER.debug("fieldsInfo from LukeRequest are either null or empty");
}
} catch (SolrServerException | SolrException | IOException e) {
LOGGER.info("Exception while processing LukeRequest", e);
}
LOGGER.debug("Did not find SchemaField for property {}", propertyName);
return schemaField;
}
use of org.apache.solr.client.solrj.response.LukeResponse.FieldInfo in project teiid by teiid.
the class SolrMetadataProcessor method getConnectorMetadata.
public void getConnectorMetadata(SolrConnection conn, MetadataFactory metadataFactory) throws TranslatorException {
int count = 0;
LukeRequest request = new LukeRequest();
request.setShowSchema(true);
LukeResponse response = conn.metadata(request);
Map<String, FieldInfo> fields = response.getFieldInfo();
Table table = metadataFactory.addTable(conn.getCoreName());
table.setSupportsUpdate(true);
for (String name : fields.keySet()) {
FieldInfo field = fields.get(name);
EnumSet<FieldFlag> flags = field.getFlags();
if ((!name.startsWith("_") && !name.endsWith("_")) || name.startsWith("*") || name.endsWith("*")) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
if (flags.contains(FieldFlag.INDEXED) && flags.contains(FieldFlag.STORED)) {
Column column = null;
// array type
if (flags.contains(FieldFlag.MULTI_VALUED)) {
// $NON-NLS-1$
column = metadataFactory.addColumn(field.getName(), resolveType(field.getType()) + "[]", table);
} else {
column = metadataFactory.addColumn(field.getName(), resolveType(field.getType()), table);
}
column.setUpdatable(true);
column.setSearchType(SearchType.Searchable);
// create primary key; and unique keys
if (field.getDistinct() > 0 || field.getName().equals("id")) {
// $NON-NLS-1$
if (table.getPrimaryKey() == null) {
// $NON-NLS-1$
metadataFactory.addPrimaryKey("PK0", Arrays.asList(field.getName()), table);
} else {
// $NON-NLS-1$
metadataFactory.addIndex("UI" + count, true, Arrays.asList(field.getName()), table);
count++;
}
}
}
}
}
}
use of org.apache.solr.client.solrj.response.LukeResponse.FieldInfo in project teiid by teiid.
the class TestSolrMetadataProcessor method testMetadata.
@Test
public void testMetadata() throws TranslatorException {
SolrMetadataProcessor mp = new SolrMetadataProcessor();
MetadataFactory mf = new MetadataFactory("vdb", 1, "solr", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
SolrConnection conn = Mockito.mock(SolrConnection.class);
Mockito.stub(conn.getCoreName()).toReturn("SomeTable");
LinkedHashMap<String, FieldInfo> fields = new LinkedHashMap<String, LukeResponse.FieldInfo>();
fields.put("col1", buildField("col1", "string", EnumSet.of(FieldFlag.STORED, FieldFlag.INDEXED)));
fields.put("col2", buildField("col2", "int", EnumSet.of(FieldFlag.STORED, FieldFlag.INDEXED)));
fields.put("col3", buildField("col3", "int", EnumSet.of(FieldFlag.STORED, FieldFlag.INDEXED, FieldFlag.MULTI_VALUED)));
fields.put("id", buildField("id", "long", EnumSet.of(FieldFlag.STORED, FieldFlag.INDEXED)));
LukeResponse response = Mockito.mock(LukeResponse.class);
;
Mockito.stub(response.getFieldInfo()).toReturn(fields);
Mockito.stub(conn.metadata(Mockito.any(LukeRequest.class))).toReturn(response);
mp.process(mf, conn);
String metadataDDL = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
String expected = "CREATE FOREIGN TABLE SomeTable (\n" + " col1 string OPTIONS (SEARCHABLE 'Searchable'),\n" + " col2 integer OPTIONS (SEARCHABLE 'Searchable'),\n" + " col3 integer[] OPTIONS (SEARCHABLE 'Searchable'),\n" + " id long OPTIONS (SEARCHABLE 'Searchable'),\n" + " CONSTRAINT PK0 PRIMARY KEY(id)\n" + ") OPTIONS (UPDATABLE TRUE);";
assertEquals(expected, metadataDDL);
}
Aggregations