{"title":"Partitioning","description":"Partition Altertable catalog tables by column or transform to improve write layout and query pruning.","order":600,"askSuggestions":["When should I partition a table instead of sorting it?","Why do older files keep the previous partition layout?","How do I partition a table by month?"],"navigation":true,"body":{"code":"var Component=(()=>{var m=Object.create;var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var T=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),b=(n,e)=>{for(var i in e)a(n,i,{get:e[i],enumerable:!0})},l=(n,e,i,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of g(e))!y.call(n,o)&&o!==i&&a(n,o,{get:()=>e[o],enumerable:!(r=u(e,o))||r.enumerable});return n};var w=(n,e,i)=>(i=n!=null?m(f(n)):{},l(e||!n||!n.__esModule?a(i,\"default\",{value:n,enumerable:!0}):i,n)),k=n=>l(a({},\"__esModule\",{value:!0}),n);var d=T((D,c)=>{c.exports=_jsx_runtime});var x={};b(x,{default:()=>p,frontmatter:()=>E});var t=w(d()),E={title:\"Partitioning\",description:\"Partition Altertable catalog tables by column or transform to improve write layout and query pruning.\",order:600,askSuggestions:[\"When should I partition a table instead of sorting it?\",\"Why do older files keep the previous partition layout?\",\"How do I partition a table by month?\"]};function h(n){let e={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",li:\"li\",p:\"p\",pre:\"pre\",strong:\"strong\",ul:\"ul\",...n.components},{DocsPreviewDocument:i,DocsPreviewSection:r,DocsTable:o}=e;return i||s(\"DocsPreviewDocument\",!0),r||s(\"DocsPreviewSection\",!0),o||s(\"DocsTable\",!0),(0,t.jsxs)(i,{anchors:\"partitioning set-partition-keys remove-partition-keys supported-transforms when-to-partition learn-more\",children:[(0,t.jsxs)(r,{sectionId:\"partitioning\",sectionTitle:\"Partitioning\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,t.jsx)(e.h1,{id:\"partitioning\",children:\"Partitioning\"}),`\n`,(0,t.jsx)(e.p,{children:\"Altertable catalog tables can be partitioned by a user-defined set of partition keys. When partition keys are set, new data is written into separate data files grouped by those keys.\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"During query planning, Altertable uses file-level zone maps \\u2014 per-column min/max statistics stored in catalog metadata \\u2014 to decide which files to scan. For order-preserving partition transforms (\",(0,t.jsx)(e.code,{children:\"identity\"}),\", \",(0,t.jsx)(e.code,{children:\"year\"}),\", \",(0,t.jsx)(e.code,{children:\"month\"}),\", \",(0,t.jsx)(e.code,{children:\"day\"}),\", \",(0,t.jsx)(e.code,{children:\"hour\"}),\"), partitioned writes produce tight zone maps on the partition column, so file-level pruning narrows scans to the matching partition files.\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"Partition keys only affect \",(0,t.jsx)(e.strong,{children:\"new\"}),\" data written to a table. Data written before a layout change keeps the partitioning keys that were active at write time. That lets the partition layout evolve over time without rewriting historical files.\"]}),`\n`,(0,t.jsx)(e.p,{children:\"Partition key values are stored in catalog metadata. They do not need to appear inside the data files or in object storage paths.\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"Run the statements below through Altertable's \",(0,t.jsx)(e.a,{href:\"/docs/lakehouse/sql-engine\",children:\"SQL engine\"}),\" against an \",(0,t.jsx)(e.a,{href:\"/docs/lakehouse/catalogs\",children:\"Altertable catalog\"}),\" you own.\"]}),`\n`]}),(0,t.jsxs)(r,{sectionId:\"set-partition-keys\",sectionTitle:\"Set partition keys\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,t.jsx)(e.h2,{id:\"set-partition-keys\",children:\"Set partition keys\"}),`\n`,(0,t.jsx)(e.p,{children:\"Partition new writes on a column:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`ALTER TABLE my_catalog.main.shipments SET PARTITIONED BY (destination_region);\n`})}),`\n`,(0,t.jsx)(e.p,{children:\"Partition on time transforms:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`ALTER TABLE my_catalog.main.shipments SET PARTITIONED BY (year(departed_at), month(departed_at));\n`})}),`\n`,(0,t.jsx)(e.p,{children:\"Distribute rows into a fixed number of buckets using an Iceberg-compatible Murmur3 hash:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`ALTER TABLE my_catalog.main.shipments SET PARTITIONED BY (bucket(8, order_id));\n`})}),`\n`,(0,t.jsx)(e.p,{children:\"Combine bucket partitioning with other transforms:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`ALTER TABLE my_catalog.main.shipments SET PARTITIONED BY (bucket(8, order_id), month(departed_at));\n`})}),`\n`]}),(0,t.jsxs)(r,{sectionId:\"remove-partition-keys\",sectionTitle:\"Remove partition keys\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,t.jsx)(e.h2,{id:\"remove-partition-keys\",children:\"Remove partition keys\"}),`\n`,(0,t.jsx)(e.p,{children:\"Stop partitioning new writes:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`ALTER TABLE my_catalog.main.shipments RESET PARTITIONED BY;\n`})}),`\n`,(0,t.jsx)(e.p,{children:\"Existing files keep their prior layout until you rewrite or compact them through maintenance operations.\"}),`\n`]}),(0,t.jsxs)(r,{sectionId:\"supported-transforms\",sectionTitle:\"Supported transforms\",anchors:\"\",ancestors:\"\",index:\"3\",children:[(0,t.jsx)(e.h2,{id:\"supported-transforms\",children:\"Supported transforms\"}),`\n`,(0,t.jsx)(o,{columns:[\"Transform\",\"Expression\"],data:[{Transform:\"identity\",Expression:\"`column_name`\"},{Transform:\"bucket\",Expression:\"`bucket(N, column_name)`\"},{Transform:\"year\",Expression:\"`year(timestamp)`\"},{Transform:\"month\",Expression:\"`month(timestamp)`\"},{Transform:\"day\",Expression:\"`day(timestamp)`\"},{Transform:\"hour\",Expression:\"`hour(timestamp)`\"}]}),`\n`]}),(0,t.jsxs)(r,{sectionId:\"when-to-partition\",sectionTitle:\"When to partition\",anchors:\"\",ancestors:\"\",index:\"4\",children:[(0,t.jsx)(e.h2,{id:\"when-to-partition\",children:\"When to partition\"}),`\n`,(0,t.jsx)(e.p,{children:\"Partition when queries repeatedly filter on the same columns \\u2014 especially high-cardinality IDs combined with time, or date/time columns used in range filters. Partitioning trades more files and metadata for smaller, targeted scans.\"}),`\n`,(0,t.jsx)(e.p,{children:\"Skip partitioning when filters are unpredictable, tables stay small, or write throughput matters more than read pruning. You can add or change partition keys later; only new data follows the updated layout.\"}),`\n`]}),(0,t.jsxs)(r,{sectionId:\"learn-more\",sectionTitle:\"Learn more\",anchors:\"\",ancestors:\"\",index:\"5\",children:[(0,t.jsx)(e.h2,{id:\"learn-more\",children:\"Learn more\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:(0,t.jsx)(e.a,{href:\"/docs/lakehouse\",children:\"Altertable Catalogs\"})}),\": Catalogs for storing and querying your data\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:(0,t.jsx)(e.a,{href:\"/docs/lakehouse/sql-engine\",children:\"SQL Engine\"})}),\": DuckDB dialect and federated queries\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:(0,t.jsx)(e.a,{href:\"/docs/lakehouse/storage/buckets\",children:\"Buckets\"})}),\": Object storage that backs catalog data files\"]}),`\n`]})]})]})}function p(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,{...n,children:(0,t.jsx)(h,{...n})}):h(n)}function s(n,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+n+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return k(x);})();\n;return Component;"},"_id":"docs/lakehouse/features/partitioning.mdx","_raw":{"sourceFilePath":"docs/lakehouse/features/partitioning.mdx","sourceFileName":"partitioning.mdx","sourceFileDir":"docs/lakehouse/features","contentType":"mdx","flattenedPath":"docs/lakehouse/features/partitioning"},"type":"Docs","path":"/lakehouse/features/partitioning","level":3,"parent":"lakehouse/features"}