diff --git a/packages/spanner/src/transaction-request.js b/packages/spanner/src/transaction-request.js index bc9c2bcedc5..9b7e949cec7 100644 --- a/packages/spanner/src/transaction-request.js +++ b/packages/spanner/src/transaction-request.js @@ -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); }); }); diff --git a/packages/spanner/system-test/spanner.js b/packages/spanner/system-test/spanner.js index a1b06b60ab7..ba1423f7d65 100644 --- a/packages/spanner/system-test/spanner.js +++ b/packages/spanner/system-test/spanner.js @@ -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(); + }); + }); }); }); diff --git a/packages/spanner/test/transaction-request.js b/packages/spanner/test/transaction-request.js index 60efd3829d0..ff8470aa6ea 100644 --- a/packages/spanner/test/transaction-request.js +++ b/packages/spanner/test/transaction-request.js @@ -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 ] ] }; @@ -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; } }