org.neo4j.graphdb.Result.columns()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中org.neo4j.graphdb.Result.columns方法的一些代码示例,展示了Result.columns的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Result.columns方法的具体详情如下:
包路径:org.neo4j.graphdb.Result
类名称:Result
方法名:columns

Result.columns介绍

[英]The exact names used to represent each column in the result set.
[中]

代码示例

代码示例来源:origin: neo4j/neo4j

@Override
public List<String> columns()
{
  return originalResult.columns();
}

代码示例来源:origin: neo4j/neo4j

EagerQueryResult()
{
  fields = originalResult.columns().toArray( new String[0] );
}

代码示例来源:origin: neo4j/neo4j

@Override
public String resultAsString()
{
  List<String> columns = originalResult.columns();
  StringBuilder builder = new StringBuilder();
  builder.append( String.join( ITEM_SEPARATOR, columns ) );
  if ( !queryResult.isEmpty() )
  {
    builder.append( lineSeparator() );
    int numberOfColumns = columns.size();
    for ( Map<String,Object> row : queryResult )
    {
      writeRow( columns, builder, numberOfColumns, row );
      builder.append( lineSeparator() );
    }
  }
  return builder.toString();
}

代码示例来源:origin: neo4j/neo4j

@Test
@SuppressWarnings( "unchecked" )
public void shouldNotIncludePlanUnlessAskedFor() throws Exception
{
  // Given
  Result result = mock( Result.class );
  when( result.hasNext() ).thenReturn( false );
  when( result.columns() ).thenReturn( new ArrayList<>() );
  // When
  Map<String, Object> serialized = serializeToStringThenParseAsToMap( new CypherResultRepresentation( result,
      /*includeStats=*/false, false ) );
  // Then
  assertFalse( "Didn't expect to see a plan here", serialized.containsKey( "plan" ) );
}

代码示例来源:origin: neo4j/neo4j

public CypherResultRepresentation( final Result result, boolean includeStats, boolean includePlan )
{
  super( RepresentationType.STRING );
  resultRepresentation = createResultRepresentation( result );
  columns = ListRepresentation.string( result.columns() );
  statsRepresentation = includeStats ? new CypherStatisticsRepresentation( result.getQueryStatistics() ) : null;
  plan = includePlan ? CypherPlanRepresentation.newFromProvider(planProvider(result)) : null;
}

代码示例来源:origin: neo4j/neo4j

private ListRepresentation createResultRepresentation( Result executionResult )
{
  final List<String> columns = executionResult.columns();
  Iterable<Map<String, Object>> inner = new RepresentationExceptionHandlingIterable<>( loop( executionResult ) );
  return new ListRepresentation( "data", new IterableWrapper<Representation,Map<String,Object>>( inner )
  {
    @Override
    protected Representation underlyingObjectToObject( final Map<String,Object> row )
    {
      return new ListRepresentation( "row", new IterableWrapper<Representation,String>( columns )
      {
        @Override
        protected Representation underlyingObjectToObject( String column )
        {
          return getRepresentation( row.get( column ) );
        }
      } );
    }
  } );
}

代码示例来源:origin: neo4j/neo4j

@SafeVarargs
private static Result mockExecutionResult( ExecutionPlanDescription planDescription,
    Iterable<Notification> notifications, Map<String, Object>... rows )
{
  Set<String> keys = new TreeSet<>();
  for ( Map<String, Object> row : rows )
  {
    keys.addAll( row.keySet() );
  }
  Result executionResult = mock( Result.class );
  when( executionResult.columns() ).thenReturn( new ArrayList<>( keys ) );
  final Iterator<Map<String, Object>> inner = asList( rows ).iterator();
  when( executionResult.hasNext() ).thenAnswer( invocation -> inner.hasNext() );
  when( executionResult.next() ).thenAnswer( invocation -> inner.next() );
  when( executionResult.getQueryExecutionType() )
      .thenReturn( null != planDescription
             ? QueryExecutionType.profiled( QueryExecutionType.QueryType.READ_WRITE )
             : QueryExecutionType.query( QueryExecutionType.QueryType.READ_WRITE ) );
  if ( executionResult.getQueryExecutionType().requestedExecutionPlanDescription() )
  {
    when( executionResult.getExecutionPlanDescription() ).thenReturn( planDescription );
  }
  mockAccept( executionResult );
  when( executionResult.getNotifications() ).thenReturn( notifications );
  return executionResult;
}

代码示例来源:origin: neo4j/neo4j

when( result.columns() ).thenReturn( new ArrayList<>() );
when( result.getExecutionPlanDescription() ).thenReturn( plan );

代码示例来源:origin: neo4j/neo4j

@Test
public void eagerResultContainsColumns()
{
  Result result = database.execute( "MATCH (n) RETURN n.c as a, count(n) as b" );
  assertEquals( 1, testCursorContext.getAdditionalAttempts() );
  assertEquals( Arrays.asList("a", "b"), result.columns() );
}

代码示例来源:origin: neo4j/neo4j

Result executionResult = mock( Result.class );
mockAccept( executionResult );
when( executionResult.columns() ).thenReturn( new ArrayList<>( data.keySet() ) );
when( executionResult.hasNext() ).thenReturn( true, true, false );
when( executionResult.next() ).thenReturn( data ).thenThrow( new RuntimeException( "Stuff went wrong!" ) );

代码示例来源:origin: neo4j/neo4j

Result executionResult = mock( Result.class );
mockAccept( executionResult );
when( executionResult.columns() ).thenReturn( new ArrayList<>( data.keySet() ) );
when( executionResult.hasNext() ).thenReturn( true ).thenThrow(
    new RuntimeException( "Stuff went wrong!" ) );

代码示例来源:origin: neo4j/neo4j

public static SubGraph from( Result result, GraphDatabaseService gds, boolean addBetween )
  final List<String> columns = result.columns();
  for ( Map<String, Object> row : loop( result ) )

代码示例来源:origin: neo4j/neo4j

try
  Iterable<String> columns = result.columns();
  writeColumns( columns );
  writeRows( columns, result, configureWriters( resultDataContents ) );

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

public String[] writeResultHeader(Result result, CSVWriter out) {
  List<String> columns = result.columns();
  int cols = columns.size();
  String[] header = columns.toArray(new String[cols]);
  out.writeNext(header, applyQuotesToAll);
  return header;
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

public ProgressInfo dump(Result result, Writer writer, Reporter reporter, ExportConfig config) throws Exception {
  Consumer<JsonGenerator> consumer = (jsonGenerator) -> {
    try {
      String[] header = result.columns().toArray(new String[result.columns().size()]);
      result.accept((row) -> {
        writeJsonResult(reporter, header, jsonGenerator, row, config);
        reporter.nextRow();
        return true;
      });
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  };
  return dump(writer, reporter, consumer);
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Procedure
@Description("apoc.exportJson.json.query(query,file,{config,...,params:{params}}) - exports results from the cypher statement as json to the provided file")
public Stream<ProgressInfo> query(@Name("query") String query, @Name("file") String fileName, @Name(value = "config", defaultValue = "{}") Map<String, Object> config) throws Exception {
  Map<String,Object> params = config == null ? Collections.emptyMap() : (Map<String,Object>)config.getOrDefault("params", Collections.emptyMap());
  Result result = db.execute(query,params);
  String source = String.format("statement: cols(%d)", result.columns().size());
  return exportJson(fileName, source,result,config);
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Procedure
@Description("apoc.export.csv.query(query,file,{config,...,params:{params}}) - exports results from the cypher statement as csv to the provided file")
public Stream<ProgressInfo> query(@Name("query") String query, @Name("file") String fileName, @Name("config") Map<String, Object> config) throws Exception {
  Map<String,Object> params = config == null ? Collections.emptyMap() : (Map<String,Object>)config.getOrDefault("params", Collections.emptyMap());
  Result result = db.execute(query,params);
  String source = String.format("statement: cols(%d)", result.columns().size());
  return exportCsv(fileName, source,result,config);
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Override
          public AnyValue apply(org.neo4j.kernel.api.proc.Context ctx, AnyValue[] input) throws ProcedureException {
            Map<String, Object> params = functionParams(input, inputs, defaultValueMapper);
            try (Result result = api.execute(statement, params)) {
//                resourceTracker.registerCloseableResource(result); // TODO
              if (!result.hasNext()) return null;
              if (output.isEmpty()) {
                return ValueUtils.of(result.stream().collect(Collectors.toList()));
              }
              List<String> cols = result.columns();
              if (cols.isEmpty()) return null;
              if (!forceSingle && outType instanceof ListType) {
                ListType listType = (ListType) outType;
                AnyType innerType = listType.innerType();
                if (innerType instanceof MapType)
                  return ValueUtils.of(result.stream().collect(Collectors.toList()));
                if (cols.size() == 1)
                  return ValueUtils.of(result.stream().map(row -> row.get(cols.get(0))).collect(Collectors.toList()));
              } else {
                Map<String, Object> row = result.next();
                if (outType instanceof MapType) return ValueUtils.of(row);
                if (cols.size() == 1) return ValueUtils.of(row.get(cols.get(0)));
              }
              throw new IllegalStateException("Result mismatch " + cols + " output type is " + output);
            }
          }
        }, true);

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@UserFunction
@Deprecated
@Description("use either apoc.cypher.runFirstColumnMany for a list return or apoc.cypher.runFirstColumnSingle for returning the first row of the first column")
public Object runFirstColumn(@Name("cypher") String statement, @Name("params") Map<String, Object> params, @Name(value = "expectMultipleValues",defaultValue = "true") boolean expectMultipleValues) {
  if (params == null) params = Collections.emptyMap();
  String resolvedStatement = withParamMapping(statement, params.keySet());
  if (!resolvedStatement.contains(" runtime")) resolvedStatement = "cypher runtime=slotted " + resolvedStatement;
  try (Result result = db.execute(resolvedStatement, params)) {
  String firstColumn = result.columns().get(0);
  try (ResourceIterator<Object> iter = result.columnAs(firstColumn)) {
    if (expectMultipleValues) return iter.stream().collect(Collectors.toList());
    return iter.hasNext() ? iter.next() : null;
  }
 }
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

/**
 * invoke cypherAction in batched transactions being feeded from cypherIteration running in main thread
 * @param cypherIterate
 * @param cypherAction
 */
@Procedure(mode = Mode.WRITE)
@Description("apoc.periodic.iterate('statement returning items', 'statement per item', {batchSize:1000,iterateList:true,parallel:false,params:{},concurrency:50,retries:0}) YIELD batches, total - run the second statement for each item returned by the first statement. Returns number of batches and total processed rows")
public Stream<BatchAndTotalResult> iterate(
    @Name("cypherIterate") String cypherIterate,
    @Name("cypherAction") String cypherAction,
    @Name("config") Map<String,Object> config) {
  long batchSize = Util.toLong(config.getOrDefault("batchSize", 10000));
  int concurrency = Util.toInteger(config.getOrDefault("concurrency", 50));
  boolean parallel = Util.toBoolean(config.getOrDefault("parallel", false));
  boolean iterateList = Util.toBoolean(config.getOrDefault("iterateList", true));
  long retries = Util.toLong(config.getOrDefault("retries", 0)); // todo sleep/delay or push to end of batch to try again or immediate ?
  Map<String,Object> params = (Map)config.getOrDefault("params", Collections.emptyMap());
  try (Result result = db.execute(cypherIterate,params)) {
    Pair<String,Boolean> prepared = prepareInnerStatement(cypherAction, iterateList, result.columns(), "_batch");
    String innerStatement = prepared.first();
    iterateList=prepared.other();
    log.info("starting batching from `%s` operation using iteration `%s` in separate thread", cypherIterate,cypherAction);
    return iterateAndExecuteBatchedInSeparateThread((int)batchSize, parallel, iterateList, retries, result, (p) -> db.execute(innerStatement, merge(params, p)).close(), concurrency);
  }
}

相关文章