org.apache.tinkerpop.gremlin.structure.util.empty.EmptyVertexProperty Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.structure.util.empty.EmptyVertexProperty. 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: JoinQueryExecutor.java    From sql-gremlin with Apache License 2.0 4 votes vote down vote up
private List<Object> project(Map<String, String> fieldToTableMap, List<String> fields,
                               List<Map<String, ? extends Element>> results,
                               Map<String, TableDef> tableIdToTableDefMap) {
    final List<Object> rows = new ArrayList<>(results.size());
    Map<String, String> labelTableIdMap = new HashMap<>();
    for (Map.Entry<String, TableDef> entry : tableIdToTableDefMap.entrySet()) {
        labelTableIdMap.put(entry.getValue().label.toLowerCase(), entry.getKey());
    }
    for(Map<String, ? extends Element> result : results) {
        final Object[] row = new Object[fields.size()];
        int column = 0;
        for(String field : fields) {
            String tableId = fieldToTableMap.get(field);
            String simpleFieldName = Character.isDigit(field.charAt(field.length()-1)) ?
                    field.substring(0, field.length()-1) : field;
            simpleFieldName = Character.isDigit(field.charAt(simpleFieldName.length()-1)) ?
                    simpleFieldName.substring(0, simpleFieldName.length()-1) : simpleFieldName;
            // check for primary & fks
            final int keyIndex = simpleFieldName.toLowerCase().indexOf("_id");
            Object val = null;
            if(keyIndex > 0) {
                // is it a pk or fk?
                String key = simpleFieldName.substring(0, keyIndex);
                String tableLabel = tableIdToTableDefMap.get(tableId).label;
                if(tableLabel.toLowerCase().equals(key.toLowerCase())) {
                    val = result.get(tableId).id();
                } else {
                    String fkTableId = labelTableIdMap.get(key.toLowerCase());
                    if(result.containsKey(fkTableId)) {
                        val = result.get(fkTableId).id();
                    }
                }
            }
            final Property<Object> property = result.get(tableId).
                    property(tableIdToTableDefMap.get(tableId).getColumn(simpleFieldName.toLowerCase()).getPropertyName());
            if(!(property instanceof EmptyProperty || property instanceof EmptyVertexProperty)) {
                if(result.get(tableId).label().equals(tableIdToTableDefMap.get(tableId).label)) {
                    val = property.value();
                } else {
                    val = null;
                }
            }
            if(tableIdToTableDefMap.get(tableId).getColumn(field) != null && val != null) {
                row[column++] = TableUtil.convertType(val, tableIdToTableDefMap.get(tableId).getColumn(field));
            } else {
                row[column++] = val;
            }
        }
        rows.add(row);
    }
    return rows;
}
 
Example #2
Source File: VertexProperty.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an empty {@code VertexProperty}.
 */
public static <V> VertexProperty<V> empty() {
    return EmptyVertexProperty.instance();
}