blob: 6e9d2121f37914417d28a6bb221b17afa013c21f [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.cql3.validation.operations;
import org.junit.Test;
import org.apache.cassandra.cql3.CQLTester;
public class InsertTest extends CQLTester
{
@Test
public void testInsertWithUnset() throws Throwable
{
createTable("CREATE TABLE %s (k int PRIMARY KEY, s text, i int)");
// insert using nulls
execute("INSERT INTO %s (k, s, i) VALUES (10, ?, ?)", "text", 10);
execute("INSERT INTO %s (k, s, i) VALUES (10, ?, ?)", null, null);
assertRows(execute("SELECT s, i FROM %s WHERE k = 10"),
row(null, null) // sending null deletes the data
);
// insert using UNSET
execute("INSERT INTO %s (k, s, i) VALUES (11, ?, ?)", "text", 10);
execute("INSERT INTO %s (k, s, i) VALUES (11, ?, ?)", unset(), unset());
assertRows(execute("SELECT s, i FROM %s WHERE k=11"),
row("text", 10) // unset columns does not delete the existing data
);
assertInvalidMessage("Invalid unset value for column k", "UPDATE %s SET i = 0 WHERE k = ?", unset());
assertInvalidMessage("Invalid unset value for column k", "DELETE FROM %s WHERE k = ?", unset());
assertInvalidMessage("Invalid unset value for argument in call to function blobasint", "SELECT * FROM %s WHERE k = blobAsInt(?)", unset());
}
@Test
public void testInsertTtlWithUnset() throws Throwable
{
createTable("CREATE TABLE %s (k int PRIMARY KEY, i int)");
execute("INSERT INTO %s (k, i) VALUES (1, 1) USING TTL ?", unset()); // treat as 'unlimited'
assertRows(execute("SELECT ttl(i) FROM %s"),
row(new Object[]{ null })
);
}
}