You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/03/06 06:16:04 UTC
[GitHub] [calcite] ritesh-kapoor opened a new pull request #1847:
[CALCITE-3647] MySQL COMPRESS function support
ritesh-kapoor opened a new pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] DonnyZone commented on a change in pull request #1847:
[CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
DonnyZone commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r390267449
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
Review comment:
Moreover, there is a topic on Java's implementation of MySQL's `compress()` function in StackOverflow.
https://stackoverflow.com/questions/39460906/java-emulation-of-mysql-comress-decompress-functions
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] XuQianJin-Stars commented on a change in pull request
#1847: [CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
XuQianJin-Stars commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r391442945
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
Review comment:
@ritesh-kapoor @DonnyZone @danny0405 Regarding compression algorithm support, I also noticed that Mysql8 provides the following support.
> The compression algorithms that the server permits for incoming connections. These include connections by client programs and by servers participating in master/slave replication or Group Replication. Compression does not apply to connections for FEDERATED tables.
> protocol_compression_algorithms does not control connection compression for X Protocol. See Section 20.5.5, “Connection Compression with X Plugin” for information on how this operates.
> The variable value is a list of one or more comma-separated compression algorithm names, in any order, chosen from the following items (not case-sensitive):
> zlib: Permit connections that use the zlib compression algorithm.
> zstd: Permit connections that use the zstd compression algorithm (zstd 1.3).
> uncompressed: Permit uncompressed connections. If this algorithm name is not included in the protocol_compression_algorithms value, the server does not permit uncompressed connections. It permits only compressed connections that use whichever other algorithms are specified in the value, and there is no fallback to uncompressed connections.
> The default value of zlib,zstd,uncompressed indicates that the server permits all compression algorithms.
https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_protocol_compression_algorithms
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] danny0405 commented on a change in pull request #1847:
[CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r391482267
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
Review comment:
Thanks @XuQianJin-Stars for the doc, it seems that the page you reference here is about the system variables of MySQL server, not the `COMPRESS` function.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] danny0405 commented on a change in pull request #1847:
[CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r390168957
##########
File path: core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
##########
@@ -172,6 +172,12 @@ private SqlLibraryOperators() {
@LibraryOperator(libraries = {MYSQL, ORACLE})
public static final SqlFunction REGEXP_REPLACE = new SqlRegexpReplaceFunction();
+ @LibraryOperator(libraries = {MYSQL})
+ public static final SqlFunction COMPRESS = new SqlFunction("COMPRESS", SqlKind.OTHER_FUNCTION,
+ ReturnTypes.cascade(ReturnTypes.explicit(SqlTypeName.VARBINARY),
+ SqlTypeTransforms.TO_NULLABLE), null, OperandTypes.STRING, SqlFunctionCategory.SYSTEM);
+
Review comment:
Should be `SqlFunctionCategory.SYSTEM` or `SqlFunctionCategory.STRING` ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] ritesh-kapoor commented on a change in pull request
#1847: [CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
ritesh-kapoor commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r391083196
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ByteBuffer dataLength = ByteBuffer.allocate(4);
+ dataLength.order(ByteOrder.LITTLE_ENDIAN);
+ dataLength.putInt(data.length());
+ outputStream.write(dataLength.array());
+ DeflaterOutputStream inflaterStream = new DeflaterOutputStream(outputStream);
+ inflaterStream.write(data.getBytes(Charset.defaultCharset()));
+ inflaterStream.close();
Review comment:
@danny0405 Seems like there is some confusion, The current implementation does compression please refer test cases and attached MySQL output: :)
```
mysql> select hex(compress(''));
+-------------------+
| hex(compress('')) |
+-------------------+
| |
+-------------------+
1 row in set (0.00 sec)
mysql> select hex(COMPRESS(REPEAT('a',1000)));
+--------------------------------------------+
| hex(COMPRESS(REPEAT('a',1000))) |
+--------------------------------------------+
| E8030000789C4B4C1C05A360140C770000F9D87AF8 |
+--------------------------------------------+
1 row in set (0.00 sec)
mysql> select hex(compress(REPEAT('a',16)));
+--------------------------------+
| hex(compress(REPEAT('a',16))) |
+--------------------------------+
| 10000000789C4B4C44050033980611 |
+--------------------------------+
1 row in set (0.00 sec)
mysql> select hex(COMPRESS('sample'));
+--------------------------------------+
| hex(COMPRESS('sample')) |
+--------------------------------------+
| 06000000789C2B4ECC2DC849050008DE0283 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> select hex(COMPRESS('example'));
+----------------------------------------+
| hex(COMPRESS('example')) |
+----------------------------------------+
| 07000000789C4BAD48CC2DC84905000BC002ED |
+----------------------------------------+
1 row in set (0.00 sec)
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] danny0405 commented on a change in pull request #1847:
[CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r390868770
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ByteBuffer dataLength = ByteBuffer.allocate(4);
+ dataLength.order(ByteOrder.LITTLE_ENDIAN);
+ dataLength.putInt(data.length());
+ outputStream.write(dataLength.array());
+ DeflaterOutputStream inflaterStream = new DeflaterOutputStream(outputStream);
+ inflaterStream.write(data.getBytes(Charset.defaultCharset()));
+ inflaterStream.close();
Review comment:
From current code, it seems that there is no compression really, it's equivalent to `CAST(varchar as varbinary)` except that there is a header to mark the bytes length.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] ritesh-kapoor commented on a change in pull request
#1847: [CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
ritesh-kapoor commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r391082295
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
Review comment:
@DonnyZone I have added more test cases, DeflaterOutputStream is based on Deflater. Implementation is similar to what you have suggested :)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] danny0405 commented on a change in pull request #1847:
[CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r390171340
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ByteBuffer dataLength = ByteBuffer.allocate(4);
+ dataLength.order(ByteOrder.LITTLE_ENDIAN);
+ dataLength.putInt(data.length());
+ outputStream.write(dataLength.array());
+ DeflaterOutputStream inflaterStream = new DeflaterOutputStream(outputStream);
+ inflaterStream.write(data.getBytes(Charset.defaultCharset()));
+ inflaterStream.close();
Review comment:
The MySQL says that
> This function requires MySQL to have been compiled with a compression library such as zlib
Should we follow that ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] ritesh-kapoor commented on a change in pull request
#1847: [CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
ritesh-kapoor commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r390243800
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ByteBuffer dataLength = ByteBuffer.allocate(4);
+ dataLength.order(ByteOrder.LITTLE_ENDIAN);
+ dataLength.putInt(data.length());
+ outputStream.write(dataLength.array());
+ DeflaterOutputStream inflaterStream = new DeflaterOutputStream(outputStream);
+ inflaterStream.write(data.getBytes(Charset.defaultCharset()));
+ inflaterStream.close();
Review comment:
I have validated the functionality by executing same function query on MySQL server. Please let me know if I have misunderstood the question.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] danny0405 commented on a change in pull request #1847:
[CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r391480780
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ByteBuffer dataLength = ByteBuffer.allocate(4);
+ dataLength.order(ByteOrder.LITTLE_ENDIAN);
+ dataLength.putInt(data.length());
+ outputStream.write(dataLength.array());
+ DeflaterOutputStream inflaterStream = new DeflaterOutputStream(outputStream);
+ inflaterStream.write(data.getBytes(Charset.defaultCharset()));
+ inflaterStream.close();
Review comment:
My fault, i didn't notice that there is a `DeflaterOutputStream`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] ritesh-kapoor commented on a change in pull request
#1847: [CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
ritesh-kapoor commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r391083196
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ByteBuffer dataLength = ByteBuffer.allocate(4);
+ dataLength.order(ByteOrder.LITTLE_ENDIAN);
+ dataLength.putInt(data.length());
+ outputStream.write(dataLength.array());
+ DeflaterOutputStream inflaterStream = new DeflaterOutputStream(outputStream);
+ inflaterStream.write(data.getBytes(Charset.defaultCharset()));
+ inflaterStream.close();
Review comment:
@danny0405 Seems like there is some confusion, The current implementation does compression please refer test cases and attached MySQL output:
`mysql> select hex(compress(''));
+-------------------+
| hex(compress('')) |
+-------------------+
| |
+-------------------+
1 row in set (0.00 sec)
mysql> select hex(COMPRESS(REPEAT('a',1000)));
+--------------------------------------------+
| hex(COMPRESS(REPEAT('a',1000))) |
+--------------------------------------------+
| E8030000789C4B4C1C05A360140C770000F9D87AF8 |
+--------------------------------------------+
1 row in set (0.00 sec)
mysql> select hex(compress(REPEAT('a',16)));
+--------------------------------+
| hex(compress(REPEAT('a',16))) |
+--------------------------------+
| 10000000789C4B4C44050033980611 |
+--------------------------------+
1 row in set (0.00 sec)
mysql> select hex(COMPRESS('sample'));
+--------------------------------------+
| hex(COMPRESS('sample')) |
+--------------------------------------+
| 06000000789C2B4ECC2DC849050008DE0283 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> select hex(COMPRESS('example'));
+----------------------------------------+
| hex(COMPRESS('example')) |
+----------------------------------------+
| 07000000789C4BAD48CC2DC84905000BC002ED |
+----------------------------------------+
1 row in set (0.00 sec)`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] ritesh-kapoor commented on a change in pull request
#1847: [CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
ritesh-kapoor commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r391083196
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ByteBuffer dataLength = ByteBuffer.allocate(4);
+ dataLength.order(ByteOrder.LITTLE_ENDIAN);
+ dataLength.putInt(data.length());
+ outputStream.write(dataLength.array());
+ DeflaterOutputStream inflaterStream = new DeflaterOutputStream(outputStream);
+ inflaterStream.write(data.getBytes(Charset.defaultCharset()));
+ inflaterStream.close();
Review comment:
@danny0405 Seems like there is some confusion, The current implementation does compression please refer test cases and attached MySQL output:
```
mysql> select hex(compress(''));
+-------------------+
| hex(compress('')) |
+-------------------+
| |
+-------------------+
1 row in set (0.00 sec)
mysql> select hex(COMPRESS(REPEAT('a',1000)));
+--------------------------------------------+
| hex(COMPRESS(REPEAT('a',1000))) |
+--------------------------------------------+
| E8030000789C4B4C1C05A360140C770000F9D87AF8 |
+--------------------------------------------+
1 row in set (0.00 sec)
mysql> select hex(compress(REPEAT('a',16)));
+--------------------------------+
| hex(compress(REPEAT('a',16))) |
+--------------------------------+
| 10000000789C4B4C44050033980611 |
+--------------------------------+
1 row in set (0.00 sec)
mysql> select hex(COMPRESS('sample'));
+--------------------------------------+
| hex(COMPRESS('sample')) |
+--------------------------------------+
| 06000000789C2B4ECC2DC849050008DE0283 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> select hex(COMPRESS('example'));
+----------------------------------------+
| hex(COMPRESS('example')) |
+----------------------------------------+
| 07000000789C4BAD48CC2DC84905000BC002ED |
+----------------------------------------+
1 row in set (0.00 sec)
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] ritesh-kapoor commented on a change in pull request
#1847: [CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
ritesh-kapoor commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r390241758
##########
File path: core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
##########
@@ -172,6 +172,12 @@ private SqlLibraryOperators() {
@LibraryOperator(libraries = {MYSQL, ORACLE})
public static final SqlFunction REGEXP_REPLACE = new SqlRegexpReplaceFunction();
+ @LibraryOperator(libraries = {MYSQL})
+ public static final SqlFunction COMPRESS = new SqlFunction("COMPRESS", SqlKind.OTHER_FUNCTION,
+ ReturnTypes.cascade(ReturnTypes.explicit(SqlTypeName.VARBINARY),
+ SqlTypeTransforms.TO_NULLABLE), null, OperandTypes.STRING, SqlFunctionCategory.SYSTEM);
+
Review comment:
Thanks @danny0405. I have made the changes
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] ritesh-kapoor commented on a change in pull request
#1847: [CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
ritesh-kapoor commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r391701029
##########
File path: site/_docs/reference.md
##########
@@ -2320,6 +2320,7 @@ semantics.
| o | CHR(integer) | Returns the character having the binary equivalent to *integer* as a CHAR value
| o | COSH(numeric) | Returns the hyperbolic cosine of *numeric*
| m o p | CONCAT(string [, string ]*) | Concatenates two or more strings
+| m | COMPRESS(string) | Compresses a string and returns the result as a binary string.
| p | CONVERT_TIMEZONE(tz1, tz2, datetime) | Converts the timezone of *datetime* from *tz1* to *tz2*
Review comment:
Done :)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] ritesh-kapoor commented on a change in pull request
#1847: [CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
ritesh-kapoor commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r391083196
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ByteBuffer dataLength = ByteBuffer.allocate(4);
+ dataLength.order(ByteOrder.LITTLE_ENDIAN);
+ dataLength.putInt(data.length());
+ outputStream.write(dataLength.array());
+ DeflaterOutputStream inflaterStream = new DeflaterOutputStream(outputStream);
+ inflaterStream.write(data.getBytes(Charset.defaultCharset()));
+ inflaterStream.close();
Review comment:
@danny0405 Seems like there is some confusion, The current implementation does compression please refer test cases and attached MySQL output:
mysql> select hex(compress(''));
```
+-------------------+
| hex(compress('')) |
+-------------------+
| |
+-------------------+
1 row in set (0.00 sec)
mysql> select hex(COMPRESS(REPEAT('a',1000)));
+--------------------------------------------+
| hex(COMPRESS(REPEAT('a',1000))) |
+--------------------------------------------+
| E8030000789C4B4C1C05A360140C770000F9D87AF8 |
+--------------------------------------------+
1 row in set (0.00 sec)
mysql> select hex(compress(REPEAT('a',16)));
+--------------------------------+
| hex(compress(REPEAT('a',16))) |
+--------------------------------+
| 10000000789C4B4C44050033980611 |
+--------------------------------+
1 row in set (0.00 sec)
mysql> select hex(COMPRESS('sample'));
+--------------------------------------+
| hex(COMPRESS('sample')) |
+--------------------------------------+
| 06000000789C2B4ECC2DC849050008DE0283 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> select hex(COMPRESS('example'));
+----------------------------------------+
| hex(COMPRESS('example')) |
+----------------------------------------+
| 07000000789C4BAD48CC2DC84905000BC002ED |
+----------------------------------------+
1 row in set (0.00 sec)
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] danny0405 commented on a change in pull request #1847:
[CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r391483126
##########
File path: site/_docs/reference.md
##########
@@ -2320,6 +2320,7 @@ semantics.
| o | CHR(integer) | Returns the character having the binary equivalent to *integer* as a CHAR value
| o | COSH(numeric) | Returns the hyperbolic cosine of *numeric*
| m o p | CONCAT(string [, string ]*) | Concatenates two or more strings
+| m | COMPRESS(string) | Compresses a string and returns the result as a binary string.
| p | CONVERT_TIMEZONE(tz1, tz2, datetime) | Converts the timezone of *datetime* from *tz1* to *tz2*
Review comment:
Can we specify the compress algorithm in the doc, e.g. the zlib.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] DonnyZone commented on a change in pull request #1847:
[CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
DonnyZone commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r390266416
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
Review comment:
I have the same concern with @danny0405. The `compress()` implementation involves compression algorithm, encoding/storage format, charset and so on. If we do not rely on a third-party libarary, exhaustive tests and documentation are necessary.
MySQL doc:
> Compresses a string and returns the result as a binary string. This function requires MySQL to have been compiled with a compression library such as zlib. Otherwise, the return value is always NULL.
> The compressed string contents are stored the following way: Empty strings are stored as empty strings. Nonempty strings are stored as a 4-byte length of the uncompressed string (low byte first), followed by the compressed string. If the string ends with space, an extra . character is added to avoid problems with endspace trimming should the result be stored in a CHAR or VARCHAR column. (However, use of nonbinary string data types such as CHAR or VARCHAR to store compressed strings is not recommended anyway because character set conversion may occur. Use a VARBINARY or BLOB binary string column instead.)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] danny0405 closed pull request #1847: [CALCITE-3647] MySQL
COMPRESS function support
Posted by GitBox <gi...@apache.org>.
danny0405 closed pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] ritesh-kapoor commented on a change in pull request
#1847: [CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
ritesh-kapoor commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r391701761
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ByteBuffer dataLength = ByteBuffer.allocate(4);
+ dataLength.order(ByteOrder.LITTLE_ENDIAN);
+ dataLength.putInt(data.length());
+ outputStream.write(dataLength.array());
+ DeflaterOutputStream inflaterStream = new DeflaterOutputStream(outputStream);
+ inflaterStream.write(data.getBytes(Charset.defaultCharset()));
+ inflaterStream.close();
Review comment:
No problem :)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] DonnyZone commented on a change in pull request #1847:
[CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
DonnyZone commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r390266416
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
Review comment:
I have the same concern with @danny0405. The `compress()` implementation involves compression algorithm, encoding and storage format, charset and so on. If we do not rely on a third-party libarary, exhaustive tests and documentation are necessary.
MySQL doc:
> Compresses a string and returns the result as a binary string. This function requires MySQL to have been compiled with a compression library such as zlib. Otherwise, the return value is always NULL.
> The compressed string contents are stored the following way: Empty strings are stored as empty strings. Nonempty strings are stored as a 4-byte length of the uncompressed string (low byte first), followed by the compressed string. If the string ends with space, an extra . character is added to avoid problems with endspace trimming should the result be stored in a CHAR or VARCHAR column. (However, use of nonbinary string data types such as CHAR or VARCHAR to store compressed strings is not recommended anyway because character set conversion may occur. Use a VARBINARY or BLOB binary string column instead.)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [calcite] DonnyZone commented on a change in pull request #1847:
[CALCITE-3647] MySQL COMPRESS function support
Posted by GitBox <gi...@apache.org>.
DonnyZone commented on a change in pull request #1847: [CALCITE-3647] MySQL COMPRESS function support
URL: https://github.com/apache/calcite/pull/1847#discussion_r390266416
##########
File path: core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.util.zip.DeflaterOutputStream;
+
+/**
+ * A collection of functions used in compression and decompression.
+ */
+public class CompressionFunctions {
+
+ private CompressionFunctions() {
+ }
+
+ public static ByteString compress(String data) {
Review comment:
I have the same concern with @danny0405. The `compress()` implementation involves compression algorithm, encoding/storage format, charset and so on. If we do not rely on a third-party libarary, exhaustive tests and documentation are necessary.
```
mysql> SELECT LENGTH(COMPRESS(REPEAT('a',1000)));
-> 21
mysql> SELECT LENGTH(COMPRESS(''));
-> 0
mysql> SELECT LENGTH(COMPRESS('a'));
-> 13
mysql> SELECT LENGTH(COMPRESS(REPEAT('a',16)));
-> 15
```
MySQL doc:
> Compresses a string and returns the result as a binary string. This function requires MySQL to have been compiled with a compression library such as zlib. Otherwise, the return value is always NULL.
> The compressed string contents are stored the following way: Empty strings are stored as empty strings. Nonempty strings are stored as a 4-byte length of the uncompressed string (low byte first), followed by the compressed string. If the string ends with space, an extra . character is added to avoid problems with endspace trimming should the result be stored in a CHAR or VARCHAR column. (However, use of nonbinary string data types such as CHAR or VARCHAR to store compressed strings is not recommended anyway because character set conversion may occur. Use a VARBINARY or BLOB binary string column instead.)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services