Skip to content

Commit

Permalink
Incapsulate is_nullable of tuple_field, key_part
Browse files Browse the repository at this point in the history
Incapsulate is_nullable attribute of tuple_field and key_part structs:
introduce new read accessors to corresponding attribute for both
structures.
This is need for following patch, which will replace is_nullable
attribute of mentioned structures w/ on_conflict_action attribute.

Part of #2217
  • Loading branch information
kyukhin committed Feb 1, 2018
1 parent e5b5dbc commit ee0bdc9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
17 changes: 9 additions & 8 deletions src/box/key_def.cc
Expand Up @@ -162,7 +162,7 @@ key_def_dump_parts(const struct key_def *def, struct key_part_def *parts)
struct key_part_def *part_def = &parts[i];
part_def->fieldno = part->fieldno;
part_def->type = part->type;
part_def->is_nullable = part->is_nullable;
part_def->is_nullable = key_part_is_nullable(part);
part_def->coll_id = (part->coll != NULL ?
part->coll->id : COLL_NONE);
}
Expand Down Expand Up @@ -205,9 +205,9 @@ key_part_cmp(const struct key_part *parts1, uint32_t part_count1,
if (part1->coll != part2->coll)
return (uintptr_t) part1->coll <
(uintptr_t) part2->coll ? -1 : 1;
if (part1->is_nullable != part2->is_nullable)
return part1->is_nullable <
part2->is_nullable ? -1 : 1;
if (key_part_is_nullable(part1) != key_part_is_nullable(part2))
return key_part_is_nullable(part1) <
key_part_is_nullable(part2) ? -1 : 1;
}
return part_count1 < part_count2 ? -1 : part_count1 > part_count2;
}
Expand All @@ -229,7 +229,7 @@ key_part_check_compatibility(const struct key_part *old_parts,
return false;
if (old_part->coll != new_part->coll)
return false;
if (old_part->is_nullable != new_part->is_nullable)
if (key_part_is_nullable(old_part) != key_part_is_nullable(new_part))
return false;
}
return true;
Expand Down Expand Up @@ -489,7 +489,7 @@ key_def_merge(const struct key_def *first, const struct key_def *second)
end = part + first->part_count;
for (; part != end; part++) {
key_def_set_part(new_def, pos++, part->fieldno, part->type,
part->is_nullable, part->coll);
key_part_is_nullable(part), part->coll);
}

/* Set-append second key def's part to the new key def. */
Expand All @@ -499,7 +499,7 @@ key_def_merge(const struct key_def *first, const struct key_def *second)
if (key_def_find(first, part->fieldno))
continue;
key_def_set_part(new_def, pos++, part->fieldno, part->type,
part->is_nullable, part->coll);
key_part_is_nullable(part), part->coll);
}
return new_def;
}
Expand All @@ -514,7 +514,8 @@ key_validate_parts(const struct key_def *key_def, const char *key,
mp_next(&key);

if (key_mp_type_validate(part->type, mp_type, ER_KEY_PART_TYPE,
i, part->is_nullable && allow_nullable))
i, key_part_is_nullable(part)
&& allow_nullable))
return -1;
}
return 0;
Expand Down
12 changes: 12 additions & 0 deletions src/box/key_def.h
Expand Up @@ -77,6 +77,18 @@ struct key_part {
struct key_def;
struct tuple;

/**
* Get is_nullable property of key_part.
* @param key_part for which attribute is being fetched
*
* @retval boolean nullability attribute
*/
static inline bool
key_part_is_nullable(const struct key_part *part)
{
return part->is_nullable;
}

/** @copydoc tuple_compare_with_key() */
typedef int (*tuple_compare_with_key_t)(const struct tuple *tuple_a,
const char *key,
Expand Down
2 changes: 1 addition & 1 deletion src/box/lua/space.cc
Expand Up @@ -203,7 +203,7 @@ lbox_fillspace(struct lua_State *L, struct space *space, int i)
lua_pushnumber(L, part->fieldno + TUPLE_INDEX_BASE);
lua_setfield(L, -2, "fieldno");

lua_pushboolean(L, part->is_nullable);
lua_pushboolean(L, key_part_is_nullable(part));
lua_setfield(L, -2, "is_nullable");

if (part->coll != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/box/tuple.c
Expand Up @@ -144,7 +144,7 @@ tuple_validate_raw(struct tuple_format *format, const char *tuple)
for (; i < defined_field_count; ++i, ++field) {
if (key_mp_type_validate(field->type, mp_typeof(*tuple),
ER_FIELD_TYPE, i + TUPLE_INDEX_BASE,
field->is_nullable))
tuple_field_is_nullable(field)))
return -1;
mp_next(&tuple);
}
Expand Down
17 changes: 10 additions & 7 deletions src/box/tuple_format.c
Expand Up @@ -158,12 +158,14 @@ tuple_format_create(struct tuple_format *format, struct key_def * const *keys,
struct tuple_field *field =
&format->fields[part->fieldno];
if (part->fieldno >= field_count) {
field->is_nullable = part->is_nullable;
} else if (field->is_nullable != part->is_nullable) {
field->is_nullable = key_part_is_nullable(part);
} else if (tuple_field_is_nullable(field) !=
key_part_is_nullable(part)) {
diag_set(ClientError, ER_NULLABLE_MISMATCH,
part->fieldno + TUPLE_INDEX_BASE,
field->is_nullable ? "nullable" :
"not nullable", part->is_nullable ?
tuple_field_is_nullable(field) ?
"nullable" : "not nullable",
key_part_is_nullable(part) ?
"nullable" : "not nullable");
return -1;
}
Expand Down Expand Up @@ -373,7 +375,8 @@ tuple_format_eq(const struct tuple_format *a, const struct tuple_format *b)
return false;
if (a->fields[i].is_key_part != b->fields[i].is_key_part)
return false;
if (a->fields[i].is_nullable != b->fields[i].is_nullable)
if (tuple_field_is_nullable(a->fields + i) !=
tuple_field_is_nullable(b->fields + i))
return false;
}
return true;
Expand Down Expand Up @@ -467,7 +470,7 @@ tuple_init_field_map(const struct tuple_format *format, uint32_t *field_map,
enum mp_type mp_type = mp_typeof(*pos);
const struct tuple_field *field = &format->fields[0];
if (key_mp_type_validate(field->type, mp_type, ER_FIELD_TYPE,
TUPLE_INDEX_BASE, field->is_nullable))
TUPLE_INDEX_BASE, tuple_field_is_nullable(field)))
return -1;
mp_next(&pos);
/* other fields...*/
Expand All @@ -478,7 +481,7 @@ tuple_init_field_map(const struct tuple_format *format, uint32_t *field_map,
mp_type = mp_typeof(*pos);
if (key_mp_type_validate(field->type, mp_type, ER_FIELD_TYPE,
i + TUPLE_INDEX_BASE,
field->is_nullable))
tuple_field_is_nullable(field)))
return -1;
if (field->offset_slot != TUPLE_OFFSET_SLOT_NIL) {
field_map[field->offset_slot] =
Expand Down
12 changes: 12 additions & 0 deletions src/box/tuple_format.h
Expand Up @@ -101,6 +101,18 @@ struct tuple_field {
bool is_nullable;
};

/**
* Get is_nullable property of tuple_field.
* @param tuple_field for which attribute is being fetched
*
* @retval boolean nullability attribute
*/
static inline bool
tuple_field_is_nullable(const struct tuple_field *tuple_field)
{
return tuple_field->is_nullable;
}

struct mh_strnu32_t;
typedef uint32_t (*field_name_hash_f)(const char *str, uint32_t len);
extern field_name_hash_f field_name_hash;
Expand Down

0 comments on commit ee0bdc9

Please sign in to comment.