From 9a8ca53e8b44fd9d3157083f543154a86b5618ee Mon Sep 17 00:00:00 2001 From: Geir Storli Date: Mon, 6 Mar 2017 12:35:29 +0000 Subject: Support building a schema from imported-fields config. --- searchcommon/src/tests/schema/attributes.cfg | 22 ---------------- .../schema/imported-fields-cfg/imported-fields.cfg | 7 ++++++ searchcommon/src/tests/schema/indexschema.cfg | 26 ------------------- .../src/tests/schema/load-save-cfg/attributes.cfg | 22 ++++++++++++++++ .../src/tests/schema/load-save-cfg/indexschema.cfg | 26 +++++++++++++++++++ .../src/tests/schema/load-save-cfg/summary.cfg | 29 ++++++++++++++++++++++ searchcommon/src/tests/schema/schema_test.cpp | 21 +++++++++++----- searchcommon/src/tests/schema/summary.cfg | 29 ---------------------- .../vespa/searchcommon/common/schemaconfigurer.cpp | 19 ++++++++++++-- .../vespa/searchcommon/common/schemaconfigurer.h | 13 +++++----- 10 files changed, 123 insertions(+), 91 deletions(-) delete mode 100644 searchcommon/src/tests/schema/attributes.cfg create mode 100644 searchcommon/src/tests/schema/imported-fields-cfg/imported-fields.cfg delete mode 100644 searchcommon/src/tests/schema/indexschema.cfg create mode 100644 searchcommon/src/tests/schema/load-save-cfg/attributes.cfg create mode 100644 searchcommon/src/tests/schema/load-save-cfg/indexschema.cfg create mode 100644 searchcommon/src/tests/schema/load-save-cfg/summary.cfg delete mode 100644 searchcommon/src/tests/schema/summary.cfg (limited to 'searchcommon') diff --git a/searchcommon/src/tests/schema/attributes.cfg b/searchcommon/src/tests/schema/attributes.cfg deleted file mode 100644 index 09f711b6a65..00000000000 --- a/searchcommon/src/tests/schema/attributes.cfg +++ /dev/null @@ -1,22 +0,0 @@ -attribute[9] -attribute[0].name a -attribute[0].datatype STRING -attribute[0].collectiontype SINGLE -attribute[1].name b -attribute[1].datatype INT8 -attribute[1].collectiontype ARRAY -attribute[2].name c -attribute[2].datatype INT16 -attribute[2].collectiontype WEIGHTEDSET -attribute[3].name d -attribute[3].datatype INT32 -attribute[4].name e -attribute[4].datatype INT64 -attribute[5].name f -attribute[5].datatype FLOAT -attribute[6].name g -attribute[6].datatype DOUBLE -attribute[7].name h -attribute[7].datatype PREDICATE -attribute[8].name i -attribute[8].datatype TENSOR 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/indexschema.cfg b/searchcommon/src/tests/schema/indexschema.cfg deleted file mode 100644 index 989f30f7499..00000000000 --- a/searchcommon/src/tests/schema/indexschema.cfg +++ /dev/null @@ -1,26 +0,0 @@ -indexfield[6] -indexfield[0].name a -indexfield[0].datatype STRING -indexfield[1].name b -indexfield[1].datatype INT64 -indexfield[2].name c -indexfield[2].datatype STRING -indexfield[2].prefix true -indexfield[2].phrases false -indexfield[2].positions false -indexfield[3].name e -indexfield[3].datatype BOOLEANTREE -indexfield[3].collectiontype SINGLE -indexfield[4].name f -indexfield[4].indextype RISE -indexfield[4].datatype STRING -indexfield[4].collectiontype WEIGHTEDSET -indexfield[5].name g -indexfield[5].indextype RISE -indexfield[5].datatype INT64 -indexfield[5].collectiontype WEIGHTEDSET -fieldset[1] -fieldset[0].name default -fieldset[0].field[2] -fieldset[0].field[0].name a -fieldset[0].field[1].name c diff --git a/searchcommon/src/tests/schema/load-save-cfg/attributes.cfg b/searchcommon/src/tests/schema/load-save-cfg/attributes.cfg new file mode 100644 index 00000000000..09f711b6a65 --- /dev/null +++ b/searchcommon/src/tests/schema/load-save-cfg/attributes.cfg @@ -0,0 +1,22 @@ +attribute[9] +attribute[0].name a +attribute[0].datatype STRING +attribute[0].collectiontype SINGLE +attribute[1].name b +attribute[1].datatype INT8 +attribute[1].collectiontype ARRAY +attribute[2].name c +attribute[2].datatype INT16 +attribute[2].collectiontype WEIGHTEDSET +attribute[3].name d +attribute[3].datatype INT32 +attribute[4].name e +attribute[4].datatype INT64 +attribute[5].name f +attribute[5].datatype FLOAT +attribute[6].name g +attribute[6].datatype DOUBLE +attribute[7].name h +attribute[7].datatype PREDICATE +attribute[8].name i +attribute[8].datatype TENSOR diff --git a/searchcommon/src/tests/schema/load-save-cfg/indexschema.cfg b/searchcommon/src/tests/schema/load-save-cfg/indexschema.cfg new file mode 100644 index 00000000000..989f30f7499 --- /dev/null +++ b/searchcommon/src/tests/schema/load-save-cfg/indexschema.cfg @@ -0,0 +1,26 @@ +indexfield[6] +indexfield[0].name a +indexfield[0].datatype STRING +indexfield[1].name b +indexfield[1].datatype INT64 +indexfield[2].name c +indexfield[2].datatype STRING +indexfield[2].prefix true +indexfield[2].phrases false +indexfield[2].positions false +indexfield[3].name e +indexfield[3].datatype BOOLEANTREE +indexfield[3].collectiontype SINGLE +indexfield[4].name f +indexfield[4].indextype RISE +indexfield[4].datatype STRING +indexfield[4].collectiontype WEIGHTEDSET +indexfield[5].name g +indexfield[5].indextype RISE +indexfield[5].datatype INT64 +indexfield[5].collectiontype WEIGHTEDSET +fieldset[1] +fieldset[0].name default +fieldset[0].field[2] +fieldset[0].field[0].name a +fieldset[0].field[1].name c diff --git a/searchcommon/src/tests/schema/load-save-cfg/summary.cfg b/searchcommon/src/tests/schema/load-save-cfg/summary.cfg new file mode 100644 index 00000000000..0c2de33d076 --- /dev/null +++ b/searchcommon/src/tests/schema/load-save-cfg/summary.cfg @@ -0,0 +1,29 @@ +defaultsummaryid 0 +classes[1] +classes[0].id 0 +classes[0].name test +classes[0].fields[12] +classes[0].fields[0].name a +classes[0].fields[0].type byte +classes[0].fields[1].name b +classes[0].fields[1].type short +classes[0].fields[2].name c +classes[0].fields[2].type integer +classes[0].fields[3].name d +classes[0].fields[3].type int64 +classes[0].fields[4].name e +classes[0].fields[4].type float +classes[0].fields[5].name f +classes[0].fields[5].type double +classes[0].fields[6].name g +classes[0].fields[6].type string +classes[0].fields[7].name h +classes[0].fields[7].type longstring +classes[0].fields[8].name i +classes[0].fields[8].type xmlstring +classes[0].fields[9].name j +classes[0].fields[9].type jsonstring +classes[0].fields[10].name k +classes[0].fields[10].type data +classes[0].fields[11].name l +classes[0].fields[11].type longdata 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/tests/schema/summary.cfg b/searchcommon/src/tests/schema/summary.cfg deleted file mode 100644 index 0c2de33d076..00000000000 --- a/searchcommon/src/tests/schema/summary.cfg +++ /dev/null @@ -1,29 +0,0 @@ -defaultsummaryid 0 -classes[1] -classes[0].id 0 -classes[0].name test -classes[0].fields[12] -classes[0].fields[0].name a -classes[0].fields[0].type byte -classes[0].fields[1].name b -classes[0].fields[1].type short -classes[0].fields[2].name c -classes[0].fields[2].type integer -classes[0].fields[3].name d -classes[0].fields[3].type int64 -classes[0].fields[4].name e -classes[0].fields[4].type float -classes[0].fields[5].name f -classes[0].fields[5].type double -classes[0].fields[6].name g -classes[0].fields[6].type string -classes[0].fields[7].name h -classes[0].fields[7].type longstring -classes[0].fields[8].name i -classes[0].fields[8].type xmlstring -classes[0].fields[9].name j -classes[0].fields[9].type jsonstring -classes[0].fields[10].name k -classes[0].fields[10].type data -classes[0].fields[11].name l -classes[0].fields[11].type longdata 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 summarySubscriber(*this, &SchemaConfigurer::configure); + search::SubscriptionProxyNg + 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 +#include #include #include #include @@ -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: /** -- cgit v1.2.3