Skip to content

Commit 1b2f945

Browse files
authored
feat: optimize java sdk (#3445)
1 parent 1792700 commit 1b2f945

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3930
-1300
lines changed

hybridse/examples/toydb/src/sdk/result_set_impl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class ResultSetImpl : public ResultSet {
7171

7272
inline int32_t Size() { return response_->count(); }
7373

74+
void CopyTo(hybridse::sdk::ByteArrayPtr buf) override {
75+
cntl_->response_attachment().copy_to(reinterpret_cast<void*>(buf));
76+
}
77+
78+
int32_t GetDataLength() override {
79+
return cntl_->response_attachment().size();
80+
}
81+
7482
private:
7583
inline uint32_t GetRecordSize() { return response_->count(); }
7684

hybridse/include/sdk/base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class ProcedureInfo {
134134
virtual ProcedureType GetType() const = 0;
135135
virtual const std::string* GetOption(const std::string& key) const = 0;
136136
virtual const std::unordered_map<std::string, std::string>* GetOption() const = 0;
137+
virtual int GetRouterCol() const = 0;
137138
};
138139

139140
} // namespace sdk

hybridse/include/sdk/result_set.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
namespace hybridse {
2727
namespace sdk {
28+
29+
typedef char* ByteArrayPtr;
30+
2831
struct Date {
2932
int32_t year;
3033
int32_t month;
@@ -235,6 +238,9 @@ class ResultSet {
235238
virtual bool IsNULL(int index) = 0;
236239

237240
virtual int32_t Size() = 0;
241+
242+
virtual void CopyTo(hybridse::sdk::ByteArrayPtr buf) = 0;
243+
virtual int32_t GetDataLength() = 0;
238244
};
239245

240246
} // namespace sdk
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2021 4Paradigm
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com._4paradigm.openmldb.common.codec;
18+
19+
public class ByteBitMap {
20+
private int size;
21+
private int length;
22+
private byte[] buf;
23+
24+
public ByteBitMap(int sizeInBits) {
25+
size = sizeInBits;
26+
length = (sizeInBits >> 3) + ((sizeInBits & 0x07) == 0 ? 0 : 1);
27+
buf = new byte[length];
28+
}
29+
30+
public int size() {
31+
return this.size;
32+
}
33+
34+
public boolean at(int offset) {
35+
int index = indexFor(offset);
36+
return (buf[index] & (1 << (offset & 0x07))) > 0;
37+
}
38+
39+
public void atPut(int offset, boolean value) {
40+
int index = indexFor(offset);
41+
buf[index] |= (1 << (offset & 0x07));
42+
}
43+
44+
public void clear() {
45+
for (int i = 0; i < length; i++) {
46+
buf[i] = 0;
47+
}
48+
}
49+
50+
public byte[] getBuffer() {
51+
return buf;
52+
}
53+
54+
public boolean allSetted() {
55+
if ((size & 0x07) == 0) {
56+
for (int i = 0; i < length; i++) {
57+
if (buf[i] != (byte)0xFF) {
58+
return false;
59+
}
60+
}
61+
} else {
62+
for (int i = 0; i < length - 1; i++) {
63+
if (buf[i] != (byte)0xFF) {
64+
return false;
65+
}
66+
}
67+
int val = (1 << (size & 0x07)) - 1;
68+
if (buf[length - 1] != val) {
69+
return false;
70+
}
71+
}
72+
return true;
73+
}
74+
75+
private int indexFor(int offset) {
76+
return offset >> 3;
77+
}
78+
}

0 commit comments

Comments
 (0)