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

Fix non-deterministic behaviors in IgniteSQLBuilder and IgniteStoreMetadataAnalyzer #296

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,13 @@ public void put(K key, T obj) throws GoraException {
Schema schema = obj.getSchema();
List<Schema.Field> fields = schema.getFields();
Map<Column, Object> data = new HashMap<>();
List<Column> dataKeyList = new ArrayList<>();
List<Object> dataValueList = new ArrayList<>();
if (igniteMapping.getPrimaryKey().size() == 1) {
Column getKey = igniteMapping.getPrimaryKey().get(0);
data.put(getKey, key);
dataKeyList.add(getKey);
dataValueList.add(key);
} else {
//Composite keys pending..
}
Expand All @@ -320,11 +324,13 @@ public void put(K key, T obj) throws GoraException {
Schema fieldSchema = field.schema();
Object serializedObj = serializeFieldValue(fieldSchema, fieldValue);
data.put(mappedColumn, serializedObj);
dataKeyList.add(mappedColumn);
dataValueList.add(serializedObj);
}
}
String baseInsertStatement = IgniteSQLBuilder.createInsertQuery(igniteMapping, data);
String baseInsertStatement = IgniteSQLBuilder.createInsertQuery(igniteMapping, dataKeyList);
try (PreparedStatement stmt = connection.prepareStatement(baseInsertStatement)) {
IgniteSQLBuilder.fillInsertQuery(stmt, data);
IgniteSQLBuilder.fillInsertQuery(stmt, dataValueList);
stmt.executeUpdate();
} catch (SQLException ex) {
throw new GoraException(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
Expand Down Expand Up @@ -64,6 +65,7 @@ public List<String> getTablesNames() throws GoraException {
} catch (SQLException ex) {
throw new GoraException(ex);
}
Collections.sort(tabs);
return tabs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ public static String dropTable(String tableName) {
* @param data A map containing the Column-Value pairs of the new record.
* @return SQL insert statement
*/
public static String createInsertQuery(IgniteMapping mapping, Map<Column, Object> data) {
public static String createInsertQuery(IgniteMapping mapping, List<Column> dataKeyList) {
DbSpec spec = new DbSpec();
DbSchema schema = spec.addDefaultSchema();
DbTable aTable = schema.addTable(mapping.getTableName());
InsertQuery insertQuery = new InsertQuery(aTable);
List<Entry<Column, Object>> list = new ArrayList<>(data.entrySet());
String[] columns = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
columns[i] = list.get(i).getKey().getName();
// List<Entry<Column, Object>> list = new ArrayList<>(data.entrySet());
String[] columns = new String[dataKeyList.size()];
for (int i = 0; i < dataKeyList.size(); i++) {
columns[i] = dataKeyList.get(i).getName();
}
return insertQuery.addCustomPreparedColumns(columns).validate().toString()
.replaceFirst("INSERT", "MERGE");
Expand All @@ -135,11 +135,11 @@ public static String createInsertQuery(IgniteMapping mapping, Map<Column, Object
* @throws SQLException When invalid values are provided as parameters for the
* insert statement.
*/
public static void fillInsertQuery(PreparedStatement statement, Map<Column, Object> insertData) throws SQLException {
List<Entry<Column, Object>> list = new ArrayList<>(insertData.entrySet());
for (int i = 0; i < list.size(); i++) {
public static void fillInsertQuery(PreparedStatement statement, List<Object> insertData) throws SQLException {
// List<Entry<Column, Object>> list = new ArrayList<>(insertData.entrySet());
for (int i = 0; i < insertData.size(); i++) {
int j = i + 1;
statement.setObject(j, list.get(i).getValue());
statement.setObject(j, insertData.get(i));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class TestIgniteStore extends DataStoreTestBase {
public void igniteStoreMetadataAnalyzerTest() throws Exception {
DataStoreMetadataAnalyzer createAnalyzer = DataStoreMetadataFactory.createAnalyzer(DataStoreTestBase.testDriver.getConfiguration());
Assert.assertEquals("Ignite Store Metadata Type", "IGNITE", createAnalyzer.getType());
Assert.assertTrue("Ignite Store Metadata Table Names", createAnalyzer.getTablesNames().equals(Lists.newArrayList("WEBPAGE", "EMPLOYEE")));
Assert.assertTrue("Ignite Store Metadata Table Names", createAnalyzer.getTablesNames().equals(Lists.newArrayList("EMPLOYEE", "WEBPAGE")));
IgniteTableMetadata tableInfo = (IgniteTableMetadata) createAnalyzer.getTableInfo("EMPLOYEE");
Assert.assertEquals("Ignite Store Metadata Table Primary Key Column", "PKSSN", tableInfo.getPrimaryKey());
Assert.assertEquals("Ignite Store Metadata Table Primary Key Type", "VARCHAR", tableInfo.getPrimaryKeyType());
Expand Down
Loading