Package java.io

Examples of java.io.DataOutput


    String funcName = descFunc.getName();

    // write the results in the file
    try {
      FileSystem fs = descFunc.getResFile().getFileSystem(conf);
      DataOutput outStream = (DataOutput)fs.create(descFunc.getResFile());

      // get the function documentation
      description desc = null;
      Class<?> funcClass = null;
      FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(funcName);
      if (functionInfo != null) {
        funcClass = functionInfo.getFunctionClass();
      }
      if (funcClass != null) {
        desc = funcClass.getAnnotation(description.class);
      }
      if (desc != null) {
        outStream.writeBytes(desc.value().replace("_FUNC_", funcName));
        if(descFunc.isExtended()) {
          Set<String> synonyms = FunctionRegistry.getFunctionSynonyms(funcName);
          if (synonyms.size() > 0) {
            outStream.writeBytes("\nSynonyms: " + join(synonyms, ", "));
          }
          if (desc.extended().length() > 0) {
            outStream.writeBytes("\n"+desc.extended().replace("_FUNC_", funcName));
          }
        }
      } else {
        if (funcClass != null) {
          outStream.writeBytes("There is no documentation for function '" + funcName + "'");
        } else {
          outStream.writeBytes("Function '" + funcName + "' does not exist.");
        }
      }

      outStream.write(terminator);

      ((FSDataOutputStream)outStream).close();
    } catch (FileNotFoundException e) {
      LOG.warn("describe function: " + stringifyException(e));
      return 1;
View Full Code Here


    }

    // write the results in the file
    try {
      FileSystem fs = showTblStatus.getResFile().getFileSystem(conf);
      DataOutput outStream = (DataOutput) fs.create(showTblStatus.getResFile());

      Iterator<Table> iterTables = tbls.iterator();
      while (iterTables.hasNext()) {
        // create a row per table name
        Table tbl = iterTables.next();
        String tableName = tbl.getName();
        String tblLoc = null;
        String inputFormattCls = null;
        String outputFormattCls = null;
        if (part != null) {
          if(par !=null) {
            tblLoc = par.getDataLocation().toString();
            inputFormattCls = par.getTPartition().getSd().getInputFormat();
            outputFormattCls = par.getTPartition().getSd().getOutputFormat();
          }
        } else {
          tblLoc = tbl.getDataLocation().toString();
          inputFormattCls = tbl.getInputFormatClass().getName();
          outputFormattCls = tbl.getOutputFormatClass().getName();
        }
       
        String owner = tbl.getOwner();
        List<FieldSchema> cols = tbl.getCols();
        String ddlCols = MetaStoreUtils.getDDLFromFieldSchema("columns", cols);
        boolean isPartitioned = tbl.isPartitioned();
        String partitionCols = "";
        if (isPartitioned)
          partitionCols = MetaStoreUtils.getDDLFromFieldSchema(
              "partition_columns", tbl.getPartCols());

        outStream.writeBytes("tableName:" + tableName);
        outStream.write(terminator);
        outStream.writeBytes("owner:" + owner);
        outStream.write(terminator);
        outStream.writeBytes("location:" + tblLoc);
        outStream.write(terminator);
        outStream.writeBytes("inputformat:" + inputFormattCls);
        outStream.write(terminator);
        outStream.writeBytes("outputformat:" + outputFormattCls);
        outStream.write(terminator);
        outStream.writeBytes("columns:" + ddlCols);
        outStream.write(terminator);
        outStream.writeBytes("partitioned:" + isPartitioned);
        outStream.write(terminator);
        outStream.writeBytes("partitionColumns:" + partitionCols);
        outStream.write(terminator);
        // output file system information
        Path tablLoc = tbl.getPath();
        List<Path> locations = new ArrayList<Path>();
        if (isPartitioned) {
          if (par == null) {
            for (Partition curPart : db.getPartitions(tbl)) {
              locations.add(new Path(curPart.getTPartition().getSd().getLocation()));
            }
          } else {
            locations.add(new Path(par.getTPartition().getSd().getLocation()));
          }
        } else {
          locations.add(tablLoc);
        }
        writeFileSystemStats(outStream, locations, tablLoc, false, 0);

        outStream.write(terminator);
      }
      ((FSDataOutputStream) outStream).close();
    } catch (FileNotFoundException e) {
      LOG.info("show table status: " + stringifyException(e));
      return 1;
View Full Code Here

    Table tbl = db.getTable(MetaStoreUtils.DEFAULT_DATABASE_NAME, tableName, false);
    Partition part = null;
    try {
      if (tbl == null) {
        FileSystem fs = descTbl.getResFile().getFileSystem(conf);
        DataOutput outStream = (DataOutput) fs.open(descTbl.getResFile());
        String errMsg = "Table " + tableName + " does not exist";
        outStream.write(errMsg.getBytes("UTF-8"));
        ((FSDataOutputStream) outStream).close();
        return 0;
      }
      if (descTbl.getPartSpec() != null) {
        part = db.getPartition(tbl, descTbl.getPartSpec(), false);
        if (part == null) {
          FileSystem fs = descTbl.getResFile().getFileSystem(conf);
          DataOutput outStream = (DataOutput) fs.open(descTbl.getResFile());
          String errMsg = "Partition " + descTbl.getPartSpec() + " for table "
              + tableName + " does not exist";
          outStream.write(errMsg.getBytes("UTF-8"));
          ((FSDataOutputStream) outStream).close();
          return 0;
        }
        tbl = part.getTable();
      }
    } catch (FileNotFoundException e) {
      LOG.info("describe table: " + stringifyException(e));
      return 1;
    } catch (IOException e) {
      LOG.info("describe table: " + stringifyException(e));
      return 1;
    }

    try {

      LOG.info("DDLTask: got data for " + tbl.getName());

      List<FieldSchema> cols = null;
      if (colPath.equals(tableName)) {
        cols = tbl.getCols();
        if (part != null) {
          cols = part.getTPartition().getSd().getCols();
        }
      } else {
        cols = Hive.getFieldsFromDeserializer(colPath, tbl.getDeserializer());
      }
      FileSystem fs = descTbl.getResFile().getFileSystem(conf);
      DataOutput outStream = (DataOutput)fs.create(descTbl.getResFile());
      Iterator<FieldSchema> iterCols = cols.iterator();
      while (iterCols.hasNext()) {
        // create a row per column
        FieldSchema col = iterCols.next();
        outStream.writeBytes(col.getName());
        outStream.write(separator);
        outStream.writeBytes(col.getType());
        outStream.write(separator);
        outStream.writeBytes(col.getComment() == null ? "" : col.getComment());
        outStream.write(terminator);
      }

      if (tableName.equals(colPath)) {
        // also return the partitioning columns
        List<FieldSchema> partCols = tbl.getPartCols();
        Iterator<FieldSchema> iterPartCols = partCols.iterator();
        while (iterPartCols.hasNext()) {
          FieldSchema col = iterPartCols.next();
          outStream.writeBytes(col.getName());
          outStream.write(separator);
          outStream.writeBytes(col.getType());
          outStream.write(separator);
          outStream.writeBytes(col.getComment() == null ? "" : col.getComment());
          outStream.write(terminator);
        }

        // if extended desc table then show the complete details of the table
        if (descTbl.isExt()) {
          // add empty line
          outStream.write(terminator);
          if (part != null) {
            // show partition information
            outStream.writeBytes("Detailed Partition Information");
            outStream.write(separator);
            outStream.writeBytes(part.getTPartition().toString());
            outStream.write(separator);
            // comment column is empty
            outStream.write(terminator);
          } else {
            // show table information
            outStream.writeBytes("Detailed Table Information");
            outStream.write(separator);
            outStream.writeBytes(tbl.getTTable().toString());
            outStream.write(separator);
            // comment column is empty
            outStream.write(terminator);
          }
        }
      }

      LOG.info("DDLTask: written data for " + tbl.getName());
View Full Code Here

    assertEquals(2 * numElements, messageBundle.getSize());
    assertEquals(2 * numElements, messageBundle.getNumElements());

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
    DataOutput output = new DataOutputStream(outputStream);
    messageBundle.write(output);

    ByteArrayInputStream inStream = new ByteArrayInputStream(
        outputStream.toByteArray());
    DataInput in = new DataInputStream(inStream);
View Full Code Here

     * @param array int[]
     * @param append boolean
     */
    public void writeIntArray(int[] array, boolean append) {
        try {
            DataOutput dos;
            if (bigEndian) {
                dos = new DataOutputStream(stream);
            } else {
                dos = new LEDataOutputStream(stream);
            }

            for (int i = 0; i < array.length; i++) {
                dos.writeInt(array[i]);
            }

            stream.close();
        } catch (IOException e) {
            throw new IllegalArgumentException("InputStream is unwritable : " + e.toString());
View Full Code Here

     * @param array float[]
     * @param append boolean
     */
    public void writeFloatArray(float[] array, boolean append) {
        try {
            DataOutput dos;
            if (bigEndian) {
                dos = new DataOutputStream(stream);
            } else {
                dos = new LEDataOutputStream(stream);
            }

            for (int i = 0; i < array.length; i++) {
                dos.writeFloat(array[i]);
            }

            stream.close();
        } catch (IOException e) {
            throw new IllegalArgumentException("InputStream is unwritable : " + e.toString());
View Full Code Here

     * @param array float[]
     * @param append boolean
     */
    public void writeDoubleArray(double[] array, boolean append) {
        try {
            DataOutput dos;
            if (bigEndian) {
                dos = new DataOutputStream(stream);
            } else {
                dos = new LEDataOutputStream(stream);
            }

            for (int i = 0; i < array.length; i++) {
                dos.writeDouble(array[i]);
            }

            stream.close();
        } catch (IOException e) {
            throw new IllegalArgumentException("InputStream is unwritable : " + e.toString());
View Full Code Here

        final AbstractValueComparisonOperation aOp = createValueComparisonOperation();
        final TaggedValuePointable tvp2 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();

        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final DataOutput dOut = abvs.getDataOutput();

        return new AbstractTaggedValueArgumentAggregateEvaluator(args) {
            long count;

            @Override
            public void init() throws AlgebricksException {
                count = 0;
            }

            @Override
            public void finish(IPointable result) throws AlgebricksException {
                if (count == 0) {
                    XDMConstants.setEmptySequence(result);
                } else {
                    result.set(abvs);
                }
            }

            @Override
            protected void step(TaggedValuePointable[] args) throws SystemException {
                TaggedValuePointable tvp1 = args[0];
                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
                    // The local aggregate did not find a value so the global aggregate is receiving a empty sequence.
                    tvp1.getValue(seqp);
                    int seqLen = seqp.getEntryCount();
                    if (seqLen != 0) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                } else {
                    if (count != 0) {
                        tvp2.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                    }
                    if (count == 0 || FunctionHelper.transformThenCompareMinMaxTaggedValues(aOp, tvp1, tvp2, dCtx)) {
                        try {
                            abvs.reset();
                            dOut.write(tvp1.getByteArray(), tvp1.getStartOffset(), tvp1.getLength());
                        } catch (IOException e) {
                            throw new SystemException(ErrorCode.SYSE0001, e);
                        }
                    }
                    count++;
View Full Code Here

    @Override
    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            throws AlgebricksException {
        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final DataOutput dOut = abvs.getDataOutput();
        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                TaggedValuePointable tvp = args[0];
                long count = 0;
                if (tvp.getTag() == ValueTag.SEQUENCE_TAG) {
                    tvp.getValue(seqp);
                    count = seqp.getEntryCount();
                } else {
                    count = 1;
                }

                try {
                    abvs.reset();
                    dOut.write(ValueTag.XS_INTEGER_TAG);
                    dOut.writeLong(count);
                    result.set(abvs);
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
            }
View Full Code Here

    @Override
    protected IAggregateEvaluator createEvaluator(IScalarEvaluator[] args) throws AlgebricksException {
        final TaggedValuePointable tvpCount = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        final ArrayBackedValueStorage abvsCount = new ArrayBackedValueStorage();
        final DataOutput dOutCount = abvsCount.getDataOutput();
        final ArrayBackedValueStorage abvsSum = new ArrayBackedValueStorage();
        final DataOutput dOutSum = abvsSum.getDataOutput();
        final ArrayBackedValueStorage abvsSeq = new ArrayBackedValueStorage();
        final SequenceBuilder sb = new SequenceBuilder();
        final AddOperation aOp = new AddOperation();

        return new AbstractTaggedValueArgumentAggregateEvaluator(args) {
            long count;
            TaggedValuePointable tvpSum = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();

            @Override
            public void init() throws AlgebricksException {
                count = 0;
                try {
                    abvsSum.reset();
                    dOutSum.write(ValueTag.XS_INTEGER_TAG);
                    dOutSum.writeLong(0);
                    tvpSum.set(abvsSum);
                } catch (Exception e) {
                    throw new AlgebricksException(e);
                }
            }
View Full Code Here

TOP

Related Classes of java.io.DataOutput

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.