Ejemplo n.º 1
0
 private Type inferType(List<Record> records, IEvaluatorContext ctx) throws IOException {
   String[] labels = null;
   if (header) {
     labels = extractLabels(records.remove(0));
   }
   Type[] fieldTypes = null;
   for (Record ri : records) {
     List<Type> ftypes = ri.getFieldTypes();
     if (fieldTypes == null) {
       fieldTypes = new Type[ftypes.size()];
       Arrays.fill(fieldTypes, types.voidType());
     } else if (ftypes.size() != fieldTypes.length) {
       // We assume all records in the CSV file to have the same arity.
       throw RuntimeExceptionFactory.illegalArgument(
           // "Inconsistent tuple in CSV expected " + fieldTypes.length + " but was " +
           // ftypes.size(),
           ctx.getCurrentAST(), ctx.getStackTrace());
     }
     for (int i = 0; i < ftypes.size(); i++) {
       fieldTypes[i] = fieldTypes[i].lub(ftypes.get(i));
       if (fieldTypes[i].isTop()) {
         fieldTypes[i] = types.stringType();
       }
     }
   }
   if (labels == null) {
     labels = makeUpLabels(fieldTypes.length);
   }
   return types.setType(types.tupleType(fieldTypes, labels));
 }
Ejemplo n.º 2
0
 public IValue uriDecode(IString str) {
   try {
     return vf.string(URLDecoder.decode(str.getValue(), "UTF-8"));
   } catch (UnsupportedEncodingException e) {
     throw RuntimeExceptionFactory.illegalArgument(
         str, null, null, "UTF-8 is not a valid encoding");
   }
 }