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:
[email protected]


With regards,
Apache Git Services

Reply via email to