org.codehaus.jackson.node.ArrayNode Java Examples

The following examples show how to use org.codehaus.jackson.node.ArrayNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpMetricsIndexHandler.java    From blueflood with Apache License 2.0 7 votes vote down vote up
public static String getSerializedJSON(List<SearchResult> searchResults) {
    ArrayNode resultArray = JsonNodeFactory.instance.arrayNode();
    for (SearchResult result : searchResults) {
        ObjectNode resultNode = JsonNodeFactory.instance.objectNode();
        resultNode.put("metric", result.getMetricName());

        String unit = result.getUnit();
        if (unit != null) {
            //Preaggreated metrics do not have units. Do not want to return null units in query results.
            resultNode.put("unit", unit);
        }

        resultArray.add(resultNode);
    }
    return resultArray.toString();
}
 
Example #2
Source File: PhysicalParser.java    From Cubert with Apache License 2.0 6 votes vote down vote up
@Override
public void exitCreateDictionary(CreateDictionaryContext ctx)
{
    ObjectNode dict = objMapper.createObjectNode();
    String dictName = ctx.ID().getText();
    for (ColumnDictionaryContext colDict : ctx.columnDictionary())
    {
        String columnName = colDict.ID().getText();
        ArrayNode values = objMapper.createArrayNode();
        for (TerminalNode val : colDict.STRING())
        {
            values.add(CommonUtils.stripQuotes(val.getText()));
        }
        dict.put(columnName, values);
    }
    inlineDictionaries.put(dictName, dict);
}
 
Example #3
Source File: JobHistoryEventHandler.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Private
public JsonNode countersToJSON(Counters counters) {
  ObjectMapper mapper = new ObjectMapper();
  ArrayNode nodes = mapper.createArrayNode();
  if (counters != null) {
    for (CounterGroup counterGroup : counters) {
      ObjectNode groupNode = nodes.addObject();
      groupNode.put("NAME", counterGroup.getName());
      groupNode.put("DISPLAY_NAME", counterGroup.getDisplayName());
      ArrayNode countersNode = groupNode.putArray("COUNTERS");
      for (Counter counter : counterGroup) {
        ObjectNode counterNode = countersNode.addObject();
        counterNode.put("NAME", counter.getName());
        counterNode.put("DISPLAY_NAME", counter.getDisplayName());
        counterNode.put("VALUE", counter.getValue());
      }
    }
  }
  return nodes;
}
 
Example #4
Source File: Lineage.java    From Cubert with Apache License 2.0 6 votes vote down vote up
private static boolean visitMappers(ObjectNode jobNode,
                                    OperatorVisitor visitorObj,
                                    boolean reverse)
{
    ArrayNode mappers = (ArrayNode) jobNode.get("map");
    int si = (reverse ? mappers.size() - 1 : 0);
    int ei = (reverse ? -1 : mappers.size());

    // TODO Auto-generated method stub
    for (int i = si; i != ei; i += increment(reverse))
    {
        if (!visitMapNode(jobNode, mappers.get(i), visitorObj, reverse))
            return false;
    }
    return true;
}
 
Example #5
Source File: GeoJsonParser.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Example:
 * [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
 * @param parser
 * @return a polygon
 * @throws JsonParseException
 * @throws IOException
 */
private Polygon parseSimplePolygonCoordinates(JsonNode node) {
  Polygon g = new Polygon();
  boolean first = true;
  ArrayNode points = (ArrayNode) node;
  for (JsonNode point : points) {
    Point p = parsePointCoordinates(point);
    if (first) {
      g.startPath(p);
      first = false;
    } else {
      g.lineTo(p);
    }  
  }
  g.closeAllPaths();
  return g;
}
 
Example #6
Source File: Lineage.java    From Cubert with Apache License 2.0 6 votes vote down vote up
private static String checkTopLevelColumn(ObjectNode sourceOp,
                                          JsonNode genExprNode)
{
    String topColName = null;
    if (!(genExprNode instanceof ObjectNode))
        return null;

    ObjectNode opNode = (ObjectNode) genExprNode;
    if (opNode.get("function") == null
            || !opNode.get("function").getTextValue().equals("INPUT_PROJECTION"))
        return null;
    ArrayNode argsNode = (ArrayNode) opNode.get("arguments");
    if (argsNode.size() != 1 
            || ((topColName = findNamedColumn(argsNode)) == null)
            && (topColName = findIndexedColumn(sourceOp, argsNode)) == null)
        return null;
    return topColName;

}
 
Example #7
Source File: PhysicalParser.java    From Cubert with Apache License 2.0 6 votes vote down vote up
private ObjectNode createProjectionConstantNode(ColumnProjectionExpressionContext columnexpr)
{
    // create constant object
    ObjectNode constant = objMapper.createObjectNode();
    constant.put("function", "CONSTANT");
    ArrayNode constantArgs = objMapper.createArrayNode();
    constant.put("arguments", constantArgs);

    if (columnexpr.ID() != null)
    {
        constantArgs.add(columnexpr.ID().getText());
    }
    else
    {
        constantArgs.add(Integer.parseInt(columnexpr.INT().getText()));
    }

    return constant;
}
 
Example #8
Source File: ShuffleRewriter.java    From Cubert with Apache License 2.0 6 votes vote down vote up
@Override
public JsonNode rewrite(JsonNode plan,
                        Set<String> namesUsed,
                        boolean debugMode,
                        boolean revisit)
{
    this.namesUsed = namesUsed;

    ObjectNode newPlan = (ObjectNode) cloneNode(plan);

    ArrayNode jobs = mapper.createArrayNode();

    for (JsonNode job : plan.path("jobs"))
    {
        jobs.add(rewriteJob(job));
    }

    newPlan.remove("jobs");
    newPlan.put("jobs", jobs);

    return newPlan;
}
 
Example #9
Source File: ClusterResource.java    From exhibitor with Apache License 2.0 6 votes vote down vote up
@Path("list")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String   getClusterAsJson() throws Exception
{
    InstanceConfig      config = context.getExhibitor().getConfigManager().getConfig();

    ObjectNode          node = JsonNodeFactory.instance.objectNode();

    ArrayNode           serversNode = JsonNodeFactory.instance.arrayNode();
    ServerList          serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
    for ( ServerSpec spec : serverList.getSpecs() )
    {
        serversNode.add(spec.getHostname());
    }
    node.put("servers", serversNode);
    node.put("port", config.getInt(IntConfigs.CLIENT_PORT));

    return JsonUtil.writeValueAsString(node);
}
 
Example #10
Source File: ShuffleRewriter.java    From Cubert with Apache License 2.0 6 votes vote down vote up
private JsonNode rewriteDistinct(JsonNode job)
{
    ObjectNode newJob = (ObjectNode) cloneNode(job);
    ObjectNode shuffle = (ObjectNode) newJob.get("shuffle");
    String name = getText(shuffle, "name");

    ObjectNode distinctOp =
            JsonUtils.createObjectNode("operator",
                                       "DISTINCT",
                                       "input",
                                       name,
                                       "output",
                                       name);

    if (!newJob.has("reduce") || newJob.get("reduce").isNull())
        newJob.put("reduce", mapper.createArrayNode());
    ArrayNode reduce = (ArrayNode) newJob.get("reduce");
    reduce.insert(0, distinctOp);

    shuffle.put("type", "SHUFFLE");
    shuffle.put("distinctShuffle", true);

    return newJob;
}
 
Example #11
Source File: Lineage.java    From Cubert with Apache License 2.0 6 votes vote down vote up
public static void visitOperators(ObjectNode programNode,
                                  ObjectNode jobNode,
                                  OperatorVisitor tracerObj,
                                  boolean reverse)
{
    ArrayNode jobs = (ArrayNode) programNode.get("jobs");
    int si = (reverse ? jobs.size() - 1 : 0);
    int ei = (reverse ? -1 : jobs.size());

    for (int i = si; i != ei; i = i + increment(reverse))
    {
        if (jobNode != null && jobNode != jobs.get(i))
            continue;

        if (!visitOperatorsInJob(programNode,
                                 (ObjectNode) jobs.get(i),
                                 tracerObj,
                                 reverse))
            return;
    }
}
 
Example #12
Source File: AggregateRewriter.java    From Cubert with Apache License 2.0 6 votes vote down vote up
protected ObjectNode getFactTimeSpecNode(ObjectNode factNode, ObjectNode cubeNode) throws AggregateRewriteException
{
    List<String> paths = lineage.getPaths(factNode.get("path"));
    for (JsonNode timeSpecNode : (ArrayNode) (cubeNode.get("timeColumnSpec")))
    {
        String elementPath =
                ((ObjectNode) timeSpecNode).get("factPath").getTextValue();
        if (paths.indexOf(elementPath) != -1)
        {
            tNode = (ObjectNode) timeSpecNode;
            return tNode;
        }
    }
    throw new AggregateRewriteException("No matching time column specification found for FACT load at "
            + factNode.toString());
}
 
Example #13
Source File: JsonUtils.java    From Cubert with Apache License 2.0 6 votes vote down vote up
public static String[] asArray(JsonNode node)
{
    if (node == null)
        throw new IllegalArgumentException("Specified JsonNode is null");

    if (node.isArray())
    {
        ArrayNode anode = (ArrayNode) node;
        int nelements = anode.size();
        String[] array = new String[nelements];
        for (int i = 0; i < nelements; i++)
        {
            array[i] = anode.get(i).getTextValue();
        }
        return array;
    }
    else
    {
        return new String[] { node.getTextValue() };
    }
}
 
Example #14
Source File: CountDistinctRewriter.java    From Cubert with Apache License 2.0 6 votes vote down vote up
public ObjectNode postCombineGroupBy()
{
    ArrayNode aggsNode = JsonUtils.createArrayNode();
    aggsNode.add(RewriteUtils.createObjectNode("type",
                                               "BITWISE_OR",
                                               "input",
                                               BITMAP_COLUMN_NAME,
                                               "output",
                                               BITMAP_COLUMN_NAME));
    ObjectNode groupByNode =
            RewriteUtils.createObjectNode("operator",
                                          "GROUP_BY",
                                          "input",
                                          combinedRelation,
                                          "output",
                                          combinedRelation,
                                          "groupBy",
                                          JsonUtils.createArrayNode(preCubeLoadColumns),
                                          "aggregates",
                                          aggsNode);
    return groupByNode;
}
 
Example #15
Source File: PhysicalParser.java    From Cubert with Apache License 2.0 6 votes vote down vote up
@Override
public void exitPivotOperator(PivotOperatorContext ctx)
{
    operatorNode.put("operator", "PIVOT_BLOCK");
    operatorNode.put("output", operatorCommandLhs);
    operatorNode.put("input", ctx.ID(0).getText());

    ArrayNode anode = objMapper.createArrayNode();
    if (ctx.columns() != null)
    {
        for (TerminalNode id : ctx.columns().ID())
            anode.add(id.getText());

        operatorNode.put("pivotBy", anode);
    }
    else
    {
        // this is pivot by row or size
        operatorNode.put("pivotType", ctx.type.getText());
        operatorNode.put("pivotValue", ctx.value.getText());
    }
    operatorNode.put("inMemory", ctx.inmemory != null);
}
 
Example #16
Source File: MovieTO.java    From big-data-lite with MIT License 6 votes vote down vote up
/** This method returns JSON object with all the movie attributes and its
 * values**/
public ObjectNode getMovieJson() {
    ObjectNode movieJson = super.getObjectNode();
    ArrayNode genreArray = super.getArrayNode();
    ObjectNode genreJson = null;

    movieJson.put(JsonConstant.ID, this.getId());
    movieJson.put(JsonConstant.TITLE, this.getTitle());
    movieJson.put(JsonConstant.RELEASE_DATE, this.getDate());        
    movieJson.put(JsonConstant.VOTE, this.getVoteCount());
    movieJson.put(JsonConstant.POPULARITY, this.getPopularity());
    movieJson.put(JsonConstant.POSTER, this.getPosterPath());
    movieJson.put(JsonConstant.RUNTIME, this.getRunTime());
    movieJson.put(JsonConstant.OVERVIEW, this.getOverview());

    for (GenreTO genreTO : genres) {
        genreJson = genreTO.getGenreJson();
        genreArray.add(genreJson);
    } //EOF for

    //set genres to movie json object
   movieJson.put(JsonConstant.GENRES, genreArray);

    return movieJson;
}
 
Example #17
Source File: BoundaryEventJsonConverter.java    From fixflow with Apache License 2.0 6 votes vote down vote up
protected void convertElementToJson(ObjectNode propertiesNode, FlowElement flowElement) {
  BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
  ArrayNode dockersArrayNode = objectMapper.createArrayNode();
  ObjectNode dockNode = objectMapper.createObjectNode();
  
  
  BPMNShape graphicInfo = BpmnModelUtil.getBpmnShape(model, boundaryEvent.getId());;
  BPMNShape parentGraphicInfo = BpmnModelUtil.getBpmnShape(model,boundaryEvent.getAttachedToRef().getId());
  dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getBounds().getX() + graphicInfo.getBounds().getWidth() - parentGraphicInfo.getBounds().getX());
  dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getBounds().getY() - parentGraphicInfo.getBounds().getY());
  dockersArrayNode.add(dockNode);
  flowElementNode.put("dockers", dockersArrayNode);
  
  if (boundaryEvent.isCancelActivity() == false) {
    propertiesNode.put(PROPERTY_CANCEL_ACTIVITY, PROPERTY_VALUE_NO);
  }
  
  addEventProperties(boundaryEvent, propertiesNode);
}
 
Example #18
Source File: TestOperators.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@Test
public void testGroupByWithSum2() throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    Object[][] rows1 =
            { { 0, 0 }, { 2, 2 }, { 2, 5 }, { 5, 6 }, { 10, 1 }, { 100, 10 } };
    Block block = new ArrayBlock(Arrays.asList(rows1), new String[] { "a", "b" }, 1);

    TupleOperator operator = new GroupByOperator();
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("first", block);

    ObjectMapper mapper = new ObjectMapper();

    ObjectNode json = mapper.createObjectNode();
    json.put("input", "first");
    ArrayNode anode = mapper.createArrayNode();
    anode.add("a");
    json.put("groupBy", anode);
    anode = mapper.createArrayNode();
    ObjectNode onode = mapper.createObjectNode();
    onode.put("type", "SUM");
    onode.put("input", "b");
    onode.put("output", "sum");
    anode.add(onode);
    json.put("aggregates", anode);

    BlockProperties props =
            new BlockProperties(null,
                                new BlockSchema("INT a, INT sum"),
                                (BlockProperties) null);
    operator.setInput(input, json, props);

    Block output = new TupleOperatorBlock(operator, props);

    ArrayBlock.assertData(output, new Object[][] { { 0, 0 }, { 2, 7 }, { 5, 6 },
            { 10, 1 }, { 100, 10 } }, new String[] { "a", "sum" });
}
 
Example #19
Source File: PhysicalParser.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@Override
public void exitInputCommand(@NotNull InputCommandContext ctx)
{
    ObjectNode inputNode = objMapper.createObjectNode();
    addLine(ctx, inputNode);

    inputNode.put("name", ctx.ID().get(0).getText());

    if (ctx.format != null)
        inputNode.put("type", ctx.format.getText().toUpperCase());
    else
        inputNode.put("type", ctx.classname.getText());

    ObjectNode paramsNode = objMapper.createObjectNode();
    if (ctx.params() != null)
    {

        for (int i = 0; i < ctx.params().keyval().size(); i++)
        {
            List<TerminalNode> kv = ctx.params().keyval(i).STRING();
            paramsNode.put(CommonUtils.stripQuotes(kv.get(0).getText()),
                           CommonUtils.stripQuotes(kv.get(1).getText()));
        }
    }
    inputNode.put("params", paramsNode);

    ArrayNode inputPathArray = createInputPathsNode(ctx.inputPaths());
    inputNode.put("path", inputPathArray);

    this.mapCommandsNode.put("input", inputNode);

}
 
Example #20
Source File: RewriteUtils.java    From Cubert with Apache License 2.0 5 votes vote down vote up
public static String[] getInputRelations(ObjectNode opNode)
{
    String[] inputRelations;
    if (opNode.get("input") instanceof ArrayNode)
        inputRelations = JsonUtils.asArray(opNode.get("input"));
    else
        inputRelations = new String[]{opNode.get("input").getTextValue()};
    return inputRelations;
}
 
Example #21
Source File: PerfProfiler.java    From Cubert with Apache License 2.0 5 votes vote down vote up
private void updateCounter()
{
    long[] operatorTime = getOperatorTime();

    String profileCounterGroupName =
            PhaseContext.isMapper() ? mapperProfileCounterGroupName
                    : reducerProfileCounterGroupName;

    ArrayNode operatorsJson = multipassOperatorsJson.get(currentPassIndex);
    for (int i = 0; i < operatorTime.length; i++)
    {
        if (operatorTime[i] > 0)
        {
            JsonNode operatorJson = operatorsJson.get(i);

            OperatorType type =
                    OperatorType.valueOf(operatorJson.get("operator").getTextValue());
            String outputName = operatorJson.get("output").getTextValue();

            String counterName =
                    String.format("P%d-O%d-%s-%s",
                                  currentPassIndex,
                                  i,
                                  type,
                                  outputName);
            Counter profileCounter =
                    PhaseContext.getCounter(profileCounterGroupName, counterName);
            profileCounter.increment(operatorTime[i]);
        }
    }
}
 
Example #22
Source File: PerInstanceAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
@GET
@Path("errors")
public Response getErrorsOnInstance(@PathParam("clusterId") String clusterId,
    @PathParam("instanceName") String instanceName) throws IOException {
  HelixDataAccessor accessor = getDataAccssor(clusterId);

  ObjectNode root = JsonNodeFactory.instance.objectNode();
  root.put(Properties.id.name(), instanceName);
  ObjectNode errorsNode = JsonNodeFactory.instance.objectNode();

  List<String> sessionIds = accessor.getChildNames(accessor.keyBuilder().errors(instanceName));

  if (sessionIds == null || sessionIds.size() == 0) {
    return notFound();
  }

  for (String sessionId : sessionIds) {
    List<String> resources =
        accessor.getChildNames(accessor.keyBuilder().errors(instanceName, sessionId));
    if (resources != null) {
      ObjectNode resourcesNode = JsonNodeFactory.instance.objectNode();
      for (String resourceName : resources) {
        List<String> partitions = accessor
            .getChildNames(accessor.keyBuilder().errors(instanceName, sessionId, resourceName));
        if (partitions != null) {
          ArrayNode partitionsNode = resourcesNode.putArray(resourceName);
          partitionsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(partitions));
        }
      }
      errorsNode.put(sessionId, resourcesNode);
    }
  }
  root.put(PerInstanceProperties.errors.name(), errorsNode);

  return JSONRepresentation(root);
}
 
Example #23
Source File: JsonUtils.java    From Cubert with Apache License 2.0 5 votes vote down vote up
public static ArrayNode createArrayNode(JsonNode... elementNodes)
{
    ArrayNode result = getMapper().createArrayNode();
    for (int i = 0; i < elementNodes.length; i++)
        result.add(elementNodes[i]);
    return result;
}
 
Example #24
Source File: LineageHelper.java    From Cubert with Apache License 2.0 5 votes vote down vote up
public List<ObjectNode> findOperatorInputSources(ObjectNode opNode,
                                                 String inputRelation)
{
    int opSequence = this.getOpSequence(opNode);
    ObjectNode jobNode = (ObjectNode) (this.getJobPhase(opNode).getFirst());
    JsonNode phaseNode = this.getJobPhase(opNode).getSecond();
    List<ObjectNode> result = new ArrayList<ObjectNode>();

    if (isReducePhase(phaseNode)
            && (opSequence == 0 || getOperatorSourceInPhase(jobNode,
                                                            (ArrayNode) phaseNode,
                                                            opNode,
                                                            inputRelation) == null))
    {
        // if either first operator in reduce phase or a matching source within
        // the same phase cannot be found,
        // look inside all the map jobs.
        ArrayNode mapsArray = (ArrayNode) getJobPhase(opNode).getFirst().get("map");
        for (JsonNode mapNode : mapsArray)
        {
            ArrayNode mapOps = (ArrayNode) ((ObjectNode) mapNode).get("operators");
            if (mapOps == null || mapOps.size() == 0)
                continue;
            ObjectNode lastOp = (ObjectNode) mapOps.get(mapOps.size() - 1);
            result.add(findOperatorSourcePrior(getOpSequence(lastOp), inputRelation));
        }
    }
    else
        result.add(findOperatorSource(opNode, inputRelation));

    return result;

}
 
Example #25
Source File: IndexerDefinitionsMessageBodyWriter.java    From hbase-indexer with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(Collection<IndexerDefinition> indices, Class<?> type,
                    Type genericType, Annotation[] annotations, MediaType mediaType,
                    MultivaluedMap<String, Object> httpHeaders, OutputStream outputStream)
        throws IOException, WebApplicationException {
    ArrayNode array = JsonNodeFactory.instance.arrayNode();
    IndexerDefinitionJsonSerDeser converter = IndexerDefinitionJsonSerDeser.INSTANCE;

    for (IndexerDefinition index : indices) {
        array.add(converter.toJson(index));
    }

    ObjectMapper objectMapper = new ObjectMapper();
    IOUtils.write(objectMapper.writeValueAsBytes(array), outputStream);
}
 
Example #26
Source File: LineageHelper.java    From Cubert with Apache License 2.0 5 votes vote down vote up
public ArrayList<ObjectNode> findAllOperatorSources(ObjectNode jobNode,
                                                    JsonNode phaseNode,
                                                    ObjectNode opNode)
{
    ArrayList<ObjectNode> sourceNodes = new ArrayList<ObjectNode>();

    if (isLoadOperator(jobNode, phaseNode, opNode))
    {
        List<String> loadPaths = operatorMapGet(loadPathsMap, opNode);
        for (String loadPath : loadPaths)
        {
            ObjectNode storeNode = findPrecedingStore(opNode, loadPath);
            if (storeNode != null)
                sourceNodes.add(storeNode);
        }
        return sourceNodes;
    }

    JsonNode inputsNode =
            (isStoreCommand(jobNode, phaseNode, opNode) ? opNode.get("name")
                    : opNode.get("input"));
    if (inputsNode == null)
    {
        // trace("Getting sources for " + opNode.toString() + " ?");
        return null;
    }

    if (!(inputsNode instanceof ArrayNode))
        sourceNodes.addAll(findOperatorInputSources(opNode, inputsNode.getTextValue()));
    else
    {
        for (JsonNode inputNode : (ArrayNode) inputsNode)
            sourceNodes.addAll(findOperatorInputSources(opNode,
                                                        inputNode.getTextValue()));
    }

    return sourceNodes;
}
 
Example #27
Source File: JsonUtils.java    From Cubert with Apache License 2.0 5 votes vote down vote up
public static boolean isPrefixArray(ArrayNode pnode, ArrayNode snode)
{
    if (pnode == null || snode == null || pnode.size() > snode.size())
        return false;

    for (int i = 0; i < pnode.size(); i++)
    {
        if (!pnode.get(i).getTextValue().equals(snode.get(i).getTextValue()))
            return false;
    }
    return true;
}
 
Example #28
Source File: JsonUtils.java    From Cubert with Apache License 2.0 5 votes vote down vote up
public static ArrayNode insertNodeListAfter(ArrayNode arrayNode,
                                            ObjectNode afterThisNode,
                                            List<ObjectNode> nodeList)
{
    ArrayList<JsonNode> currentNodeList = JsonUtils.toArrayList(arrayNode);
    int insertPosition = CommonUtils.indexOfByRef(currentNodeList, afterThisNode);
    currentNodeList.addAll(insertPosition + 1, nodeList);
    return JsonUtils.toArrayNode(currentNodeList);
}
 
Example #29
Source File: JsonUtils.java    From Cubert with Apache License 2.0 5 votes vote down vote up
public static ArrayNode toArrayNode(List<JsonNode> nodelist)
{
    ArrayNode result = createArrayNode();
    for (JsonNode elem : nodelist)
        result.add(elem);
    return result;
}
 
Example #30
Source File: PhysicalParser.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@Override
public void exitEncodeOperator(@NotNull EncodeOperatorContext ctx)
{
    operatorNode.put("operator", "DICT_ENCODE");
    operatorNode.put("input", ctx.ID(0).getText());
    operatorNode.put("output", operatorCommandLhs);

    ArrayNode anode = objMapper.createArrayNode();

    for (TerminalNode id : ctx.columns().ID())
        anode.add(id.getText());

    operatorNode.put("columns", anode);

    if (ctx.path() == null)
    {
        ObjectNode dict = inlineDictionaries.get(ctx.dictname.getText());
        if (dict == null)
            throw new RuntimeException("Dictionary " + ctx.dictname.getText()
                    + " is not available");
        operatorNode.put("dictionary", dict);
    }
    else
    {
        String dictionaryPath = cleanPath(ctx.path());
        operatorNode.put("path", dictionaryPath);
        cachedFiles.add(dictionaryPath);
    }

    if (ctx.nullas != null)
    {
        operatorNode.put("replaceNull", ctx.nullas.getText());
    }

    if (ctx.n != null)
    {
        operatorNode.put("replaceUnknownCodes", ctx.n.getText());
    }
}