微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JavaPairRDD 将键值转换为键列表

如何解决JavaPairRDD 将键值转换为键列表

我有一个包含 (Key,Value) 的 JavaPairRDD,我想按键对其进行分组,并使“第二列”成为包含该键的所有值的列表。我目前正在使用 groupby() 函数,该函数正确执行密钥聚合但将我的值转换为 Long 的 Iterable。这是,

Key1 Iterable<Long>
Key2 Iterable<Long>
...

有什么办法可以强制这个函数使用 Long 列表而不是 Iterable 对象吗?

Key1 List<Long>
Key2 List<Long>
...

我阅读了一些关于名为 combineByKey()函数内容,但我认为这不是一个用例。可能我需要使用 reduceByKey 但我没有看到它。应该是这样的:

myRDD.reduceByKey((a,b) -> new ArrayList<Long>()) //and add b to a 

最后,我想组合值来获得一个Key n,List<Long> RDD。 感谢您抽出宝贵时间。

解决方法

你可以试试这样的:

kernel

首先,您映射以将值转换为长整型列表。然后 reduceByKey 并在 arraylist 上使用 #include <efi.h> #include <efilib.h> #include <elf.h> #define PSF1_MAGIC0 0x36 #define PSF1_MAGIC1 0x04 typedef unsigned long long size_t; typedef struct { unsigned char magic[2]; unsigned char mode; unsigned char charsize; } PSF1_HEADER; typedef struct { PSF1_HEADER* psf1_Header; void* glyphBuffer; } PSF1_FONT; typedef struct { void* BaseAddress; size_t BufferSize; unsigned int Width; unsigned int Height; unsigned int PixelsPerScanLine; } Framebuffer; Framebuffer framebuffer; Framebuffer* InitializeGOP() { EFI_GUID gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; EFI_GRAPHICS_OUTPUT_PROTOCOL* gop; EFI_STATUS status; status = uefi_call_wrapper(BS->LocateProtocol,3,&gopGuid,NULL,(void**)&gop); if (EFI_ERROR(status)) { Print(L"Unable to locate GOP\n\r"); return NULL; } else { Print(L"GOP located\n\r"); } framebuffer.BaseAddress = (void*)gop->Mode->FrameBufferBase; framebuffer.BufferSize = gop->Mode->FrameBufferSize; framebuffer.Width = gop->Mode->Info->HorizontalResolution; framebuffer.Height = gop->Mode->Info->VerticalResolution; framebuffer.PixelsPerScanLine = gop->Mode->Info->PixelsPerScanLine; return &framebuffer; } EFI_FILE* LoadFile(EFI_FILE* Directory,CHAR16* Path,EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE* SystemTable) { EFI_FILE* LoadedFile; EFI_LOADED_IMAGE_PROTOCOL* LoadedImage; SystemTable->BootServices->HandleProtocol(ImageHandle,&gEfiLoadedImageProtocolGuid,(void**)&LoadedImage); EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* FileSystem; SystemTable->BootServices->HandleProtocol(LoadedImage->DeviceHandle,&gEfiSimpleFileSystemProtocolGuid,(void**)&FileSystem); if (Directory == NULL) { FileSystem->OpenVolume(FileSystem,&Directory); } EFI_STATUS s = Directory->Open(Directory,&LoadedFile,Path,EFI_FILE_MODE_READ,EFI_FILE_READ_ONLY); if (s != EFI_SUCCESS) { return NULL; } return LoadedFile; } PSF1_FONT* LoadPSF1Font(EFI_FILE* Directory,EFI_SYSTEM_TABLE* SystemTable) { EFI_FILE* font = LoadFile(Directory,ImageHandle,SystemTable); if (font == NULL) return NULL; PSF1_HEADER* fontHeader; SystemTable->BootServices->AllocatePool(EfiLoaderData,sizeof(PSF1_HEADER),(void**)&fontHeader); UINTN size = sizeof(PSF1_HEADER); font->Read(font,&size,fontHeader); if (fontHeader->magic[0] != PSF1_MAGIC0 || fontHeader->magic[1] != PSF1_MAGIC1) return NULL; UINTN glyphBufferSize = fontHeader->charsize * 256; if (fontHeader->mode == 1) { // 512 glyph mode glyphBufferSize *= 2; } void* glyphBuffer; font->SetPosition(font,sizeof(PSF1_HEADER)); SystemTable->BootServices->AllocatePool(EfiLoaderData,glyphBufferSize,(void**)&glyphBuffer); font->Read(font,&glyphBufferSize,glyphBuffer); PSF1_FONT* finishedFont; SystemTable->BootServices->AllocatePool(EfiLoaderData,sizeof(PSF1_FONT),(void**)&finishedFont); finishedFont->psf1_Header = fontHeader; finishedFont->glyphBuffer = glyphBuffer; return finishedFont; } int memcmp(const void* aptr,const void* bptr,size_t n) { const unsigned char* a = aptr,*b = bptr; for (size_t i = 0; i < n; i++) { if (a[i] < b[i]) return -1; else if(a[i] > b[i]) return 1; } return 0; } EFI_STATUS efi_main (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable) { InitializeLib(ImageHandle,SystemTable); Print(L"Hello World!\n\r"); EFI_FILE* Kernel = LoadFile(NULL,L"kernel.elf",SystemTable); if ( Kernel == NULL) { Print(L"Could not load kernel \n\r"); } else { Print(L"Kernel Loaded Successfully \n\r"); } Elf64_Ehdr header; { UINTN FileInfoSize; EFI_FILE_INFO* FileInfo; Kernel->GetInfo(Kernel,&gEfiFileInfoGuid,&FileInfoSize,NULL); SystemTable->BootServices->AllocatePool(EfiLoaderData,FileInfoSize,(void**)&FileInfo); Kernel->GetInfo(Kernel,(void**)&FileInfo); UINTN size = sizeof(header); Kernel->Read(Kernel,&header); } if ( memcmp(&header.e_ident[EI_MAG0],ELFMAG,SELFMAG) != 0 || header.e_ident[EI_CLASS] != ELFCLASS64 || header.e_ident[EI_DATA] != ELFDATA2LSB || header.e_type != ET_EXEC || header.e_machine != EM_X86_64 || header.e_version != EV_CURRENT ) { Print(L"kernel format is bad\r\n"); } else { Print(L"kernel header successfully verified\r\n"); } Elf64_Phdr* phdrs; { Kernel->SetPosition(Kernel,header.e_phoff); UINTN size = header.e_phnum * header.e_phentsize; SystemTable->BootServices->AllocatePool(EfiLoaderData,size,(void**)&phdrs); Kernel->Read(Kernel,phdrs); } for ( Elf64_Phdr* phdr = phdrs; (char*)phdr < (char*)phdrs + header.e_phnum * header.e_phentsize; phdr = (Elf64_Phdr*)((char*)phdr + header.e_phentsize) ) { switch(phdr->p_type) { case PT_LOAD: { int pages = (phdr->p_memsz + 0x1000 - 1) / 0x1000; Elf64_Addr segment = phdr->p_paddr; SystemTable->BootServices->AllocatePages(AllocateAddress,EfiLoaderData,pages,&segment); Kernel->SetPosition(Kernel,phdr->p_offset); UINTN size = phdr->p_filesz; Kernel->Read(Kernel,(void*)segment); break; } } } Print(L"Kernel Loaded\n\r"); void (*KernelStart)(Framebuffer*,PSF1_FONT**) = ((__attribute__((sysv_abi)) void(*)(Framebuffer*,PSF1_FONT**) ) header.e_entry); PSF1_FONT* newFont = LoadPSF1Font(NULL,L"zap-light16.psf",SystemTable); if (newFont == NULL) { Print(L"Font is not valid or is not found\n\r"); } else { Print(L"Font found,char size = %d\n\r",newFont->psf1_Header->charsize); } PSF1_FONT* newFontExt = LoadPSF1Font(NULL,L"zap-ext-light16.psf",SystemTable); if (newFont == NULL) { Print(L"Font is not valid or is not found\n\r"); } else { Print(L"Font found,newFont->psf1_Header->charsize); } PSF1_FONT* fonts[] = {newFont,newFontExt}; Framebuffer* newBuffer = InitializeGOP(); Print(L"Base: 0x%x\n\rSize: 0x%x\n\rWidth: %d\n\rHeight: %d\n\rPixelsPerScanline: %d\n\r",newBuffer->BaseAddress,newBuffer->BufferSize,newBuffer->Width,newBuffer->Height,newBuffer->PixelsPerScanLine); KernelStart(newBuffer,fonts); return EFI_SUCCESS; // Exit the UEFI application } 方法组合列表。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。