doc987 commented on issue #6004: Automatically Determine Ingestion Schema
URL: 
https://github.com/apache/incubator-druid/issues/6004#issuecomment-411611395
 
 
   Okay, so how does one make an InputRowParser and InputRow?  Does an InputRow 
look something like the code shown below?
   
   ```java
   import java.util.*;
   
   import com.fasterxml.jackson.core.JsonProcessingException;
   import com.fasterxml.jackson.databind.ObjectMapper;
   import com.fasterxml.jackson.databind.JsonNode;
   import com.fasterxml.jackson.databind.node.ObjectNode;
   
   import org.joda.time.DateTime;
   
   
   class Telegraf_JSON_InputRow {
      
      private JsonNode root;
      private int time_factor = 1000; //convert input from seconds to 
milliseconds
      
      public Telegraf_JSON_InputRow(String json){
         this.init(json);
      }
      
      public void init(String json){
         this.root = this.json_string_to_node(json);
         this.time_factor = 1000; //different factors?
      }
      
      public JsonNode json_string_to_node(String json){
         ObjectMapper mapper = new ObjectMapper();
         JsonNode node = null;
         try{
            node = mapper.readTree(json);
         }catch(java.io.IOException e){
            e.printStackTrace();
         }
         return node;
      }
      
      long getTimestampFromEpoch(){
         return this.root.path("timestamp").longValue() * this.time_factor;
      }
      
      DateTime getTimestamp(){
         return new DateTime( this.root.path("timestamp").longValue() * 
this.time_factor );
      }
      
      List<String> getDimension(String dimension){
         return Arrays.asList( this.root.path("tags").path(dimension).asText() 
);
      }
      
      List<String> getDimensions(){
         List<String> ret = new ArrayList<String>();
         JsonNode tags = this.root.path("tags");
         if(!tags.isMissingNode()){
            Iterator<Map.Entry<String,JsonNode>> iter = tags.fields();
            while(iter.hasNext()){
               Map.Entry<String,JsonNode> entry = iter.next();
               ret.add(entry.getKey());
            }
         }
         return ret;
      }
      
      Object getRaw(String dimension){
         return new Object(); //what is this supposed to return?
      }
      
      Number getMetric(String dimension){
         return this.root.path("fields").path(dimension).numberValue();
      }
      
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to