Skip to content

Commit

Permalink
remove auto-null behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Jun 30, 2017
1 parent d3f1d5d commit 3ae6621
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 20 deletions.
6 changes: 3 additions & 3 deletions packages/spanner/src/transaction-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,9 @@ TransactionRequest.prototype.mutate_ = function(method, table, keyVals, cb) {
var columns = uniq(flatten(keyVals.map(Object.keys))).sort();

var values = keyVals.map(function(keyVal) {
return columns.map(function(key) {
var value = keyVal[key];
return codec.encode(is.undefined(value) ? null : value);
return columns.map(function(column) {
var value = keyVal[column];
return codec.encode(value);
});
});

Expand Down
37 changes: 31 additions & 6 deletions packages/spanner/system-test/spanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,43 @@ var spanner = new Spanner(env);
});

describe('uneven rows', function() {
it('should allow inserting uneven rows', function(done) {
table.insert([
it('should allow differently-ordered rows', function(done) {
var data = [
{
Key: generateName('id'),
BoolValue: true
BoolValue: true,
IntValue: spanner.int(10)
},
{
Key: generateName('id'),
BoolValue: true,
IntValue: 10
IntValue: spanner.int(10),
BoolValue: true
}
], done);
];

table.insert(data, function(err) {
assert.ifError(err);

database.run({
sql: `SELECT * FROM \`${table.name}\` WHERE Key = @a OR KEY = @b`,
params: {
a: data[0].Key,
b: data[1].Key
}
}, function(err, rows) {
assert.ifError(err);

var row1 = rows[0].toJSON();
assert.deepStrictEqual(row1.IntValue, data[0].IntValue);
assert.deepStrictEqual(row1.BoolValue, data[0].BoolValue);

var row2 = rows[1].toJSON();
assert.deepStrictEqual(row2.IntValue, data[1].IntValue);
assert.deepStrictEqual(row2.BoolValue, data[1].BoolValue);

done();
});
});
});
});

Expand Down
49 changes: 38 additions & 11 deletions packages/spanner/test/transaction-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,22 +760,36 @@ describe('TransactionRequest', function() {
var METHOD = 'methodName';
var TABLE = 'table-name';
var KEYVALS = [
{ key: 'value', nullable: true },
{ key: 'value' } // missing nullable value
{
key: '1-key-value',
anotherNullable: '1-anotherNullable-value',
nonNullable: '1-nonNullable-value',
nullable: '1-nullable-value'
},
{ /* keys defined in different order */
key: '2-key-value',
nullable: null,
nonNullable: '2-nonNullable-value',
anotherNullable: null
}
];

var EXPECTED_MUTATION = {};
EXPECTED_MUTATION[METHOD] = {
table: TABLE,
columns: ['key', 'nullable'],
columns: ['anotherNullable', 'key', 'nonNullable', 'nullable'],
values: [
[
KEYVALS[0].anotherNullable,
KEYVALS[0].key,
KEYVALS[0].nonNullable,
KEYVALS[0].nullable
],
[
KEYVALS[1].anotherNullable,
KEYVALS[1].key,
null
KEYVALS[1].nonNullable,
KEYVALS[1].nullable
]
]
};
Expand All @@ -797,22 +811,35 @@ describe('TransactionRequest', function() {

switch (numEncodeRequests) {
case 1: {
assert.strictEqual(value, KEYVALS[0].key);
assert.strictEqual(value, KEYVALS[0].anotherNullable);
break;
}

case 2: {
assert.strictEqual(value, KEYVALS[0].nullable);
assert.strictEqual(value, KEYVALS[0].key);
break;
}

case 3: {
assert.strictEqual(value, KEYVALS[1].key);
assert.strictEqual(value, KEYVALS[0].nonNullable);
break;
}

case 4: {
assert.strictEqual(value, null);
assert.strictEqual(value, KEYVALS[0].nullable);
break;
}
case 5: {
assert.strictEqual(value, KEYVALS[1].anotherNullable);
break;
}
case 6: {
assert.strictEqual(value, KEYVALS[1].key);
break;
}
case 7: {
assert.strictEqual(value, KEYVALS[1].nonNullable);
break;
}
case 8: {
assert.strictEqual(value, KEYVALS[1].nullable);
break;
}
}
Expand Down

0 comments on commit 3ae6621

Please sign in to comment.