@@ -280,6 +280,20 @@ bool StorageObjectStorage::Configuration::update( ///NOLINT
280280 return true ;
281281}
282282
283+ void StorageObjectStorage::Configuration::initPartitionStrategy (ASTPtr partition_by, const ColumnsDescription & columns, ContextPtr context)
284+ {
285+
286+ partition_strategy = PartitionStrategyFactory::get (
287+ partition_strategy_type,
288+ partition_by,
289+ columns.getOrdinary (),
290+ context,
291+ format,
292+ getRawPath ().withGlobs (),
293+ getRawPath ().withPartitionWildcard (),
294+ partition_columns_in_data_file);
295+ }
296+
283297IDataLakeMetadata * StorageObjectStorage::getExternalMetadata (ContextPtr query_context)
284298{
285299 configuration->update (
@@ -454,7 +468,7 @@ class ReadFromObjectStorageStep : public SourceStepWithFilter
454468 auto context = getContext ();
455469 iterator_wrapper = StorageObjectStorageSource::createFileIterator (
456470 configuration, configuration->getQuerySettings (context), object_storage, distributed_processing,
457- context, predicate, filter_actions_dag, virtual_columns, nullptr , context->getFileProgressCallback ());
471+ context, predicate, filter_actions_dag, virtual_columns, info. hive_partition_columns_to_read_from_file_path , nullptr , context->getFileProgressCallback ());
458472 }
459473};
460474}
@@ -464,9 +478,10 @@ ReadFromFormatInfo StorageObjectStorage::Configuration::prepareReadingFromFormat
464478 const Strings & requested_columns,
465479 const StorageSnapshotPtr & storage_snapshot,
466480 bool supports_subset_of_columns,
467- ContextPtr local_context)
481+ ContextPtr local_context,
482+ const PrepareReadingFromFormatHiveParams & hive_params)
468483{
469- return DB::prepareReadingFromFormat (requested_columns, storage_snapshot, local_context, supports_subset_of_columns);
484+ return DB::prepareReadingFromFormat (requested_columns, storage_snapshot, local_context, supports_subset_of_columns, hive_params );
470485}
471486
472487std::optional<ColumnsDescription> StorageObjectStorage::Configuration::tryGetTableStructureFromMetadata () const
@@ -752,7 +767,7 @@ void StorageObjectStorage::Configuration::initialize(
752767 {
753768 configuration_to_initialize.format
754769 = FormatFactory::instance ()
755- .tryGetFormatFromFileName (configuration_to_initialize.isArchive () ? configuration_to_initialize.getPathInArchive () : configuration_to_initialize.getPath () )
770+ .tryGetFormatFromFileName (configuration_to_initialize.isArchive () ? configuration_to_initialize.getPathInArchive () : configuration_to_initialize.getRawPath (). path )
756771 .value_or (" auto" );
757772 }
758773 }
@@ -767,33 +782,65 @@ void StorageObjectStorage::Configuration::check(ContextPtr) const
767782 FormatFactory::instance ().checkFormatName (format);
768783}
769784
770- bool StorageObjectStorage::Configuration::withPartitionWildcard () const
785+ StorageObjectStorage::Configuration::Path StorageObjectStorage::Configuration::getPathForRead () const
786+ {
787+ auto raw_path = getRawPath ();
788+
789+ if (!partition_strategy)
790+ {
791+ return raw_path;
792+ }
793+
794+ return Path {partition_strategy->getPathForRead (raw_path.path )};
795+ }
796+
797+ StorageObjectStorage::Configuration::Path StorageObjectStorage::Configuration::getPathForWrite (const std::string & partition_id) const
798+ {
799+ auto raw_path = getRawPath ();
800+
801+ if (!partition_strategy)
802+ {
803+ return raw_path;
804+ }
805+
806+ return Path {partition_strategy->getPathForWrite (raw_path.path , partition_id)};
807+ }
808+
809+ bool StorageObjectStorage::Configuration::Path::withPartitionWildcard () const
771810{
772811 static const String PARTITION_ID_WILDCARD = " {_partition_id}" ;
773- return getPath ().find (PARTITION_ID_WILDCARD) != String::npos
774- || getNamespace ().find (PARTITION_ID_WILDCARD) != String::npos;
812+ return path.find (PARTITION_ID_WILDCARD) != String::npos;
775813}
776814
777- bool StorageObjectStorage::Configuration::withGlobsIgnorePartitionWildcard () const
815+ bool StorageObjectStorage::Configuration::Path:: withGlobsIgnorePartitionWildcard () const
778816{
779817 if (!withPartitionWildcard ())
780818 return withGlobs ();
781- return PartitionedSink::replaceWildcards (getPath () , " " ).find_first_of (" *?{" ) != std::string::npos;
819+ return PartitionedSink::replaceWildcards (path , " " ).find_first_of (" *?{" ) != std::string::npos;
782820}
783821
784- bool StorageObjectStorage::Configuration::isPathWithGlobs () const
822+ bool StorageObjectStorage::Configuration::Path::withGlobs () const
785823{
786- return getPath () .find_first_of (" *?{" ) != std::string::npos;
824+ return path .find_first_of (" *?{" ) != std::string::npos;
787825}
788826
789- bool StorageObjectStorage::Configuration::isNamespaceWithGlobs () const
827+ std::string StorageObjectStorage::Configuration::Path::getWithoutGlobs () const
790828{
791- return getNamespace ().find_first_of (" *?{" ) != std::string::npos;
829+ if (allow_partial_prefix)
830+ {
831+ return path.substr (0 , path.find_first_of (" *?{" ));
832+ }
833+
834+ auto first_glob_pos = path.find_first_of (" *?{" );
835+ auto end_of_path_without_globs = path.substr (0 , first_glob_pos).rfind (' /' );
836+ if (end_of_path_without_globs == std::string::npos || end_of_path_without_globs == 0 )
837+ return " /" ;
838+ return path.substr (0 , end_of_path_without_globs);
792839}
793840
794- std::string StorageObjectStorage::Configuration::getPathWithoutGlobs () const
841+ bool StorageObjectStorage::Configuration::isNamespaceWithGlobs () const
795842{
796- return getPath ().substr ( 0 , getPath (). find_first_of (" *?{" )) ;
843+ return getNamespace ().find_first_of (" *?{" ) != std::string::npos ;
797844}
798845
799846bool StorageObjectStorage::Configuration::isPathInArchiveWithGlobs () const
@@ -803,7 +850,7 @@ bool StorageObjectStorage::Configuration::isPathInArchiveWithGlobs() const
803850
804851std::string StorageObjectStorage::Configuration::getPathInArchive () const
805852{
806- throw Exception (ErrorCodes::LOGICAL_ERROR, " Path {} is not archive" , getPath () );
853+ throw Exception (ErrorCodes::LOGICAL_ERROR, " Path {} is not archive" , getRawPath (). path );
807854}
808855
809856void StorageObjectStorage::Configuration::assertInitialized () const
0 commit comments