Skip to content

In Session, the JDBC module can set the Boolean return data type to 0/1 or true/false.#1642

Closed
shutter-cp wants to merge 20 commits intoapache:masterfrom
shutter-cp:booleanType
Closed

In Session, the JDBC module can set the Boolean return data type to 0/1 or true/false.#1642
shutter-cp wants to merge 20 commits intoapache:masterfrom
shutter-cp:booleanType

Conversation

@shutter-cp
Copy link

可以通过在 Session,JDBC模块中可以设置Boolean的返回数据类型为0/1或true/false
In Session, the JDBC module can set the Boolean return data type to 0/1 or true/false.

SessionExample

Map<String,String> map = new HashMap<>();
map.put("boolFormat", "number");
//map.put("boolFormat", "bool");
session = new Session("127.0.0.1", 6667, "root", "root",map);

JDBCExample

Connection connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/?boolFormat=number", "root", "root");
// Connection connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/?boolFormat=bool", "root", "root");

将来需要传输多个参数也能支持如:
The need to transfer multiple parameters in the future can also be supported such as:
SessionExample

Map<String,String> map = new HashMap<>();
map.put("boolFormat", "number");
map.put("key", "value");
session = new Session("127.0.0.1", 6667, "root", "root",map);

JDBCExample

Connection connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/?boolFormat=number&&key=value", "root", "root");

Copy link
Contributor

@HTHou HTHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good job. I marked some format issues. It will be great if you fix them.
Also, I think it's necessary to add these interface changes into User Guide docs to tell users.
By the way, the Travis CI has many errors, please fix them. Big thanks!

Comment on lines +1 to +11
package org.apache.iotdb.rpc;


/**
* @author chenPeng
* @version 1.0.0
* @ClassName Config.java
* @Description TODO
* @createTime 2020年08月19日 22:26:00
*/
public class Config {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Apache header here...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this header to all new files.

/*
 * 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.
 */

shutter-cp and others added 13 commits September 12, 2020 00:45
Let me change that

Co-authored-by: Haonan <hhaonan@outlook.com>
Co-authored-by: Haonan <hhaonan@outlook.com>
Co-authored-by: Haonan <hhaonan@outlook.com>
Co-authored-by: Haonan <hhaonan@outlook.com>
Co-authored-by: Haonan <hhaonan@outlook.com>
….java

Co-authored-by: Haonan <hhaonan@outlook.com>
Co-authored-by: Haonan <hhaonan@outlook.com>
…java

Co-authored-by: Haonan <hhaonan@outlook.com>
Co-authored-by: Haonan <hhaonan@outlook.com>
Co-authored-by: Haonan <hhaonan@outlook.com>
@shutter-cp shutter-cp requested a review from HTHou September 11, 2020 17:37
Copy link
Contributor

@HTHou HTHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a conflict needs to be fixed.

@shutter-cp shutter-cp requested a review from HTHou September 14, 2020 13:25
Co-authored-by: Haonan <hhaonan@outlook.com>
@shutter-cp shutter-cp requested a review from HTHou September 14, 2020 14:12
Copy link
Contributor

@HTHou HTHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI failed, please take a look.

Copy link
Member

@qiaojialin qiaojialin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! Please add ITs in jdbc and Session module. And update the docs/UserGuide/Client and docs/UserGuide/zh/Client.

@shutter-cp shutter-cp requested a review from HTHou September 20, 2020 12:07
Comment on lines +96 to +101
if (org.apache.iotdb.rpc.Config.boolFormat == org.apache.iotdb.rpc.Config.Constant.BOOLEAN) {
field.setBoolV(booleanValue);
} else {
field = new Field(TSDataType.deserialize((short) 1));
field.setIntV(booleanValue ? 1 : 0);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I think we should not change the type of Field. This issue only changes how the getString() method returns data.

Comment on lines +96 to +101
session.insertRecord(deviceId, 1L, measurements, dataTypes, values);

String expected = "1";
SessionDataSet dataSet = session.executeQueryStatement("select s2 from root.sg1.d1");
while (dataSet.hasNext()) {
List<Field> fields = dataSet.next().getFields();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, you could use the SessionDataSet.Iterator() to get the iterator and use the iterator.getString() that triggers the config.

Comment on lines 32 to 34
Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
try (Connection connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
try (Connection connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/?boolFormat=bool", "root", "root");
Statement statement = connection.createStatement()) {
Copy link
Contributor

@HTHou HTHou Sep 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't indicate ?boolFormat=bool, is there any problem?
If not, I think we'd better keep the old example to show we don't have to do such setting when getting a normal JDBC connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants