registerAll method

void registerAll(
  1. Map<String, Object> tables
)

Registers all entries atomically with respect to Dart-side validation.

Implementation

void registerAll(Map<String, Object> tables) {
  for (final entry in tables.entries) {
    _validateName(entry.key, 'table name');
    final value = entry.value;
    if (value is LazyFrame) {
      _runtime._requireLazy(value);
    } else if (value is DataFrame) {
      _runtime._requireFrame(value);
    } else {
      throw ArgumentError.value(
        value,
        'tables',
        'values must be LazyFrame or DataFrame',
      );
    }
  }
  if (tables.length > 10000) {
    throw ArgumentError.value(
      tables,
      'tables',
      'must contain at most 10000 entries',
    );
  }

  final temporary = <LazyFrame>[];
  try {
    final frames = <MapEntry<String, LazyFrame>>[];
    for (final entry in tables.entries) {
      final value = entry.value;
      final lazy = value is LazyFrame ? value : (value as DataFrame).lazy();
      if (value is DataFrame) temporary.add(lazy);
      frames.add(MapEntry(entry.key, lazy));
    }
    final leases = _leaseAll([
      _owner,
      ...frames.map((entry) => entry.value._owner),
    ]);
    try {
      _runtime._client.invokeSync('sqlContextRegisterAll', {
        'context': leases.first.handle.toString(),
        'tables': [
          for (var index = 0; index < frames.length; index++)
            {
              'name': frames[index].key,
              'input': leases[index + 1].handle.toString(),
            },
        ],
      });
    } finally {
      _releaseAll(leases);
    }
  } finally {
    for (final frame in temporary.reversed) {
      frame.close();
    }
  }
}