Package sizzle.types

Examples of sizzle.types.SizzleBytes


  }

  /** {@inheritDoc} */
  @Override
  public SizzleType visit(final BytesLiteral n, final SymbolTable argu) {
    return new SizzleBytes();
  }
View Full Code Here


    this.staticinitializer = new StaticInitializationCodeGeneratingVisitor(this);

    this.tables = new HashMap<String, TableDescription>();
    this.tables.put("stdout", new TableDescription("stdout", new SizzleString()));
    this.tables.put("stderr", new TableDescription("stderr", new SizzleString()));
    this.tables.put("output", new TableDescription("output", new SizzleBytes()));

    this.name = name;
    this.stg = stg;
  }
View Full Code Here

    st.setAttribute("name", this.name);
    if (argu.get("input").equals(new SizzleString())) {
      st.setAttribute("inputFormatClass", "org.apache.hadoop.mapreduce.lib.input.TextInputFormat");
      st.setAttribute("keyClass", "org.apache.hadoop.io.LongWritable");
      st.setAttribute("valueClass", "org.apache.hadoop.io.Text");
    } else if (argu.get("input").equals(new SizzleBytes())) {
      throw new RuntimeException("unimplemented");
    }

    st.setAttribute("staticDeclarations", this.staticdeclarator.visit(n, argu));
    st.setAttribute("staticStatements", this.staticinitializer.visit(n, argu));
View Full Code Here

  @Test
  public void testTypeCheckingVisitorP4Stat() throws IOException, ParseException {
    final String source = "proto \"p4stat.proto\"\nsubmitsthroughweek: table sum[minute: int] of count: int;\nlog: P4ChangelistStats = input;\nt: time = log.time; # microseconds\nminute: int = minuteof(t)+60*(hourof(t)+24*(dayofweek(t)-1));\nemit submitsthroughweek[minute] <- 1;\n";

    final SymbolTable st = new SymbolTable(new SizzleBytes());

    SizzleParser.ReInit(new StringReader(source));
    TestTypeCheckingVisitor.typeChecker.visit(SizzleParser.Start(), st);

    Assert.assertEquals("submitsthroughweek is not an unweighted table of ints indexed by int",
View Full Code Here

  @Test
  public void testTypeCheckingVisitorMaxPagerank() throws IOException, ParseException {
    final String source = "proto \"sizzle_document.proto\"\nmax_pagerank_url:\n     table maximum(1) [domain: string] of url: string\n           weight pagerank: float;\ndoc: Document = input;\nemit max_pagerank_url[domain(doc.url)] <- doc.url\n     weight doc.pagerank;\n";

    final SymbolTable st = new SymbolTable(new SizzleBytes());

    SizzleParser.ReInit(new StringReader(source));
    TestTypeCheckingVisitor.typeChecker.visit(SizzleParser.Start(), st);

    Assert.assertEquals("max_pagerank_url is not table of strings indexed by string weighted by int",
View Full Code Here

  @Test
  public void testTypeCheckingVisitorQueryLog() throws IOException, ParseException {
    final String source = "proto \"querylog.proto\"\n\nqueries_per_degree: table sum[lat: int][lon: int] of int;\n\nlog_record: QueryLogProto = input;\nloc: Location = locationinfo(log_record.ip);\nemit queries_per_degree[int(loc.lat)][int(loc.lon)] <- 1;\n";

    final SymbolTable st = new SymbolTable(new SizzleBytes());

    SizzleParser.ReInit(new StringReader(source));
    TestTypeCheckingVisitor.typeChecker.visit(SizzleParser.Start(), st);

    Assert.assertEquals("queries_per_degree is not an unweighted table of ints indexed by ints",
View Full Code Here

  @Test
  public void testTypeCheckingRobustQueryLogFixed() throws IOException, ParseException {
    final String source = "proto \"querylog.proto\"\n  static MINUTE: float = 0.0; static RESOLUTION: int = 5;  # minutes; must be divisor of 60\n  log_record: QueryLogProto = input;\n  queries_per_degree: table sum[t: time][lat: int][lon: int] of int;\n  loc: Location = locationinfo(log_record.ip);\n  if (def(loc)) {\n      t: time = log_record.time_usec;\n      m: int = minuteof(t); # within the hour\n      m = m - m % RESOLUTION;\n      t = trunctohour(t) + time(m * int(MINUTE));\n      emit queries_per_degree[t][int(loc.lat)][int(loc.lon)] <- 1;\n  }";

    final SymbolTable st = new SymbolTable(new SizzleBytes());

    SizzleParser.ReInit(new StringReader(source));
    TestTypeCheckingVisitor.typeChecker.visit(SizzleParser.Start(), st);

    Assert.assertEquals("queries_per_degree is not an unweighted table of ints indexed by various",
View Full Code Here

    this.protomap.put(int.class, new SizzleInt());
    this.protomap.put(long.class, new SizzleInt());
    this.protomap.put(float.class, new SizzleFloat());
    this.protomap.put(double.class, new SizzleFloat());
    this.protomap.put(boolean.class, new SizzleBool());
    this.protomap.put(byte[].class, new SizzleBytes());
    this.protomap.put(String.class, new SizzleString());

    // this maps scalar Sizzle scalar types names to their classes
    // TODO: do this via reflection
    this.idmap = new HashMap<String, SizzleType>();
    this.idmap.put("any", new SizzleAny());
    this.idmap.put("none", null);
    this.idmap.put("bool", new SizzleBool());
    this.idmap.put("int", new SizzleInt());
    this.idmap.put("float", new SizzleFloat());
    this.idmap.put("time", new SizzleTime());
    this.idmap.put("fingerprint", new SizzleFingerprint());
    this.idmap.put("string", new SizzleString());
    this.idmap.put("bytes", new SizzleBytes());

    // does the same for arrays
    // for (final String key : new HashSet<String>(this.idmap.keySet())) {
    // final SizzleType value = this.idmap.get(key);
    // if (value instanceof SizzleScalar)
    // this.idmap.put("array of " + key, new SizzleArray((SizzleScalar)
    // value));
    // }

    // variables with a global scope
    this.globals = new HashMap<String, SizzleType>();
    // set the type of the input
    this.globals.put("input", input);
    this.globals.put("true", new SizzleBool());
    this.globals.put("false", new SizzleBool());
    this.globals.put("PI", new SizzleFloat());
    this.globals.put("Inf", new SizzleFloat());
    this.globals.put("inf", new SizzleFloat());
    this.globals.put("NaN", new SizzleFloat());
    this.globals.put("nan", new SizzleFloat());

    // variables with a local scope
    this.locals = new HashMap<String, SizzleType>();
    this.aggregators = new HashMap<String, Class<?>>();
    this.functions = new FunctionTrie();

    // these generic functions require more finagling than can currently be
    // (easily) done with a static method, so they are handled with macros

    this.setFunction("def", new SizzleFunction(new SizzleBool(), new SizzleType[] { new SizzleAny() }, "${0} != null"));
    this.setFunction("len", new SizzleFunction(new SizzleInt(), new SizzleType[] { new SizzleArray(new SizzleScalar()) }, "${0}.length"));
    this.setFunction("len", new SizzleFunction(new SizzleInt(), new SizzleType[] { new SizzleString() }, "${0}.length()"));
    this.setFunction("len", new SizzleFunction(new SizzleInt(), new SizzleType[] { new SizzleBytes() }, "${0}.length"));
    this.setFunction("len", new SizzleFunction(new SizzleInt(), new SizzleType[] { new SizzleMap(new SizzleScalar(), new SizzleScalar()) },
        "${0}.keySet().size()"));
    this.setFunction("haskey", new SizzleFunction(new SizzleBool(), new SizzleType[] { new SizzleMap(new SizzleScalar(), new SizzleScalar()),
        new SizzleScalar() }, "${0}.containsKey(${1})"));
    this.setFunction("keys", new SizzleFunction(new SizzleArray(new SizzleScalar()), new SizzleType[] { new SizzleMap(new SizzleScalar(),
        new SizzleScalar()) }, "${0}.keySet().toArray()"));
    this.setFunction("lookup", new SizzleFunction(new SizzleScalar(), new SizzleType[] { new SizzleMap(new SizzleScalar(), new SizzleScalar()),
        new SizzleScalar(), new SizzleScalar() }, "(${0}.containsKey(${1}) ? ${0}.get(${1}) : ${2})"));

    this.setFunction("regex", new SizzleFunction(new SizzleString(), new SizzleType[] { new SizzleName(new SizzleScalar()), new SizzleInt() },
        "sizzle.functions.SizzleSpecialIntrinsics.regex(\"${0}\", ${1})"));
    this.setFunction("regex", new SizzleFunction(new SizzleString(), new SizzleType[] { new SizzleName(new SizzleScalar()) },
        "sizzle.functions.SizzleSpecialIntrinsics.regex(\"${0}\")"));
    // these fingerprints are identity functions
    this.setFunction("fingerprintof", new SizzleFunction(new SizzleFingerprint(), new SizzleScalar[] { new SizzleInt() }));
    this.setFunction("fingerprintof", new SizzleFunction(new SizzleFingerprint(), new SizzleScalar[] { new SizzleTime() }));

    /* expose all the casting constructors to Sawzall */

    // string to bool
    this.setFunction("bool",
        new SizzleFunction("sizzle.functions.SizzleCasts.stringToBoolean", new SizzleBool(), new SizzleScalar[] { new SizzleString() }));

    // bool to int
    this.setFunction("int", new SizzleFunction("sizzle.functions.SizzleCasts.booleanToLong", new SizzleInt(), new SizzleScalar[] { new SizzleBool() }));
    // float to int
    this.setFunction("int", new SizzleFunction(new SizzleInt(), new SizzleScalar[] { new SizzleFloat() }, "(long)${0}"));
    // time to int
    this.setFunction("int", new SizzleFunction(new SizzleInt(), new SizzleScalar[] { new SizzleTime() }));
    // fingerprint to int
    this.setFunction("int", new SizzleFunction(new SizzleInt(), new SizzleScalar[] { new SizzleFingerprint() }));
    // string to int
    this.setFunction("int", new SizzleFunction("java.lang.Long.decode", new SizzleInt(), new SizzleScalar[] { new SizzleString() }));
    // string to int with param base
    this.setFunction("int", new SizzleFunction(new SizzleInt(), new SizzleScalar[] { new SizzleString(), new SizzleInt() },
        "java.lang.Long.parseLong(${0}, (int)${1})"));
    // bytes to int with param encoding format
    this.setFunction("int", new SizzleFunction("sizzle.functions.SizzleCasts.bytesToLong", new SizzleInt(), new SizzleScalar[] { new SizzleBytes(),
        new SizzleString() }));

    // int to float
    this.setFunction("float", new SizzleFunction(new SizzleFloat(), new SizzleScalar[] { new SizzleInt() }, "(double)${0}"));
    // string to float
    this.setFunction("float", new SizzleFunction("java.lang.Double.parseDouble", new SizzleFloat(), new SizzleScalar[] { new SizzleString() }));

    // int to time
    this.setFunction("time", new SizzleFunction(new SizzleTime(), new SizzleScalar[] { new SizzleInt() }));
    // string to time
    this.setFunction("time", new SizzleFunction("sizzle.functions.SizzleCasts.stringToTime", new SizzleTime(), new SizzleScalar[] { new SizzleString() }));
    // string to time
    this.setFunction("time", new SizzleFunction("sizzle.functions.SizzleCasts.stringToTime", new SizzleTime(), new SizzleScalar[] { new SizzleString(),
        new SizzleString() }));

    // int to fingerprint
    this.setFunction("fingerprint", new SizzleFunction(new SizzleFingerprint(), new SizzleScalar[] { new SizzleInt() }));
    // string to fingerprint
    this.setFunction("fingerprint", new SizzleFunction("java.lang.Long.parseLong", new SizzleInt(), new SizzleScalar[] { new SizzleString() }));
    // string to fingerprint with param base
    this.setFunction("fingerprint", new SizzleFunction("java.lang.Long.parseLong", new SizzleInt(), new SizzleScalar[] { new SizzleString(),
        new SizzleInt() }));
    // bytes to fingerprint
    this.setFunction("fingerprint", new SizzleFunction("sizzle.functions.SizzleCasts.bytesToFingerprint", new SizzleFingerprint(),
        new SizzleScalar[] { new SizzleBytes() }));

    // bool to string
    this.setFunction("string", new SizzleFunction("java.lang.Boolean.toString", new SizzleString(), new SizzleScalar[] { new SizzleBool() }));
    // int to string
    this.setFunction("string", new SizzleFunction("java.lang.Long.toString", new SizzleString(), new SizzleScalar[] { new SizzleInt() }));
    // int to string with parameter base
    this.setFunction("string", new SizzleFunction("sizzle.functions.SizzleCasts.longToString", new SizzleString(), new SizzleScalar[] { new SizzleInt(),
        new SizzleInt() }));
    // float to string
    this.setFunction("string", new SizzleFunction("java.lang.Double.toString", new SizzleString(), new SizzleScalar[] { new SizzleFloat() }));
    // time to string
    this.setFunction("string", new SizzleFunction("sizzle.functions.SizzleCasts.timeToString", new SizzleString(), new SizzleScalar[] { new SizzleTime() }));
    // fingerprint to string
    this.setFunction("string", new SizzleFunction("java.lang.Long.toHexString", new SizzleString(), new SizzleScalar[] { new SizzleFingerprint() }));
    // bytes to string
    this.setFunction("string", new SizzleFunction("new java.lang.String", new SizzleString(), new SizzleScalar[] { new SizzleBytes() }));
    // bytes to string
    this.setFunction("string", new SizzleFunction("new java.lang.String", new SizzleString(), new SizzleScalar[] { new SizzleBytes(), new SizzleString() }));

    // int to bytes with param encoding format
    this.setFunction("bytes", new SizzleFunction("sizzle.functions.SizzleCasts.longToBytes", new SizzleInt(), new SizzleScalar[] { new SizzleInt(),
        new SizzleString() }));
    // fingerprint to bytes
    this.setFunction("bytes", new SizzleFunction("sizzle.functions.SizzleCasts.fingerprintToBytes", new SizzleBytes(),
        new SizzleScalar[] { new SizzleFingerprint() }));
    // string to bytes
    this.setFunction("bytes",
        new SizzleFunction("sizzle.functions.SizzleCasts.stringToBytes", new SizzleBytes(), new SizzleScalar[] { new SizzleString() }));

    /* expose the java.lang.Math class to Sawzall */

    this.setFunction("highbit", new SizzleFunction("java.lang.Long.highestOneBit", new SizzleInt(), new SizzleScalar[] { new SizzleInt() }));

    // abs just needs to be overloaded
    this.setFunction("abs", new SizzleFunction("java.lang.Math.abs", new SizzleFloat(), new SizzleScalar[] { new SizzleInt() }));
    this.setFunction("abs", new SizzleFunction("java.lang.Math.abs", new SizzleFloat(), new SizzleScalar[] { new SizzleFloat() }));

    // abs is also named fabs in Sawzall
    this.setFunction("fabs", new SizzleFunction("java.lang.Math.abs", new SizzleFloat(), new SizzleScalar[] { new SizzleFloat() }));

    // log is named ln in Sawzall
    this.setFunction("ln", new SizzleFunction("java.lang.Math.log", new SizzleFloat(), new SizzleScalar[] { new SizzleFloat() }));

    // expose the rest of the unary functions
    for (final String s : Arrays.asList("log10", "exp", "sqrt", "sin", "cos", "tan", "asin", "acos", "atan", "cosh", "sinh", "tanh", "ceil", "floor",
        "round"))
      this.setFunction(s, new SizzleFunction("java.lang.Math." + s, new SizzleFloat(), new SizzleScalar[] { new SizzleFloat() }));

    // expose the binary functions
    for (final String s : Arrays.asList("pow", "atan2"))
      this.setFunction(s, new SizzleFunction("java.lang.Math." + s, new SizzleFloat(), new SizzleScalar[] { new SizzleFloat(), new SizzleFloat() }));

    for (final String s : Arrays.asList("max", "min"))
      for (final SizzleScalar t : Arrays.asList(new SizzleInt(), new SizzleFloat()))
        this.setFunction(s, new SizzleFunction("java.lang.Math." + s, new SizzleFloat(), new SizzleScalar[] { t, t }));

    this.setFunction("max", new SizzleFunction(new SizzleFloat(), new SizzleScalar[] { new SizzleTime(), new SizzleTime() }, "(${0} > ${1} ? ${0} : ${1})"));
    this.setFunction("min", new SizzleFunction(new SizzleFloat(), new SizzleScalar[] { new SizzleTime(), new SizzleTime() }, "(${0} < ${1} ? ${0} : ${1})"));

    this.setFunction("max", new SizzleFunction(new SizzleFloat(), new SizzleScalar[] { new SizzleString(), new SizzleString() },
        "(${0}.compareTo(${1}) > 0 ? ${0} : ${1})"));
    this.setFunction("min", new SizzleFunction(new SizzleFloat(), new SizzleScalar[] { new SizzleString(), new SizzleString() },
        "(${0}.compareTo(${1}) < 0 ? ${0} : ${1})"));

    // expose whatever is left, assuming we are not aiming for strict
    // compatibility
    if (!this.strictCompatibility) {
      // random takes no argument

      // these three have capitals in the name
      this.setFunction("ieeeremainder", new SizzleFunction("java.lang.Math.IEEEremainder", new SizzleFloat(), new SizzleScalar[] { new SizzleFloat(),
          new SizzleFloat() }));
      this.setFunction("todegrees", new SizzleFunction("java.lang.Math.toDegrees", new SizzleFloat(), new SizzleScalar[] { new SizzleFloat() }));
      this.setFunction("toradians", new SizzleFunction("java.lang.Math.toRadians", new SizzleFloat(), new SizzleScalar[] { new SizzleFloat() }));

      // the unaries
      for (final String s : Arrays.asList("cbrt", "expm1", "log1p", "rint", "signum", "ulp"))
        this.setFunction(s, new SizzleFunction("java.lang.Math." + s, new SizzleFloat(), new SizzleScalar[] { new SizzleFloat() }));

      // and binaries
      this.setFunction("hypot",
          new SizzleFunction("java.lang.Math.hypot", new SizzleFloat(), new SizzleScalar[] { new SizzleFloat(), new SizzleFloat() }));
    }

    // add in the default tables
    // FIXME: support format strings and files
    this.set("stdout", new SizzleTable(new SizzleString()));
    this.set("stderr", new SizzleTable(new SizzleString()));
    this.set("output", new SizzleTable(new SizzleBytes()));

    this.importLibs(libs);
  }
View Full Code Here

TOP

Related Classes of sizzle.types.SizzleBytes

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.