Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Fixes #1632 #1677

Merged
merged 6 commits into from Oct 5, 2018
Merged

Fixes #1632 #1677

merged 6 commits into from Oct 5, 2018

Conversation

yuce
Copy link
Contributor

@yuce yuce commented Oct 3, 2018

Overview

[Describe what this pull request addresses.]

Fixes #1632

Pull request checklist

Code review checklist

This is the checklist that the reviewer will follow while reviewing your pull request. You do not need to do anything with this checklist, but be aware of what the reviewer will be looking for.

  • Ensure that any changes to external docs have been included in this pull request.
  • If the changes require that minor/major versions need to be updated, tag the PR appropriately.
  • Ensure the new code is properly commented and follows Idiomatic Go.
  • Check that tests have been written and that they cover the new functionality.
  • Run tests and ensure they pass.
  • Build and run the code, performing any applicable integration testing.

Copy link
Member

@travisturner travisturner left a comment

Choose a reason for hiding this comment

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

This looks good, but there are some issues when column keys are used.

  1. executor.translateCall() needs to contain SetColumnAttrs like this:
if c.Name == "Set" || c.Name == "Clear" || c.Name == "Row" || c.Name == "SetColumnAttrs" {

This is a separate bug, but it causes problems with testing this PR. It's related to #1679. In fact, we should probably audit that method to ensure that all possible query types are handling the translate calls correctly there.

  1. with keys, the output ends up looking like this:
  "columnAttrs": [
    {
      "id": 0,
      "key": "one",
      "attrs": {
        "name": "To Kill a Mockingbird",
        "year": 1960
      }
    },
    {
      "id": 0,
      "key": "two",
      "attrs": {
        "name": "No Name in the Street",
        "year": 1972
      }
    }
    }
  ]

It would be nice if we could suppress that "id": 0, from the output when a key is present. It seems like we've done that elsewhere.

  1. We should add a test that covers the columnAttr key translation.

executor.go Outdated

// Translate column attributes, if necessary.
if e.Holder.translateFile != nil {
for _, col := range resp.ColumnAttrSets {
Copy link
Member

Choose a reason for hiding this comment

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

resp.ColumnAttrSets needs to be columnAttrSets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't that break compatibility with Pilosa 1.0 ?

Copy link
Member

Choose a reason for hiding this comment

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

I mean that this range loop is using the wrong argument.
resp.ColumnAttrSets is empty, but columnAttrSets was populated in the code block above.
The range needs to loop over columnAttrSets.

executor.go Outdated
}

// Translate column attributes, if necessary.
if e.Holder.translateFile != nil {
Copy link
Member

Choose a reason for hiding this comment

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

this line should be

if idx.Keys() {

executor.go Show resolved Hide resolved
@yuce
Copy link
Contributor Author

yuce commented Oct 5, 2018

Updated

executor.go Outdated
func (e *executor) translateCall(index string, idx *Index, c *pql.Call) error {
var colKey, rowKey, fieldName string
if c.Name == "Set" || c.Name == "Clear" || c.Name == "Row" {
Copy link
Member

Choose a reason for hiding this comment

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

I definitely like the idea of cleaning this up, but let's make it a switch statement instead of a map lookup:

switch c.Name {
case: "Set", "Clear", "Row", "SetColumnAttrs":
    ...
case: "SetRowAttrs":
    ...
default:
    ...
}

Copy link
Member

Choose a reason for hiding this comment

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

@yuce I just merged #1679 which actually implements this switch, so you can just rebase master for the update, and add in "SetColumnAttrs".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -117,7 +117,7 @@ var nameRegexp = regexp.MustCompile(`^[a-z][a-z0-9_-]{0,63}$`)
// ColumnAttrSet represents a set of attributes for a vertical column in an index.
// Can have a set of attributes attached to it.
type ColumnAttrSet struct {
ID uint64 `json:"id"`
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this works for the case where ID is actually supposed to be 0 (with no column key). Should we open a ticket to write a custom JSON marshaler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do we try to remove ID from the result in the first place ?

Copy link
Member

Choose a reason for hiding this comment

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

Well, we omit the key when it doesn't apply, so it seems to make sense to omit the ID when it doesn't apply. And when there is a key, the ID is always 0, so it's not really useful anyway. I don't have a strong opinion on this, however. I'll make a ticket suggesting we revisit that output and it can be discussed there.

@yuce yuce merged commit 396ec6e into FeatureBaseDB:master Oct 5, 2018
@yuce yuce deleted the 1632-move-columnattrs branch October 5, 2018 19:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

columnAttrs logic should be in executor, not API
2 participants