Package com.odiago.flumebase.lang

Examples of com.odiago.flumebase.lang.Type


  @Override
  public Type getType(SymbolTable symTab) {
    // Get the types of the lhs and rhs, and then verify that one promotes to the other.
    mLhsType = mLeftExpr.getType(symTab);
    mRhsType = mRightExpr.getType(symTab);
    Type sharedType = null;
    if (mLhsType.promotesTo(mRhsType)) {
      sharedType = mRhsType;
    } else if (mRhsType.promotesTo(mLhsType)) {
      sharedType = mLhsType;
    }
View Full Code Here


          List<Type> outputTypes = new ArrayList<Type>();
          for (TypedField field : mFlumeInputFields) {
            outputTypes.add(field.getType());
          }
 
          Type streamType = new StreamType(outputTypes);
          StreamSymbol streamSym = new StreamSymbol(mFlumeNodeName, StreamSourceType.Node,
              streamType, mFlumeNodeName, true, mOutputFields, formatSpec);
          if (!streamSym.getEventParser().validate(streamSym)) {
            throw new IOException("Could not create valid stream for schema");
          }
View Full Code Here

  }

  @Override
  public Object eval(EventWrapper e) throws IOException {
    Object childObj = mSubExpr.eval(e);
    Type childType = mSubExpr.getResolvedType();
    switch (mOp) {
    case Plus:
      // Keep the object (number) with the same sign; don't need to do anything.
      return childObj;
    case Minus:
      if (childObj == null) {
        return null;
      }

      switch (childType.getPrimitiveTypeName()) {
      case INT:
        return -((Integer) childObj).intValue();
      case BIGINT:
        return -((Long) childObj).longValue();
      case FLOAT:
View Full Code Here

    List<Schema.Field> avroFields = new ArrayList<Schema.Field>();
    Schema record = Schema.createRecord(recordName, null, null, false);
    for (TypedField field : requiredFields) {
      LOG.debug("Considering field: " + field);
      String fieldName = field.getAvroName();
      Type t = field.getType();
      Schema fieldSchema = t.getAvroSchema();
      Schema.Field avroField = new Schema.Field(fieldName, fieldSchema, null, null);
      avroFields.add(avroField);
    }
    record.setFields(avroFields);
    return record;
View Full Code Here

    assert mArgExprs.size() == abstractArgTypes.size();

    // Check that each expression type can promote to the argument type.
    for (int i = 0; i < mArgExprs.size(); i++) {
      Type exprType = mArgExprs.get(i).getType(symTab);
      mExprTypes.add(exprType);
      if (!exprType.promotesTo(abstractArgTypes.get(i))) {
        throw new TypeCheckException("Invalid argument to function " + mFunctionName
            + ": argument " + i + " has type " + exprType + "; requires type "
            + abstractArgTypes.get(i));
      }
    }

    mArgTypes = new Type[mArgExprs.size()];

    // Now identify all the UniversalType instances in here, and the
    // actual constraints on each of these.
    Map<UniversalType, List<Type>> unifications = new HashMap<UniversalType, List<Type>>();
    for (int i = 0; i < abstractArgTypes.size(); i++) {
      Type abstractType = abstractArgTypes.get(i);
      Type actualType = mExprTypes.get(i);
      UniversalConstraintExtractor constraintExtractor = new UniversalConstraintExtractor();
      if (constraintExtractor.extractConstraint(abstractType, actualType)) {
        // Found a UniversalType. Make sure it's mapped to a list of actual constraints.
        UniversalType univType = constraintExtractor.getUniversalType();
        List<Type> actualConstraints = unifications.get(univType);
        if (null == actualConstraints) {
          actualConstraints = new ArrayList<Type>();
          unifications.put(univType, actualConstraints);
        }

        // Add the actual constraint of the expression being applied as this argument.
        actualConstraints.add(constraintExtractor.getConstraintType());
      }
    }

    // Perform unifications on all the UniversalType expressions.
    Map<Type, Type> unificationOut = new HashMap<Type, Type>();
    for (Map.Entry<UniversalType, List<Type>> unification : unifications.entrySet()) {
      UniversalType univType = unification.getKey();
      List<Type> actualConstraints = unification.getValue();
      Type out = univType.getRuntimeType(actualConstraints);
      unificationOut.put(univType, out);
    }
   
    // Finally, generate a list of concrete argument types for coercion purposes.
    for (int i = 0; i < abstractArgTypes.size(); i++ ) {
      Type abstractType = abstractArgTypes.get(i);
      mArgTypes[i] = abstractType.replaceUniversal(unificationOut);
      assert mArgTypes[i] != null;
    }

    // Also set mReturnType; if this referenced a UniversalType, use the resolved
    // version. Otherwise, use the version from the function directly.
    Type fnRetType = mFnSymbol.getReturnType();
    try {
      mReturnType = fnRetType.replaceUniversal(unificationOut);
    } catch (TypeCheckException tce) {
      // We can only resolve against our arguments, not our caller's type.
      if (fnRetType instanceof ListType) {
        // If the unresolved typevar is an argument to a list type, we can
        // return this -- it's going to be an empty list, so we can return
View Full Code Here

      }
      List<TypedField> columnFields = streamSym.getFields();

      for (int i = 0; i < columnFields.size(); i++) {
        TypedField col = columnFields.get(i);
        Type colType = col.getType();
       
        // Get the schema field that matches this column name.
        Schema.Field schemaField = null;
        for (Schema.Field testSchemaField : schemaFields) {
          if (testSchemaField.name().equals(col.getUserAlias())) {
            schemaField = testSchemaField;
            break;
          }
        }
       
        if (null == schemaField) {
          // Can't find a field in the schema to match the current column.
          LOG.error("The Avro schema does not contain a field with the same name "
              + "as column '" + col.getUserAlias() + "'.");
          return false;
        }
       
        // Are the schemas compatible?
        if (!schemaField.schema().equals(colType.getAvroSchema())) {
          boolean warned = false;

          if (colType.isNullable() && colType.isPrimitive()) {
            // A common error is that the rtsql type is nullable and the schema
            // type isn't. Give a specific suggestion in this case.
            Type nonNullVersion = Type.getPrimitive(colType.getPrimitiveTypeName());
            if (schemaField.schema().equals(nonNullVersion.getAvroSchema())) {
              LOG.error("Column " + col.getUserAlias() + " has type " + colType
                  + ", but requires type " + nonNullVersion + " to match the Avro schema.");
              warned = true;
            }
          }
View Full Code Here

        }
      } else {
        // Get the type within the expression, and add the appropriate labels.
        // These have been already assigned by a visitor pass.

        Type t = e.getType(fieldSymbols);
        TypedField projectionField = new TypedField(
          aliasExpr.getUserAlias(), t,
          aliasExpr.getAvroLabel(), aliasExpr.getDisplayLabel());

        // Make sure our dependencies are pulled out of the source layer.
View Full Code Here

      List<TypedField> aggOutputFields = new ArrayList<TypedField>();
      aggOutputFields.addAll(groupByPropagateFields);
      // As well as the names of everything we calculate in this layer.
      for (AliasedExpr aliasExpr : mAggregateExprs) {
        Expr e = aliasExpr.getExpr();
        Type t = e.getType(fieldSymbols);
        TypedField aggregateField = new TypedField(
          aliasExpr.getUserAlias(), t,
          aliasExpr.getAvroLabel(), aliasExpr.getDisplayLabel());
        aggOutputFields.add(aggregateField);
      }
View Full Code Here

   * Load instances of the built-in functions into the BuiltInSymbolTable.
   */
  private static void loadBuiltinFunction(Class<? extends Function> cls) {
    try {
      Function fn = (Function) cls.newInstance();
      Type retType = fn.getReturnType();
      List<Type> argTypes = fn.getArgumentTypes();
      List<Type> varArgTypes = fn.getVarArgTypes();
      String fnName = cls.getSimpleName();
      LOG.debug("Loaded built-in function: " + fnName);
      Symbol fnSymbol = new FnSymbol(fnName, fn, retType, argTypes, varArgTypes);
View Full Code Here

TOP

Related Classes of com.odiago.flumebase.lang.Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.