BaurzhanSakhariev commented on code in PR #3791: URL: https://github.com/apache/hop/pull/3791#discussion_r1570622754
########## plugins/databases/cratedb/src/test/java/org/apache/hop/databases/cratedb/CrateDBDatabaseMetaIT.java: ########## @@ -0,0 +1,201 @@ +/* + * 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.hop.databases.cratedb; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import org.apache.hop.core.row.value.ValueMetaDate; +import org.apache.hop.core.row.value.ValueMetaNumber; +import org.apache.hop.core.row.value.ValueMetaString; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.postgresql.util.PSQLException; +import org.testcontainers.cratedb.CrateDBContainer; + +public class CrateDBDatabaseMetaIT { + + @ClassRule public static CrateDBContainer crateDBContainer = new CrateDBContainer("crate"); + + private static Connection connection; + + private CrateDbDatabaseMeta nativeMeta = new CrateDbDatabaseMeta(); + + @BeforeClass + public static void setup() throws Exception { + connection = crateDBContainer.createConnection(""); + } + + @Before + public void setUp() throws Exception { + executeUpdate("DROP TABLE IF EXISTS foo;"); + executeUpdate("CREATE TABLE foo (id INT PRIMARY KEY, name VARCHAR(100), description TEXT);"); + } + + @Test + public void testSimpleSelect() throws Exception { + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery("SELECT 1"); + assertTrue(resultSet.next()); + assertEquals(1, resultSet.getInt(1)); + } + + @Test + public void doNotSupportSequences() { + assertFalse(nativeMeta.isSupportsSequences()); + assertThrows( + UnsupportedOperationException.class, + () -> executeUpdate(nativeMeta.getSqlListOfSequences())); + assertThrows( + UnsupportedOperationException.class, + () -> executeUpdate(nativeMeta.getSqlSequenceExists("FOO"))); + assertThrows( + UnsupportedOperationException.class, + () -> executeUpdate(nativeMeta.getSqlCurrentSequenceValue("FOO"))); + assertThrows( + UnsupportedOperationException.class, + () -> executeUpdate(nativeMeta.getSqlNextSequenceValue("FOO"))); + } + + @Test + public void sqlStatements() throws Exception { + executeUpdate( + "INSERT INTO foo (id, name, description) VALUES (1, 'Alice', 'test_description');"); + Thread.sleep(1500); // need a break to make sure the data is there: unfortunately, + // CrateDB does not support transactions, rather it promote eventual consistency. Review Comment: Hi, thanks for adding CrateDB support! FYI: you can use `refresh table foo` after insert statement. https://cratedb.com/docs/crate/reference/en/5.6/general/dql/refresh.html -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
