Skip to content

Commit bf2c5b1

Browse files
authored
Fix upper-case database name in TableSession error
1 parent 098306c commit bf2c5b1

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

integration-test/src/test/java/org/apache/iotdb/relational/it/session/IoTDBTableModelSessionIT.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,43 @@ public void testUseDatabase() {
112112
fail(e.getMessage());
113113
}
114114
}
115+
116+
@Test
117+
public void testCreateSessionWithCapitalDB() {
118+
final String[] table2Names = new String[] {"table2"};
119+
final String[] table2ttls = new String[] {"6600000"};
120+
121+
try (final ITableSession session =
122+
EnvFactory.getEnv().getTableSessionConnectionWithDB("TEST2")) {
123+
124+
session.executeNonQueryStatement("CREATE DATABASE test1");
125+
session.executeNonQueryStatement("CREATE DATABASE test2");
126+
127+
// or use full qualified table name
128+
session.executeNonQueryStatement(
129+
"create table test1.table1(region_id STRING ID, plant_id STRING ID, device_id STRING ID, model STRING ATTRIBUTE, temperature FLOAT MEASUREMENT, humidity DOUBLE MEASUREMENT) with (TTL=3600000)");
130+
131+
session.executeNonQueryStatement(
132+
"create table table2(region_id STRING ID, plant_id STRING ID, color STRING ATTRIBUTE, temperature FLOAT MEASUREMENT, speed DOUBLE MEASUREMENT) with (TTL=6600000)");
133+
134+
try (final SessionDataSet dataSet = session.executeQueryStatement("SHOW TABLES")) {
135+
int cnt = 0;
136+
assertEquals(showTablesColumnHeaders.size(), dataSet.getColumnNames().size());
137+
for (int i = 0; i < showTablesColumnHeaders.size(); i++) {
138+
assertEquals(
139+
showTablesColumnHeaders.get(i).getColumnName(), dataSet.getColumnNames().get(i));
140+
}
141+
while (dataSet.hasNext()) {
142+
final RowRecord rowRecord = dataSet.next();
143+
assertEquals(table2Names[cnt], rowRecord.getFields().get(0).getStringValue());
144+
assertEquals(table2ttls[cnt], rowRecord.getFields().get(1).getStringValue());
145+
cnt++;
146+
}
147+
assertEquals(table2Names.length, cnt);
148+
}
149+
150+
} catch (final IoTDBConnectionException | StatementExecutionException e) {
151+
fail(e.getMessage());
152+
}
153+
}
115154
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
import java.util.Collections;
209209
import java.util.HashMap;
210210
import java.util.List;
211+
import java.util.Locale;
211212
import java.util.Map;
212213
import java.util.Optional;
213214
import java.util.concurrent.TimeUnit;
@@ -1230,7 +1231,7 @@ public TSOpenSessionResp openSession(TSOpenSessionReq req) throws TException {
12301231
TSStatus tsStatus = RpcUtils.getStatus(openSessionResp.getCode(), openSessionResp.getMessage());
12311232

12321233
if (tsStatus.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode() && database.isPresent()) {
1233-
clientSession.setDatabaseName(database.get());
1234+
clientSession.setDatabaseName(database.get().toLowerCase(Locale.ENGLISH));
12341235
}
12351236
TSOpenSessionResp resp = new TSOpenSessionResp(tsStatus, CURRENT_RPC_VERSION);
12361237
Map<String, String> configuration = new HashMap<>();

0 commit comments

Comments
 (0)