diff options
author | Geir Storli <geirst@yahoo-inc.com> | 2017-03-06 12:35:29 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahoo-inc.com> | 2017-03-07 11:42:20 +0000 |
commit | 9a8ca53e8b44fd9d3157083f543154a86b5618ee (patch) | |
tree | 6508f1086b56a20eea11984fe8c2adc66b007279 /searchcommon | |
parent | 6518cbc8ccf51ca41d99ac7dc53d6c0eb92c7756 (diff) |
Support building a schema from imported-fields config.
Diffstat (limited to 'searchcommon')
-rw-r--r-- | searchcommon/src/tests/schema/imported-fields-cfg/imported-fields.cfg | 7 | ||||
-rw-r--r-- | searchcommon/src/tests/schema/load-save-cfg/attributes.cfg (renamed from searchcommon/src/tests/schema/attributes.cfg) | 0 | ||||
-rw-r--r-- | searchcommon/src/tests/schema/load-save-cfg/indexschema.cfg (renamed from searchcommon/src/tests/schema/indexschema.cfg) | 0 | ||||
-rw-r--r-- | searchcommon/src/tests/schema/load-save-cfg/summary.cfg (renamed from searchcommon/src/tests/schema/summary.cfg) | 0 | ||||
-rw-r--r-- | searchcommon/src/tests/schema/schema_test.cpp | 21 | ||||
-rw-r--r-- | searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp | 19 | ||||
-rw-r--r-- | searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h | 13 |
7 files changed, 46 insertions, 14 deletions
diff --git a/searchcommon/src/tests/schema/imported-fields-cfg/imported-fields.cfg b/searchcommon/src/tests/schema/imported-fields-cfg/imported-fields.cfg new file mode 100644 index 00000000000..ccfec672134 --- /dev/null +++ b/searchcommon/src/tests/schema/imported-fields-cfg/imported-fields.cfg @@ -0,0 +1,7 @@ +attribute[2] +attribute[0].name imported_a +attribute[0].referencefield ref_a +attribute[0].targetfield target_a +attribute[1].name imported_b +attribute[1].referencefield ref_b +attribute[1].targetfield target_b diff --git a/searchcommon/src/tests/schema/attributes.cfg b/searchcommon/src/tests/schema/load-save-cfg/attributes.cfg index 09f711b6a65..09f711b6a65 100644 --- a/searchcommon/src/tests/schema/attributes.cfg +++ b/searchcommon/src/tests/schema/load-save-cfg/attributes.cfg diff --git a/searchcommon/src/tests/schema/indexschema.cfg b/searchcommon/src/tests/schema/load-save-cfg/indexschema.cfg index 989f30f7499..989f30f7499 100644 --- a/searchcommon/src/tests/schema/indexschema.cfg +++ b/searchcommon/src/tests/schema/load-save-cfg/indexschema.cfg diff --git a/searchcommon/src/tests/schema/summary.cfg b/searchcommon/src/tests/schema/load-save-cfg/summary.cfg index 0c2de33d076..0c2de33d076 100644 --- a/searchcommon/src/tests/schema/summary.cfg +++ b/searchcommon/src/tests/schema/load-save-cfg/summary.cfg diff --git a/searchcommon/src/tests/schema/schema_test.cpp b/searchcommon/src/tests/schema/schema_test.cpp index 142a5f25184..f399215dbda 100644 --- a/searchcommon/src/tests/schema/schema_test.cpp +++ b/searchcommon/src/tests/schema/schema_test.cpp @@ -13,6 +13,8 @@ using vespalib::string; namespace search { namespace index { +using SIAF = Schema::ImportedAttributeField; + void assertField(const Schema::Field & exp, const Schema::Field & act) { EXPECT_EQUAL(exp.getName(), act.getName()); EXPECT_EQUAL(exp.getDataType(), act.getDataType()); @@ -84,7 +86,7 @@ TEST("testBasic") { s.addFieldSet(Schema::FieldSet("default").addField("foo").addField("bar")); - s.addImportedAttributeField(Schema::ImportedAttributeField("imported", schema::INT32)); + s.addImportedAttributeField(SIAF("imported", schema::INT32)); EXPECT_EQUAL(2u, s.getNumIndexFields()); { @@ -157,9 +159,7 @@ TEST("testBasic") { { const auto &imported = s.getImportedAttributeFields(); EXPECT_EQUAL(1u, imported.size()); - EXPECT_EQUAL("imported", imported[0].getName()); - EXPECT_EQUAL(schema::INT32, imported[0].getDataType()); - EXPECT_EQUAL(schema::SINGLE, imported[0].getCollectionType()); + TEST_DO(assertField(SIAF("imported", schema::INT32, schema::SINGLE), imported[0])); } } @@ -167,14 +167,13 @@ TEST("testLoadAndSave") { using SIF = Schema::IndexField; using SAF = Schema::AttributeField; using SSF = Schema::SummaryField; - using SIAF = Schema::ImportedAttributeField; using SDT = schema::DataType; using SCT = schema::CollectionType; typedef Schema::FieldSet SFS; { // load from config -> save to file -> load from file Schema s; - SchemaConfigurer configurer(s, "dir:" + TEST_PATH("")); + SchemaConfigurer configurer(s, "dir:" + TEST_PATH("load-save-cfg")); EXPECT_EQUAL(3u, s.getNumIndexFields()); assertIndexField(SIF("a", SDT::STRING), s.getIndexField(0)); assertIndexField(SIF("b", SDT::INT64), s.getIndexField(1)); @@ -411,6 +410,16 @@ TEST("require that imported attribute fields are not saved to disk") } } +TEST("require that schema can be built from imported-fields config") +{ + Schema s; + SchemaConfigurer configurer(s, "dir:" + TEST_PATH("imported-fields-cfg")); + const auto &imported = s.getImportedAttributeFields(); + EXPECT_EQUAL(2u, imported.size()); + TEST_DO(assertField(SIAF("imported_a", schema::STRING, schema::SINGLE), imported[0])); + TEST_DO(assertField(SIAF("imported_b", schema::STRING, schema::SINGLE), imported[1])); +} + } // namespace index } // namespace search diff --git a/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp b/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp index e6e081831e5..647a23a8db8 100644 --- a/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp +++ b/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp @@ -198,6 +198,15 @@ SchemaBuilder::build(const SummaryConfig &cfg, Schema &schema) } } +void +SchemaBuilder::build(const ImportedFieldsConfig &cfg, Schema &schema) +{ + for (const auto &attr : cfg.attribute) { + // TODO: Use correct datatype and collection type when available in config. + schema.addImportedAttributeField(Schema::ImportedAttributeField(attr.name, + schema::DataType::STRING)); + } +} void SchemaConfigurer::configure(const IndexschemaConfig &cfg) @@ -205,20 +214,23 @@ SchemaConfigurer::configure(const IndexschemaConfig &cfg) SchemaBuilder::build(cfg, _schema); } - void SchemaConfigurer::configure(const AttributesConfig &cfg) { SchemaBuilder::build(cfg, _schema); } - void SchemaConfigurer::configure(const SummaryConfig & cfg) { SchemaBuilder::build(cfg, _schema); } +void +SchemaConfigurer::configure(const vespa::config::search::ImportedFieldsConfig &cfg) +{ + SchemaBuilder::build(cfg, _schema); +} SchemaConfigurer::SchemaConfigurer(Schema &schema, const vespalib::string &configId) @@ -230,9 +242,12 @@ SchemaConfigurer::SchemaConfigurer(Schema &schema, attributesSubscriber(*this, &SchemaConfigurer::configure); search::SubscriptionProxyNg<SchemaConfigurer, SummaryConfig> summarySubscriber(*this, &SchemaConfigurer::configure); + search::SubscriptionProxyNg<SchemaConfigurer, ImportedFieldsConfig> + importedFieldsSubscriber(*this, &SchemaConfigurer::configure); indexSchemaSubscriber.subscribe(configId.c_str()); attributesSubscriber.subscribe(configId.c_str()); summarySubscriber.subscribe(configId.c_str()); + importedFieldsSubscriber.subscribe(configId.c_str()); } diff --git a/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h b/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h index 3c63d13ed28..4a2f8e5149e 100644 --- a/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h +++ b/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h @@ -3,6 +3,7 @@ #pragma once #include <vespa/config-attributes.h> +#include <vespa/config-imported-fields.h> #include <vespa/config-indexschema.h> #include <vespa/config-summary.h> #include <vespa/searchcommon/common/schema.h> @@ -38,22 +39,21 @@ public: * * @param indexCfg vespa::config::search::IndexschemaConfig to use */ - static void - build(const vespa::config::search::IndexschemaConfig &cfg, Schema &schema); + static void build(const vespa::config::search::IndexschemaConfig &cfg, Schema &schema); /** * Build from attribute config. * * @param attributeCfg vespa::config::search::AttributesConfig to use **/ - static void - build(const vespa::config::search::AttributesConfig &cfg, Schema &schema); + static void build(const vespa::config::search::AttributesConfig &cfg, Schema &schema); /** * Build from summary config. * * @param summaryCfg vespa::config::search::SummaryConfig to use **/ - static void - build(const vespa::config::search::SummaryConfig &cfg, Schema &schema); + static void build(const vespa::config::search::SummaryConfig &cfg, Schema &schema); + + static void build(const vespa::config::search::ImportedFieldsConfig &cfg, Schema &schema); }; class SchemaConfigurer @@ -63,6 +63,7 @@ private: void configure(const vespa::config::search::IndexschemaConfig & cfg); void configure(const vespa::config::search::AttributesConfig & cfg); void configure(const vespa::config::search::SummaryConfig & cfg); + void configure(const vespa::config::search::ImportedFieldsConfig &cfg); public: /** |