OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExtensionFunction.java
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
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 package com.mapd.parser.server;
17 
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 
28 public class ExtensionFunction {
29  final static Logger MAPDLOGGER = LoggerFactory.getLogger(ExtensionFunction.class);
30 
31  public enum ExtArgumentType {
56  }
57  ;
58 
59  ExtensionFunction(final List<ExtArgumentType> args, final ExtArgumentType ret) {
60  this.args = args;
61  this.ret = ret;
62  this.isRowUdf = true;
63  }
64 
65  ExtensionFunction(final List<ExtArgumentType> args,
66  final ExtArgumentType ret,
67  final boolean row_udf) {
68  this.args = args;
69  this.ret = ret;
70  this.isRowUdf = row_udf;
71  }
72 
73  public List<ExtArgumentType> getArgs() {
74  return this.args;
75  }
76 
78  return this.ret;
79  }
80 
81  public boolean isRowUdf() {
82  return this.isRowUdf;
83  }
84 
85  public boolean isTableUdf() {
86  return !this.isRowUdf();
87  }
88 
89  public String toJson(final String name) {
90  MAPDLOGGER.debug("Extensionfunction::toJson: " + name);
91  StringBuilder json_cons = new StringBuilder();
92  json_cons.append("{");
93  json_cons.append("\"name\":").append(dq(name)).append(",");
94  json_cons.append("\"ret\":").append(dq(typeName(ret))).append(",");
95  json_cons.append("\"args\":");
96  json_cons.append("[");
97  List<String> param_list = new ArrayList<String>();
98  for (final ExtArgumentType arg : args) {
99  param_list.add(dq(typeName(arg)));
100  }
101  json_cons.append(ExtensionFunctionSignatureParser.join(param_list, ","));
102  json_cons.append("]");
103  json_cons.append("}");
104  return json_cons.toString();
105  }
106 
107  private static String typeName(final ExtArgumentType type) {
108  switch (type) {
109  case Bool:
110  return "i1";
111  case Int8:
112  return "i8";
113  case Int16:
114  return "i16";
115  case Int32:
116  return "i32";
117  case Int64:
118  return "i64";
119  case Float:
120  return "float";
121  case Double:
122  return "double";
123  case Void:
124  return "void";
125  case PInt8:
126  return "i8*";
127  case PInt16:
128  return "i16*";
129  case PInt32:
130  return "i32*";
131  case PInt64:
132  return "i64*";
133  case PFloat:
134  return "float*";
135  case PDouble:
136  return "double*";
137  case ArrayInt8:
138  return "array_i8";
139  case ArrayInt16:
140  return "array_i16";
141  case ArrayInt32:
142  return "array_i32";
143  case ArrayInt64:
144  return "array_i64";
145  case ArrayFloat:
146  return "array_float";
147  case ArrayDouble:
148  return "array_double";
149  case GeoPoint:
150  return "geo_point";
151  case Cursor:
152  return "cursor";
153  case GeoLineString:
154  return "geo_linestring";
155  case GeoPolygon:
156  return "geo_polygon";
157  }
158  MAPDLOGGER.info("Extensionfunction::typeName: unknown type=`" + type + "`");
159  assert false;
160  return null;
161  }
162 
163  private static String dq(final String str) {
164  return "\"" + str + "\"";
165  }
166 
167  private final List<ExtArgumentType> args;
168  private final ExtArgumentType ret;
169  private final boolean isRowUdf;
170 }
size_t append(FILE *f, const size_t size, int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
Definition: File.cpp:136
int64_t const int32_t sz assert(dest)
ExtensionFunction(final List< ExtArgumentType > args, final ExtArgumentType ret)
static String typeName(final ExtArgumentType type)
static String dq(final String str)
ExtensionFunction(final List< ExtArgumentType > args, final ExtArgumentType ret, final boolean row_udf)