OmniSciDB  06b3bd477c
 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 {
66  }
67  ;
68 
69  ExtensionFunction(final List<ExtArgumentType> args, final ExtArgumentType ret) {
70  this.args = args;
71  this.ret = ret;
72  this.isRowUdf = true;
73  }
74 
75  ExtensionFunction(final List<ExtArgumentType> args,
76  final ExtArgumentType ret,
77  final boolean row_udf) {
78  this.args = args;
79  this.ret = ret;
80  this.isRowUdf = row_udf;
81  }
82 
83  public List<ExtArgumentType> getArgs() {
84  return this.args;
85  }
86 
88  return this.ret;
89  }
90 
91  public boolean isRowUdf() {
92  return this.isRowUdf;
93  }
94 
95  public boolean isTableUdf() {
96  return !this.isRowUdf();
97  }
98 
99  public String toJson(final String name) {
100  MAPDLOGGER.debug("Extensionfunction::toJson: " + name);
101  StringBuilder json_cons = new StringBuilder();
102  json_cons.append("{");
103  json_cons.append("\"name\":").append(dq(name)).append(",");
104  json_cons.append("\"ret\":").append(dq(typeName(ret))).append(",");
105  json_cons.append("\"args\":");
106  json_cons.append("[");
107  List<String> param_list = new ArrayList<String>();
108  for (final ExtArgumentType arg : args) {
109  param_list.add(dq(typeName(arg)));
110  }
111  json_cons.append(ExtensionFunctionSignatureParser.join(param_list, ","));
112  json_cons.append("]");
113  json_cons.append("}");
114  return json_cons.toString();
115  }
116 
117  private static String typeName(final ExtArgumentType type) {
118  switch (type) {
119  case Bool:
120  return "i1";
121  case Int8:
122  return "i8";
123  case Int16:
124  return "i16";
125  case Int32:
126  return "i32";
127  case Int64:
128  return "i64";
129  case Float:
130  return "float";
131  case Double:
132  return "double";
133  case Void:
134  return "void";
135  case PInt8:
136  return "i8*";
137  case PInt16:
138  return "i16*";
139  case PInt32:
140  return "i32*";
141  case PInt64:
142  return "i64*";
143  case PFloat:
144  return "float*";
145  case PDouble:
146  return "double*";
147  case PBool:
148  return "i1*";
149  case ArrayInt8:
150  return "{i8*, i64, i8}*";
151  case ArrayInt16:
152  return "{i16*, i64, i8}*";
153  case ArrayInt32:
154  return "{i32*, i64, i8}*";
155  case ArrayInt64:
156  return "{i64*, i64, i8}*";
157  case ArrayFloat:
158  return "{float*, i64, i8}*";
159  case ArrayDouble:
160  return "{double*, i64, i8}*";
161  case ArrayBool:
162  return "{i1*, i64, i8}*";
163  case ColumnInt8:
164  return "{i8*, i64}";
165  case ColumnInt16:
166  return "{i16*, i64}";
167  case ColumnInt32:
168  return "{i32*, i64}";
169  case ColumnInt64:
170  return "{i64*, i64}";
171  case ColumnFloat:
172  return "{float*, i64}";
173  case ColumnDouble:
174  return "{double*, i64}";
175  case ColumnBool:
176  return "{i1*, i64}";
177  case GeoPoint:
178  return "geo_point";
179  case Cursor:
180  return "cursor";
181  case GeoLineString:
182  return "geo_linestring";
183  case GeoPolygon:
184  return "geo_polygon";
185  case GeoMultiPolygon:
186  return "geo_multi_polygon";
187  }
188  MAPDLOGGER.info("Extensionfunction::typeName: unknown type=`" + type + "`");
189  assert false;
190  return null;
191  }
192 
193  private static String dq(final String str) {
194  return "\"" + str + "\"";
195  }
196 
197  private final List<ExtArgumentType> args;
198  private final ExtArgumentType ret;
199  private final boolean isRowUdf;
200 }
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:135
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)