-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for node-commons, some udfs and export、import-csv
- Loading branch information
1 parent
06c8c09
commit 312e749
Showing
5 changed files
with
102 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/BlobUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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.iotdb.commons.utils; | ||
|
||
import com.google.common.base.CharMatcher; | ||
|
||
import static java.util.Locale.ENGLISH; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class BlobUtils { | ||
|
||
private BlobUtils() {} | ||
|
||
// the grammar could possibly include whitespace in the value it passes to us | ||
private static final CharMatcher WHITESPACE_MATCHER = CharMatcher.whitespace(); | ||
private static final CharMatcher HEX_DIGIT_MATCHER = | ||
CharMatcher.inRange('A', 'F').or(CharMatcher.inRange('0', '9')).precomputed(); | ||
|
||
public static byte[] parseBlobString(String value) { | ||
requireNonNull(value, "value is null"); | ||
if (value.length() < 3 || !value.startsWith("X'") || !value.endsWith("'")) { | ||
throw new IllegalArgumentException("Binary literal must be in the form X'hexstring'"); | ||
} | ||
value = value.substring(2, value.length() - 1); | ||
String hexString = WHITESPACE_MATCHER.removeFrom(value).toUpperCase(ENGLISH); | ||
if (!HEX_DIGIT_MATCHER.matchesAllOf(hexString)) { | ||
throw new IllegalArgumentException("Binary literal can only contain hexadecimal digits"); | ||
} | ||
if (hexString.length() % 2 != 0) { | ||
throw new IllegalArgumentException("Binary literal must contain an even number of digits"); | ||
} | ||
int len = hexString.length(); | ||
byte[] values = new byte[len / 2]; | ||
|
||
for (int i = 0; i < len; i += 2) { | ||
values[i / 2] = | ||
(byte) | ||
((Character.digit(hexString.charAt(i), 16) << 4) | ||
+ Character.digit(hexString.charAt(i + 1), 16)); | ||
} | ||
return values; | ||
} | ||
} |