Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

WIP simple configuration #95

Merged
merged 1 commit into from
Apr 6, 2018
Merged

WIP simple configuration #95

merged 1 commit into from
Apr 6, 2018

Conversation

SudoBobo
Copy link
Contributor

@SudoBobo SudoBobo commented Mar 23, 2018

Related to #59 and #60.

@SudoBobo SudoBobo requested a review from Totktonada March 23, 2018 13:26
Copy link
Member

@Totktonada Totktonada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link #59 and #60 to the PR.

Consider comments below.

@@ -15,7 +15,7 @@ function common_testdata.get_test_metadata()
"type": "record",
"name": "user",
"fields": [
{ "name": "user_id", "type": "string" },
{ "name": " user_id", "type": "string" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be sure you read entire git diff before propose changes to review. This is typo, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. Fixed.


local config_complement = {}

--- The function determines connection type by fully qualified connection.parts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean with fully qualified? Usually that means that a name has all its namespaces as parts of the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that connection.parts must have a format of:

"parts": [
    { "source_field": "user_id", "destination_field": "user_id" },
    ...
],

I am not sure about naming here. The logic of config_complement is about converting from:

{
    name='order_connection',
    source_collection = 'user_collection',
    destination_collection = 'order_collection',
    index_name = 'user_id_index'
}

to (in source_collection)

{
    "type": "1:N",
    "name": "order_connection",
    "destination_collection":  "order_collection",
    "parts": [
         { "source_field": "user_id", "destination_field": "user_id" }
    ],
    "index_name": "user_id_index"
}

How to name this two formats? Simplified and full connections?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially / fully defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to partially / fully defined.

@@ -827,7 +827,7 @@ local function process_tuple(state, tuple, opts)

-- convert tuple -> object
local obj = opts.unflatten_tuple(collection_name, tuple,
opts.default_unflatten_tuple)
opts.default_unflatten_tuple, opts.is_collection_formatted)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it worth to keep profile of the default_unflatten_tuple function the same as unflatten_tuple (except the last parameter, default).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discucced verbally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed.

@@ -1285,6 +1288,7 @@ function accessor_general.new(opts, funcs)
indexes = indexes,
models = models,
default_unflatten_tuple = default_unflatten_tuple,
formatted_collections = opts.formatted_collections,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re naming: maybe space_format_layout?

Copy link
Contributor Author

@SudoBobo SudoBobo Mar 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it is a map with {collection_name: is_formatted}. We may extend it to be like: {collection_name: related_space_format}, but currently we does not need this information in accessor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed. We both ok with have_space_format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

local function unflatten_tuple(collection_name, tuple, default)
local function unflatten_tuple(collection_name, tuple, default, is_collection_formatted)
if is_collection_formatted then
return tuple:tomap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What with number fields? tarantool/tarantool#3281

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why it works w/o extra hacks. Because of fields selection in executor. So, okay to leave as is, but add the option for future tarantool versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You propose to clarify our intensions with this?

return tuple:tomap{{only_names=true})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, would be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.




local gql_wrapper = graphql.new({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is difference from space_common test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In simple_config we just test new constructor format.
space_common:

local accessor = graphql.accessor_space.new({
    schemas = schemas,
    collections = collections,
    service_fields = service_fields,
    indexes = indexes,
})

local gql_wrapper = graphql.new({
    schemas = schemas,
    collections = collections,
    accessor = accessor,
})

simple_config:

local gql_wrapper = graphql.new({
    schemas = schemas,
    collections = collections,
    service_fields = service_fields,
    indexes = indexes,
    accessor = 'space'
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

local shard = shard or box.space

shard.user_collection:replace(
{'user_id_1', 'Ivan', 42})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fxd.

local gql_query_1 = gql_wrapper:compile(query_1)
local result = gql_query_1:execute(variables_1)
results = results .. print_and_return(
('RESULT\n%s'):format(yaml.encode(result)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fxd.

box.once('test_space_init_spaces', function()
box.schema.create_space('user_collection')
box.space.user_collection:create_index('user_id_index',
{type = 'tree', unique = true, parts = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fxd.

box.cfg { background = false }
init_spaces()
fill_test_data()
local gql_wrapper = graphql.new({auto_cfg = true})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want graphql:compile() method (and create zero configuration graphql instance under hood) and graphql:execute() method?

Copy link
Contributor Author

@SudoBobo SudoBobo Apr 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do. Except for graphql:execute(). Currently we do not use it like graphql:execute(), we use it like compiled_quer.execute(). Do you suggest to support graphql:execute() anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? Consider box.sql.execute for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call compile + execute at once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, Done.

@Totktonada Totktonada added enhancement New feature or request usability labels Mar 27, 2018
@SudoBobo SudoBobo force-pushed the sb/simple_config branch 4 times, most recently from c2cec15 to 82c0bad Compare April 2, 2018 17:10
Copy link
Member

@Totktonada Totktonada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of comments are about my feelings and can be ignored. The PR generally LGTM, so you can do what you want on it and merge. Please, squash commits and rebase on current master.

{ "source_field": "user_id", "destination_field": "user_id" }
],
"index_name": "user_id_index"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason. Fxd.

@@ -827,7 +827,7 @@ local function process_tuple(state, tuple, opts)

-- convert tuple -> object
local obj = opts.unflatten_tuple(collection_name, tuple,
opts.default_unflatten_tuple)
{ has_space_format = opts.has_space_format }, opts.default_unflatten_tuple)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fxd.

@@ -1179,6 +1180,7 @@ local function get_pcre_argument_type(self, collection_name)
return pcre_type
end

--todo add comments about opts.formatted_collections (also assertions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you going to do it in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -1285,6 +1287,7 @@ function accessor_general.new(opts, funcs)
indexes = indexes,
models = models,
default_unflatten_tuple = default_unflatten_tuple,
has_space_format = opts.has_space_format or {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a boolean or a table?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified names, so now there is no such uncertain names.

@@ -84,12 +84,19 @@ end
---
--- @tparam string collection_name
--- @tparam cdata/table tuple
--- @tparam table opts
--- * `has_space_format` (boolean, if collection 'collection_name' generated
--- from space:format() or not).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to rephrase it to avoid misinterpret as 'boolean if ..., but other type otherwise':

boolean, default: false; whether objects in collection collection_name intended to be unflattened using tuple:tomap({names_only = true}) method instead of compiled_avro_schema.unflatten(tuple).

Here I proposed more concrete wording about how exactly behaviour will be changed by enabling this flag.

Copy link
Contributor Author

@SudoBobo SudoBobo Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Fxd.

end

--- Check if given table has only one specific key.
function utils.has_only(t, key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No copy (and certainly deepcopy) need, try this:

local fst_key = next(t)
local snd_key = next(t, fst_key)
return fst_key == key and snd_key == nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good, fxd.

return has_key and not_has_another_key
end

function utils.size(t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer less general name like table_size.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fxd.

('RESULT\n%s'):format(yaml.encode(result)))
end)

utils.show_trace(function()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don’t need to try-catch such prints.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Fxd.

@@ -0,0 +1,56 @@
#!/usr/bin/env tarantool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding this test as one of configurations of test/local/space_common.test.lua. Use suite.cfg file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be part of test refactoring ticket we discussed verbaly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File it to issues, please.

@@ -0,0 +1,74 @@
env = require('test_run')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be added as one of configuration of the shard_common.test.lua test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above

1. Zero config
2. require('graphql').execute()/compile()
functionality
3. GraphiQL
4. Config complementation
@SudoBobo SudoBobo merged commit 30c64ab into master Apr 6, 2018
@SudoBobo SudoBobo deleted the sb/simple_config branch May 26, 2018 18:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request usability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants