Java Code Examples for org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode#size()
The following examples show how to use
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode#size() .
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: JsonRowSchemaConverter.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private static TypeInformation<Row> convertObject(String location, JsonNode node, JsonNode root) { // validate properties if (!node.has(PROPERTIES)) { return Types.ROW(); } if (!node.isObject()) { throw new IllegalArgumentException( "Invalid '" + PROPERTIES + "' property for object type in node: " + location); } final JsonNode props = node.get(PROPERTIES); final String[] names = new String[props.size()]; final TypeInformation<?>[] types = new TypeInformation[props.size()]; final Iterator<Map.Entry<String, JsonNode>> fieldIter = props.fields(); int i = 0; while (fieldIter.hasNext()) { final Map.Entry<String, JsonNode> subNode = fieldIter.next(); // set field name names[i] = subNode.getKey(); // set type types[i] = convertType(location + '/' + subNode.getKey(), subNode.getValue(), root); i++; } // validate that object does not contain additional properties if (node.has(ADDITIONAL_PROPERTIES) && node.get(ADDITIONAL_PROPERTIES).isBoolean() && node.get(ADDITIONAL_PROPERTIES).asBoolean()) { throw new IllegalArgumentException( "An object must not allow additional properties in node: " + location); } return Types.ROW_NAMED(names, types); }
Example 2
Source File: JsonRowSchemaConverter.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private static TypeInformation<?>[] convertTypes(String location, JsonNode arrayNode, JsonNode root) { final TypeInformation<?>[] types = new TypeInformation[arrayNode.size()]; final Iterator<JsonNode> elements = arrayNode.elements(); int i = 0; while (elements.hasNext()) { final TypeInformation<?> elementType = convertType( location + '[' + i + ']', elements.next(), root); types[i] = elementType; i += 1; } return types; }
Example 3
Source File: JsonRowDeserializationSchema.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private Object convertObjectArray(JsonNode node, TypeInformation<?> elementType) { final Object[] array = (Object[]) Array.newInstance(elementType.getTypeClass(), node.size()); for (int i = 0; i < node.size(); i++) { array[i] = convert(node.get(i), elementType); } return array; }
Example 4
Source File: FlinkDistribution.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public void startFlinkCluster() throws IOException { AutoClosableProcess.runBlocking("Start Flink cluster", bin.resolve("start-cluster.sh").toAbsolutePath().toString()); final OkHttpClient client = new OkHttpClient(); final Request request = new Request.Builder() .get() .url("http://localhost:8081/taskmanagers") .build(); Exception reportedException = null; for (int retryAttempt = 0; retryAttempt < 30; retryAttempt++) { try (Response response = client.newCall(request).execute()) { if (response.isSuccessful()) { final String json = response.body().string(); final JsonNode taskManagerList = OBJECT_MAPPER.readTree(json) .get("taskmanagers"); if (taskManagerList != null && taskManagerList.size() > 0) { LOG.info("Dispatcher REST endpoint is up."); return; } } } catch (IOException ioe) { reportedException = ExceptionUtils.firstOrSuppressed(ioe, reportedException); } LOG.info("Waiting for dispatcher REST endpoint to come up..."); try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); reportedException = ExceptionUtils.firstOrSuppressed(e, reportedException); } } throw new AssertionError("Dispatcher REST endpoint did not start in time.", reportedException); }
Example 5
Source File: JsonRowSchemaConverter.java From flink with Apache License 2.0 | 5 votes |
private static TypeInformation<Row> convertObject(String location, JsonNode node, JsonNode root) { // validate properties if (!node.has(PROPERTIES)) { return Types.ROW(); } if (!node.isObject()) { throw new IllegalArgumentException( "Invalid '" + PROPERTIES + "' property for object type in node: " + location); } final JsonNode props = node.get(PROPERTIES); final String[] names = new String[props.size()]; final TypeInformation<?>[] types = new TypeInformation[props.size()]; final Iterator<Map.Entry<String, JsonNode>> fieldIter = props.fields(); int i = 0; while (fieldIter.hasNext()) { final Map.Entry<String, JsonNode> subNode = fieldIter.next(); // set field name names[i] = subNode.getKey(); // set type types[i] = convertType(location + '/' + subNode.getKey(), subNode.getValue(), root); i++; } // validate that object does not contain additional properties if (node.has(ADDITIONAL_PROPERTIES) && node.get(ADDITIONAL_PROPERTIES).isBoolean() && node.get(ADDITIONAL_PROPERTIES).asBoolean()) { throw new IllegalArgumentException( "An object must not allow additional properties in node: " + location); } return Types.ROW_NAMED(names, types); }
Example 6
Source File: JsonRowSchemaConverter.java From flink with Apache License 2.0 | 5 votes |
private static TypeInformation<?>[] convertTypes(String location, JsonNode arrayNode, JsonNode root) { final TypeInformation<?>[] types = new TypeInformation[arrayNode.size()]; final Iterator<JsonNode> elements = arrayNode.elements(); int i = 0; while (elements.hasNext()) { final TypeInformation<?> elementType = convertType( location + '[' + i + ']', elements.next(), root); types[i] = elementType; i += 1; } return types; }
Example 7
Source File: FlinkDistribution.java From flink with Apache License 2.0 | 5 votes |
public void startFlinkCluster() throws IOException { LOG.info("Starting Flink cluster."); AutoClosableProcess.runBlocking(bin.resolve("start-cluster.sh").toAbsolutePath().toString()); final OkHttpClient client = new OkHttpClient(); final Request request = new Request.Builder() .get() .url("http://localhost:8081/taskmanagers") .build(); Exception reportedException = null; for (int retryAttempt = 0; retryAttempt < 30; retryAttempt++) { try (Response response = client.newCall(request).execute()) { if (response.isSuccessful()) { final String json = response.body().string(); final JsonNode taskManagerList = OBJECT_MAPPER.readTree(json) .get("taskmanagers"); if (taskManagerList != null && taskManagerList.size() > 0) { LOG.info("Dispatcher REST endpoint is up."); return; } } } catch (IOException ioe) { reportedException = ExceptionUtils.firstOrSuppressed(ioe, reportedException); } LOG.info("Waiting for dispatcher REST endpoint to come up..."); try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); reportedException = ExceptionUtils.firstOrSuppressed(e, reportedException); } } throw new AssertionError("Dispatcher REST endpoint did not start in time.", reportedException); }
Example 8
Source File: JsonRowSchemaConverter.java From flink with Apache License 2.0 | 5 votes |
private static TypeInformation<Row> convertObject(String location, JsonNode node, JsonNode root) { // validate properties if (!node.has(PROPERTIES)) { return Types.ROW(); } if (!node.isObject()) { throw new IllegalArgumentException( "Invalid '" + PROPERTIES + "' property for object type in node: " + location); } final JsonNode props = node.get(PROPERTIES); final String[] names = new String[props.size()]; final TypeInformation<?>[] types = new TypeInformation[props.size()]; final Iterator<Map.Entry<String, JsonNode>> fieldIter = props.fields(); int i = 0; while (fieldIter.hasNext()) { final Map.Entry<String, JsonNode> subNode = fieldIter.next(); // set field name names[i] = subNode.getKey(); // set type types[i] = convertType(location + '/' + subNode.getKey(), subNode.getValue(), root); i++; } // validate that object does not contain additional properties if (node.has(ADDITIONAL_PROPERTIES) && node.get(ADDITIONAL_PROPERTIES).isBoolean() && node.get(ADDITIONAL_PROPERTIES).asBoolean()) { throw new IllegalArgumentException( "An object must not allow additional properties in node: " + location); } return Types.ROW_NAMED(names, types); }
Example 9
Source File: JsonRowSchemaConverter.java From flink with Apache License 2.0 | 5 votes |
private static TypeInformation<?>[] convertTypes(String location, JsonNode arrayNode, JsonNode root) { final TypeInformation<?>[] types = new TypeInformation[arrayNode.size()]; final Iterator<JsonNode> elements = arrayNode.elements(); int i = 0; while (elements.hasNext()) { final TypeInformation<?> elementType = convertType( location + '[' + i + ']', elements.next(), root); types[i] = elementType; i += 1; } return types; }
Example 10
Source File: FlinkDistribution.java From flink with Apache License 2.0 | 5 votes |
public void startFlinkCluster() throws IOException { LOG.info("Starting Flink cluster."); AutoClosableProcess.runBlocking(bin.resolve("start-cluster.sh").toAbsolutePath().toString()); final OkHttpClient client = new OkHttpClient(); final Request request = new Request.Builder() .get() .url("http://localhost:8081/taskmanagers") .build(); Exception reportedException = null; for (int retryAttempt = 0; retryAttempt < 30; retryAttempt++) { try (Response response = client.newCall(request).execute()) { if (response.isSuccessful()) { final String json = response.body().string(); final JsonNode taskManagerList = OBJECT_MAPPER.readTree(json) .get("taskmanagers"); if (taskManagerList != null && taskManagerList.size() > 0) { LOG.info("Dispatcher REST endpoint is up."); return; } } } catch (IOException ioe) { reportedException = ExceptionUtils.firstOrSuppressed(ioe, reportedException); } LOG.info("Waiting for dispatcher REST endpoint to come up..."); try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); reportedException = ExceptionUtils.firstOrSuppressed(e, reportedException); } } throw new AssertionError("Dispatcher REST endpoint did not start in time.", reportedException); }