michaelmior commented on a change in pull request #1591: [CALCITE-3510] 
Implement sqlquery for Redis adapter
URL: https://github.com/apache/calcite/pull/1591#discussion_r347999633
 
 

 ##########
 File path: 
redis/src/test/java/org/apache/calcite/adapter/redis/RedisServerMini.java
 ##########
 @@ -0,0 +1,122 @@
+/*
+ * 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.adapter.redis;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.JedisPoolConfig;
+import redis.embedded.RedisServer;
+
+/**
+ * RedisDataTypeTest.
+ */
+public class RedisServerMini {
+  private static JedisPool pool;
+  private static final int PORT = 6379;
+  private static final String HOST = "127.0.0.1";
+
+  private static RedisServer redisServer;
+
+  private RedisServerMini() {
+    super();
+  }
+
+  public static void setUp() throws IOException {
+    try {
+      redisServer = new RedisServer(PORT);
+      redisServer.start();
+      JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
+      jedisPoolConfig.setMaxTotal(10);
+      pool = new JedisPool(jedisPoolConfig, HOST, PORT);
+      System.out.println("The redis server is start! host:" + HOST + " port:" 
+ PORT);
+    } catch (Exception e) {
+      throw e;
+    }
+  }
+
+  private static void makeData() {
+    try (Jedis jedis = pool.getResource()) {
+      jedis.del("raw_01");
+      jedis.del("raw_02");
+      jedis.del("raw_03");
+      jedis.del("raw_04");
+      jedis.del("raw5");
+      jedis.del("json_01");
+      jedis.del("json_02");
+      jedis.del("json_03");
+      jedis.del("json_04");
+      jedis.del("json_05");
+      jedis.del("csv_01");
+      jedis.del("csv_02");
+      jedis.del("csv_03");
+      jedis.del("csv_04");
+      jedis.del("csv_05");
+      //set string
+      jedis.set("raw_01", "123");
+      jedis.set("json_01", "{\"DEPTNO\":10,\"NAME\":\"Sales\"}");
+      jedis.set("csv_01", "10:Sales");
+      //set list
+      jedis.lpush("raw_02", "book1");
+      jedis.lpush("raw_02", "book2");
+      jedis.lpush("json_02", "{\"DEPTNO\":10,\"NAME\":\"Sales1\"}");
+      jedis.lpush("json_02", "{\"DEPTNO\":20,\"NAME\":\"Sales2\"}");
+      jedis.lpush("csv_02", "10:Sales");
+      jedis.lpush("csv_02", "20:Sales");
+      //set Set
+      jedis.sadd("raw_03", "user1");
+      jedis.sadd("raw_03", "user2");
+      jedis.sadd("json_03", "{\"DEPTNO\":10,\"NAME\":\"Sales1\"}");
+      jedis.sadd("json_03", "{\"DEPTNO\":20,\"NAME\":\"Sales1\"}");
+      jedis.sadd("csv_03", "10:Sales");
+      jedis.sadd("csv_03", "20:Sales");
+      // set sortSet
+      jedis.zadd("raw_04", 22, "user3");
+      jedis.zadd("raw_04", 24, "user4");
+      jedis.zadd("json_04", 1, "{\"DEPTNO\":10,\"NAME\":\"Sales1\"}");
+      jedis.zadd("json_04", 2, "{\"DEPTNO\":11,\"NAME\":\"Sales2\"}");
+      jedis.zadd("csv_04", 1, "10:Sales");
+      jedis.zadd("csv_04", 2, "20:Sales");
+      //set map
+      Map<String, String> raw5 = new HashMap<>();
+      raw5.put("stuA", "a1");
+      raw5.put("stuB", "b2");
+      jedis.hmset("raw_05", raw5);
+
+      Map<String, String> json5 = new HashMap<>();
+      json5.put("stuA", "{\"DEPTNO\":10,\"NAME\":\"stuA\"}");
+      json5.put("stuB", "{\"DEPTNO\":10,\"NAME\":\"stuB\"}");
+      jedis.hmset("json_05", json5);
+
+      Map<String, String> csv5 = new HashMap<>();
+      csv5.put("stuA", "10:Sales");
+      csv5.put("stuB", "20:Sales");
+      jedis.hmset("csv_05", csv5);
+    }
+    System.out.println("Test data insert redis server is complete!");
 
 Review comment:
   This output should likely be removed.

----------------------------------------------------------------
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