Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GlobalSecondaryIndexes with projection creates the field with double quotation marks #59

Open
rbodoque opened this issue Oct 5, 2016 · 3 comments

Comments

@rbodoque
Copy link

rbodoque commented Oct 5, 2016

Hello
I have a json definition like that

{
    "AttributeDefinitions": [{
        "AttributeName": "UserName",
        "AttributeType": "S"
    },
    {
        "AttributeName": "Email",
        "AttributeType": "S"
    },
    {
        "AttributeName": "LastName",
        "AttributeType": "S"
    }],
    "TableName": "CustomerService_User",
    "KeySchema": [{
        "AttributeName": "UserName",
        "KeyType": "HASH"
    }],
    "GlobalSecondaryIndexes": [{
        "IndexName": "EmailLastNameIndex",
        "KeySchema": [{
            "AttributeName": "Email",
            "KeyType": "HASH"
        },
        {
            "AttributeName": "LastName",
            "KeyType": "RANGE"
        }],
        "Projection": {
            "NonKeyAttributes": ["FirstName"],
            "ProjectionType": "INCLUDE"
        },
        "ProvisionedThroughput": {
            "ReadCapacityUnits": "1",
            "WriteCapacityUnits": "1"
        }
    }],
    "ProvisionedThroughput": {
        "ReadCapacityUnits": "1",
        "WriteCapacityUnits": "1"
    }

}

As you can see in the Projection of the GlobalSecondaryIndexes there is one field "FirstName" that needs to be projected to the index.

When I create the table by maven and then query Dynamo for describe the table it returns:

{
    Table: {
        AttributeDefinitions: [{
            AttributeName: UserName,
            AttributeType: S
        },
        {
            AttributeName: Email,
            AttributeType: S
        },
        {
            AttributeName: LastName,
            AttributeType: S
        }],
        TableName: CustomerService_User,
        KeySchema: [{
            AttributeName: UserName,
            KeyType: HASH
        }],
        TableStatus: ACTIVE,
        CreationDateTime: WedOct0505: 26: 04PDT2016,
        ProvisionedThroughput: {
            LastIncreaseDateTime: WedDec3116: 00: 00PST1969,
            LastDecreaseDateTime: WedDec3116: 00: 00PST1969,
            NumberOfDecreasesToday: 0,
            ReadCapacityUnits: 1,
            WriteCapacityUnits: 1
        },
        TableSizeBytes: 218,
        ItemCount: 1,
        TableArn: arn: aws: dynamodb: ddblocal: 000000000000: table/CustomerService_User,
        GlobalSecondaryIndexes: [{
            IndexName: EmailLastNameIndex,
            KeySchema: [{
                AttributeName: Email,
                KeyType: HASH
            },
            {
                AttributeName: LastName,
                KeyType: RANGE
            }],
            Projection: {
                ProjectionType: INCLUDE,
                NonKeyAttributes: ["FirstName"]
            },
            IndexStatus: ACTIVE,
            ProvisionedThroughput: {
                ReadCapacityUnits: 1,
                WriteCapacityUnits: 1
            },
            IndexSizeBytes: 218,
            ItemCount: 1,
            IndexArn: arn: aws: dynamodb: ddblocal: 000000000000: table/CustomerService_User/index/EmailLastNameIndex
        }],

    }
}

As you can see the projection is created with double quotation marks

Projection: {ProjectionType: INCLUDE,NonKeyAttributes: ["FirstName"]}

I think the issue is in com.jcabi.dynamodb.core.Tables in the method

private Projection projection(final JsonObject json)

in the line 290 is doing

nonkeyattrs.add(nonkey.toString());

And this causes put the double quotation.

Maybe a solution could be change to something like

JsonString nonkeyStr = (JsonString)nonkey;
nonkeyattrs.add(nonkeyStr.getString());

thanks
Rafa

@dmarkov
Copy link

dmarkov commented Oct 10, 2016

@yegor256 please dispatch this issue

@yegor256
Copy link
Member

yegor256 commented Nov 23, 2016

@rbodoque I'm not sure I understand the problem. What do you expect to see there instead of "FirstName"? Also, this code:

x = (JsonString) y;
print(y.toString());

is equivalent to:

print(x.toString());

@rbodoque
Copy link
Author

rbodoque commented Mar 20, 2017

Hello @yegor256 sorry for the late response, Time ago that I'm not working with this.

I think assumption is not correct I mean =>
x = (JsonString) y;
print(y.toString());
is equivalent to:

print(x.toString());

for show you I've created this simple test https://github.com/rbodoque/-jacabitest.git

the test is the method

private static void projection(final JsonObject json) {
        final JsonObject projn = json.getJsonObject("Projection");
//        final Projection projection = new Projection()
//            .withProjectionType(projn.getString("ProjectionType"));
        final Collection<String> nonkeyattrs = new LinkedList<String>();
        if (projn.containsKey("NonKeyAttributes")) {
            for (final JsonValue nonkey
                : projn.getJsonArray("NonKeyAttributes")) {
                //nonkeyattrs.add(nonkey.toString());
                System.out.println(nonkey.toString());
                JsonString nonkeyStr = (JsonString)nonkey;
                //nonkeyattrs.add(nonkeyStr.getString());
                System.out.println(nonkeyStr.getString());
                
                
            }
           // projection.setNonKeyAttributes(nonkeyattrs);
        }
        //return projection;
    }

If both were the same it will print FirstName twice but what is printing is

"FirstName"
FirstName

I think this is because the current implementation is executing this code
https://java.net/projects/jsonp/sources/git/content/impl/src/main/java/org/glassfish/json/JsonStringImpl.java => line 93. As you can see it first add the quotation marks

What the issue is causing it creates a projection but with the "FirstName" column instead of the FirstName column

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants