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

The following examples show how to use org.apache.tinkerpop.gremlin.structure.util.empty.EmptyProperty. 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: Property.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
/**
 * Create an empty property that is not present.
 *
 * @param <V> The value class of the empty property
 * @return A property that is not present
 */
public static <V> Property<V> empty() {
    return EmptyProperty.instance();
}